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

 


Dernière réponse
Sujet : [Visual C++] Dans un projet SDI, problème de changement de vue
Scusez_Moi 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;
}

Votre réponse
Nom d'utilisateur    Pour poster, vous devez être inscrit sur ce forum .... si ce n'est pas le cas, cliquez ici !
Le ton de votre message                        
                       
Votre réponse


[b][i][u][strike][spoiler][fixed][cpp][url][email][img][*]   
 
   [quote]
 

Options

 
Vous avez perdu votre mot de passe ?


Vue Rapide de la discussion
Scusez_Moi 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;
}
n0mad 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.

shaman 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.
oh_damned uuuuup
oh_damned 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

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