Home > Software engineering >  Add an item to the tree control in the MDI encountered problems
Add an item to the tree control in the MDI encountered problems

Time:09-24

Is directly through multiple files vs style code generated by the wizard, hope to open a file at the same time, a number of nodes are added to a view on the left
Doc. The relevant code from the CPP
Void CMFCApplication1Doc: : OnFileOpen ()
{
HWND HWND=FindWindowEx (NULL, NULL, NULL, _T (" view "));
M_wndClassView1. M_hWnd=HWND;
HTREEITEM hRoot=m_wndClassView1. InsertItem (_T (" 123 "), 0, 0).
}

Program triggered the breakpoint here {ASSERT (: : IsWindow (m_hWnd)); Return InsertItem (... ), could you tell me where is the problem?

CodePudding user response:

Don't have to write, in the open file function
Void CMFCApplication1Doc: : OnFileOpen ()
{
.//open the file and read, do you want to do, of course, if you don't need the file content itself, it also can not read it
}

After the complete file open action, all the view will receive a message, it will automatically call views OnInitUpdate () interface (the function name should be this, if not, where is less than), in this function to update their display can

CodePudding user response:

reference 1st floor JSZJ response:
don't have to write, in the function of open file
Void CMFCApplication1Doc: : OnFileOpen ()
{
.//open the file and read, do you want to do, of course, if you don't need the file content itself, it also can not read it
}

After complete file open action, all the view will receive a message, it will automatically call views OnInitUpdate () interface (the function name should be this, if not, where is also less than), in this function to update their own display can

Thank you for your reply, but I didn't find you said the function, also have no access to the similar function function,
In my code, I think there should be no access to class to handle to the window, to cause the failure of inertitem, but did not find the solution

CodePudding user response:

FindWindowEx set breakpoints, view the search to the window?

CodePudding user response:

"View" on the left is split window?
////
CLeftView * CMainFrame: : GetLeftPane ()
{
The CWnd * pWnd=m_wndSplitter. GetPane (0, 0);
PView=DYNAMIC_DOWNCAST CLeftView * (CLeftView, pWnd);
Return pView;
}


CMainFrame * pMain=(CMainFrame *) AfxGetMainWnd ();
if(! PMain) return;//init
if(! IsWindow (pMain - & gt; M_hWnd)) return;
//
CLeftView * pLeftView=pMain - & gt; GetLeftPane ();//tree
CTreeCtrl& LeftTree=pLeftView - & gt; GetTreeCtrl ();

CodePudding user response:

refer to the second floor yuyuyuxue response:
Quote: refer to 1st floor JSZJ response:

Don't have to write, in the open file function
Void CMFCApplication1Doc: : OnFileOpen ()
{
.//open the file and read, do you want to do, of course, if you don't need the file content itself, it also can not read it
}

After complete file open action, all the view will receive a message, it will automatically call views OnInitUpdate () interface (the function name should be this, if not, where is also less than), in this function to update their own display can

Thank you for your reply, but I didn't find you said the function, also have no access to the similar function function,
In my code, I think there should be no access to class to handle to the window, to cause the failure of inertitem, but did not find solution


Function named OnInitialUpdate (), is a virtual function, from the class of "attributes" - & gt;" Rewrite "can be found in the list
  • Related