Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. When is an HWND invalid?

When is an HWND invalid?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maverick
    wrote on last edited by
    #1

    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.."

    J 1 Reply Last reply
    0
    • M Maverick

      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.."

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • J John R Shaw

        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

        M Offline
        M Offline
        Maverick
        wrote on last edited by
        #3

        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..

        T 1 Reply Last reply
        0
        • M Maverick

          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..

          T Offline
          T Offline
          Tim Smith
          wrote on last edited by
          #4

          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.

          M 1 Reply Last reply
          0
          • T Tim Smith

            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.

            M Offline
            M Offline
            Maverick
            wrote on last edited by
            #5

            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..

            H 1 Reply Last reply
            0
            • M Maverick

              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..

              H Offline
              H Offline
              HumanOsc
              wrote on last edited by
              #6

              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:

              M 1 Reply Last reply
              0
              • H HumanOsc

                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:

                M Offline
                M Offline
                Maverick
                wrote on last edited by
                #7

                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.."

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups