When is an HWND invalid?
-
Hi! in a Subclassed Cedit Control, I issued a SetWindowText() function many times in my program.. I traced my program, Now In the first call to SetWindowText(), the function succeeds and it sets the text .. Now on the second call the function asserts, and upon tracing, The ::IsWindow(hwndofCedit) returns FALSE. My question when does an HWND becomes invalid? aside from window destruction?.. My Cedit's parent is not a CDialog, would that be an issue? "geez i cracked myself off.."
-
Hi! in a Subclassed Cedit Control, I issued a SetWindowText() function many times in my program.. I traced my program, Now In the first call to SetWindowText(), the function succeeds and it sets the text .. Now on the second call the function asserts, and upon tracing, The ::IsWindow(hwndofCedit) returns FALSE. My question when does an HWND becomes invalid? aside from window destruction?.. My Cedit's parent is not a CDialog, would that be an issue? "geez i cracked myself off.."
A HWND becomes invalid when the windows is destroyed. Sorry, but there is no 'aside', either the window exist or it does not. I will note however that the windows destruction has nothing to do with wether or not the destructor for a CWnd object is called. The handle belongs to the system and not the code using it. Therefore, you must be telling the system to destroy the window. And no: the parent of the window is not an issue, unless the parent window was closed, in which case, all its child windows would also be closed (destroyed). INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen
-
A HWND becomes invalid when the windows is destroyed. Sorry, but there is no 'aside', either the window exist or it does not. I will note however that the windows destruction has nothing to do with wether or not the destructor for a CWnd object is called. The handle belongs to the system and not the code using it. Therefore, you must be telling the system to destroy the window. And no: the parent of the window is not an issue, unless the parent window was closed, in which case, all its child windows would also be closed (destroyed). INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen
-
But why is it that when I test ::IsValidWindow(CEdit::GetSafeHwnd()), it returns FALSE in the middle of my program, and I have not destroyed the CEdit yet.. I have seen in some articles that there are some events that makes the window handles invalid..
There are only two things that can happen here, if IsValidWindow returns TRUE and then soon after returns false, either the window is destroyed or the value that CEdit::GetSafeHwnd() returns is now wrong. This can happen if the CWnd data structure gets trashed. Look at the m_hWnd value and see if it changes. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
There are only two things that can happen here, if IsValidWindow returns TRUE and then soon after returns false, either the window is destroyed or the value that CEdit::GetSafeHwnd() returns is now wrong. This can happen if the CWnd data structure gets trashed. Look at the m_hWnd value and see if it changes. Tim Smith I'm going to patent thought. I have yet to see any prior art.
I can tell you that the window was not destroyed.. so definiteyly my problem is GetSafeHWnd() changing to a wrong value.. My question is how did it changed value? how did the window structure get trashed? I Didn't do anything to it... I just set its text..
-
I can tell you that the window was not destroyed.. so definiteyly my problem is GetSafeHWnd() changing to a wrong value.. My question is how did it changed value? how did the window structure get trashed? I Didn't do anything to it... I just set its text..
-
Hello... I known only two situations where a window handle is invalid. 1. window isn't created 2. window destroyed It's possible that window creation or subclassing failed... :doh:
Hi All!!! hehe.. you know what, i found out the problem of my HWND being invalid... it turns out Im looking into a different CMainFrame pointer that holds the control bar that holds the CEdit.. I have implemented 2 Doc/View architectures in my program.. So I have 2 frames, 1 Mainframe and 1 Framewnd(inside another control bar)... It turns out i cast the Framewnd which has no CEdit variable, to CMainFrame.. So im looking in the framewnd which has no CEdit at all, not created.. So that solves my problem, I just got the pointer to the actual CMainframe which has the CEdit... tnx for the replies!! :-D Maverick "you can be my wingman anytime.."