Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1375 connectés 

  FORUM HardWare.fr
  Programmation

  [Visual C++] Dans un projet SDI, problème de changement de vue

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Visual C++] Dans un projet SDI, problème de changement de vue

n°42763
oh_damned
Posté le 26-06-2001 à 11:14:11  profilanswer
 

int CMainFrame::ChangeView()
{
 CView *currentView = GetActiveView();
 currentView->ShowWindow(SW_HIDE);
 CView *newView = new CAdminProdView2();
 newView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
 this, IDD_ADMINPROD_FORM2);
 newView->OnInitialUpdate();
 SetActiveView(newView);
 ((CAdminProdView2 *)newView)->Test();
 newView->ShowWindow(SW_SHOW);
 newView->SetDlgCtrlID(IDD_ADMINPROD_FORM2);
 return 0;
}
 
l'objet newView est bien créé (appel de la méthode Test OK)
mon problème est que la fenêtre n'est pas rafraîchie, la nouvelle vue n'est pas affichée.
 
Thanks for your help

mood
Publicité
Posté le 26-06-2001 à 11:14:11  profilanswer
 

n°42914
oh_damned
Posté le 26-06-2001 à 18:02:09  profilanswer
 

uuuuup

n°43093
shaman
Posté le 27-06-2001 à 12:46:57  profilanswer
 

Je suis debutant en mfc mais cette fonction declare la fenetre invalide envoie un evenement WM_PAINT
 
CWindow::InvalidateRect
This method invalidates the client area within the specified rectangle.
 
BOOL InvalidateRect(  
LPCRECT lpRect,  
BOOL bErase = TRUE);  
Parameters
lpRect  
Long pointer to a RECT structure that contains the client coordinates of the rectangle to be added to the update region. If this parameter is NULL, the entire client area is added to the update region.  
bErase  
Boolean that specifies whether the background within the update region is to be erased when the update region is processed. If this parameter is TRUE, the background is erased when the BeginPaint function is called. If this parameter is FALSE, the background remains unchanged.  
Return Values
Nonzero indicates success. Zero indicates failure.  
 
To get extended error information, call GetLastError.
 
Remarks
The invalidated areas accumulate in the update region until the region is processed when the next WM_PAINT message occurs or until the region is validated by using the ValidateRect function.
 
The system sends a WM_PAINT message to a window whenever its update region is not empty and there are no other messages in the application queue for that window.
 
If the bErase parameter is TRUE for any part of the update region, the background is erased in the entire region, not just in the specified part.

n°43198
n0mad
inscrit au XXe siècle
Posté le 27-06-2001 à 16:56:00  profilanswer
 

C'est un copy-paste d'un de mes projets en cours, j'espère que tu comprendras qqc.
 

Code :
  1. // ce code est inclu dans une classe qui derive de CView  
  2. // (vue principale d'un SDI)
  3. // il cree une frame CPJFrame qui contient une vue CHoryzonVue
  4. // (qui derive de CScrollView) et l'attache au document en cours  
  5. CFrameWnd* vueCarte = (CFrameWnd*) RUNTIME_CLASS( CPJFrame )->CreateObject(); // on instancie grace au DYNCREATE
  6. // création du contexte de création :
  7. CCreateContext* pCtxtCarte = new CCreateContext;
  8. pCtxtCarte->m_pCurrentDoc = GetDocument();
  9. pCtxtCarte->m_pCurrentFrame = (CFrameWnd*) AfxGetApp()->m_pMainWnd;
  10. pCtxtCarte->m_pLastView = this;
  11. pCtxtCarte->m_pNewDocTemplate = NULL;
  12. pCtxtCarte->m_pNewViewClass = RUNTIME_CLASS(CHoryzonView);  // la CScrollView
  13. // rectangle :
  14. CRect rectDef(0,0,760,550);
  15. // Affichage de la frame :
  16. vueCarte->Create(NULL,"Carte de la Galaxie", WS_OVERLAPPEDWINDOW ,rectDef,NULL,NULL,0,pCtxtCarte);
  17. vueCarte->InitialUpdateFrame(GetDocument(),TRUE);   // et voila
  18. delete pCtxtCarte;


 
Là, il y a tout. D'après ce que j'ai lu de ton code, tu essaies de créer toi même ta CView et c'est pas bon. Une CView doit vivre dans une CFrameWnd sinon elle ne peut être attachée à un CDocument. Avec ça, la nouvelle vue recoie les evenements lancés par la méthode CDocument::UpdateAllViews() ce qui est bien pratique pour les mises à jour.


---------------
Pipiru piru piru pipiru pi
n°43207
Scusez_Moi
Posté le 27-06-2001 à 17:25:02  profilanswer
 

Voici mon code qui marche maintenant sans problème
 
int CMainFrame::ChangeToView1()
{
 CView *View1 = GetActiveView();
 View1->ShowWindow(SW_HIDE);
 CView *newView = new CAdminProdView2();
 CCreateContext context;
 context.m_pCurrentDoc = View1->GetDocument();
 newView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
 this, AFX_IDW_PANE_FIRST, &context);
 newView->OnInitialUpdate();
 SetActiveView(newView);
 newView->ShowWindow(SW_SHOW);
 return 0;
}


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  [Visual C++] Dans un projet SDI, problème de changement de vue

 

Sujets relatifs
[php] problème bizarreprobleme d'algo pour affichage de graph
[Visual C++] Titre en couleur[VB6] Probleme pour me connecter à une DB Access
[Visual C++] ActiveX Flash[C++] Problème avec les destructeurs de class
probleme en php avec odbc_num_rows??Visual C ++ - Par ou commencer
[VISUAL C++] Trois details embetants resolus[Visual C++] Forcer un focus sur un bouton quelconque ?
Plus de sujets relatifs à : [Visual C++] Dans un projet SDI, problème de changement de vue


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR