Home > Software engineering >  MFC application documents, I the pointer variable defined in a window, and then zero it in another w
MFC application documents, I the pointer variable defined in a window, and then zero it in another w

Time:10-10

MFC application documents, I the pointer variable defined in a window, and then zero it in another window, can see to zero, but why the debugger running back to the current window, how the value of the pointer variable is back? I create multiple views form, program is running, can switch between each form to deal with reality, but I am currently a form in close and then open the form, the program runs is failed, then check the handle to the child form has changed, wanted to remove child form a pointer to the variable to create a handle, but the value is a NULL pointer variable, is back, please masters teach you!

CodePudding user response:

Not come back, but run shows different window instance is different, so the pointer is a value, so before shows that the new window, you need to determine whether a window handle to effective,
Multiple document USES the following way, visit different View:
 POSITION pos=GetFirstViewPosition (); 
While (pos!=NULL) {
PView=GetNextView (pos);
if(! PView - & gt; IsKindOf (pClass))
break;

For example, when access to the main frame adopts a method:
 CWnd * pWnd=theApp GetMainWnd (); 
CMainFrame * pFrame=DYNAMIC_DOWNCAST (CMainFrame, pWnd);

CodePudding user response:

1, what you call in another window to clean up the 0, may not be the current window variable pointer;
2, memory disorders, check the structure and the members of the class alignment of bytes to variables.

CodePudding user response:

refer to the second floor syy64 response:
1, your so-called in another window to clean up the 0, may not be the current window variable pointer;
2, memory disorders, check the structure and member variables of the class of byte alignment,

A pointer to the variable is the current window I defined

CodePudding user response:

reference 1st floor lishunihaoa response:
is not come back, but run shows different window instance is different, so the pointer is a value, so before shows that the new window, you need to determine whether a window handle to effective,
Multiple document USES the following way, visit different View:
 POSITION pos=GetFirstViewPosition (); 
While (pos!=NULL) {
PView=GetNextView (pos);
if(! PView - & gt; IsKindOf (pClass))
break;

For example, when access to the main frame adopts a method:
 CWnd * pWnd=theApp GetMainWnd (); 
CMainFrame * pFrame=DYNAMIC_DOWNCAST (CMainFrame, pWnd);

Pointer to the window the value of the variable is clear after click close the current window is NULL, why then click open the closed window after back to the main form, the value and also in? Debugging and running of view, I am using the DEBUG is how can my child Windows are closed to open again?

CodePudding user response:

"Why then click open the closed window after back to the main form, the value and also in?"
If "shut down" is destroyed, "open" is to create again, of course not 0.
Try SW_HIDE hidden.

CodePudding user response:

Don't visit each other between the view of the variable, if need be, can define public variables,
When the document changes, update the view at the same time relevant variables as well as the public variables,
  • Related