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. Is there any method to check for a valid hwnd from an another thread?

Is there any method to check for a valid hwnd from an another thread?

Scheduled Pinned Locked Moved C / C++ / MFC
jsonquestion
3 Posts 3 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.
  • N Offline
    N Offline
    namaskaaram
    wrote on last edited by
    #1

    Apart the api "IsWndow" which the microsoft doesnt recommend to be used other than by the thread which had created the window,is there any method to check for a valid hwnd i.e from an another thread?

    dont want,dont want thinking,climbing on head and jumping grass! (venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)

    S A 2 Replies Last reply
    0
    • N namaskaaram

      Apart the api "IsWndow" which the microsoft doesnt recommend to be used other than by the thread which had created the window,is there any method to check for a valid hwnd i.e from an another thread?

      dont want,dont want thinking,climbing on head and jumping grass! (venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      From MSDN:

      A thread should not use IsWindow for a window that it did not create because the window could be destroyed after this function was called. Further, because window handles are recycled the handle could even point to a different window.

      Are you sure this is a concern? If you're going to do anything with the HWND the same applies (it could be destroyed). Just use IsWindow.

      Steve

      1 Reply Last reply
      0
      • N namaskaaram

        Apart the api "IsWndow" which the microsoft doesnt recommend to be used other than by the thread which had created the window,is there any method to check for a valid hwnd i.e from an another thread?

        dont want,dont want thinking,climbing on head and jumping grass! (venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)

        A Offline
        A Offline
        asrelu
        wrote on last edited by
        #3

        If the target window is a top level window you can install a hook (see WH_SHELL) to be notified about destroying top level windows. But frankly, no matter what technique you use, you can be never sure. If everything looks ok and you send a message to that window, the window still can be destroyed in the same moment(almost the same). Or while is processing your message. Simply there is no way to prevent a foreign window from beeing destroyed anytime. The only thing you can do is to implement thoroughful error processing, verify the effects of each of the messages sent and check regularly if the handle is still for the same window and not reused for another one. Working with a foreign windows is something similar to working with dialog boxes. You can never be sure what stupidity will a user type in an edit box so you have to check everything. I think a window beeing destroyed exactly in the very moment when you need it, is a very rare occurence. Just make sure to limit to minimum the damages of such an event. If your software stops abruptly and hours of the user's unsaved work are gone, that's unacceptable. If the only thing that happens is an error message "Internal error, please repeat the last command", that's acceptable, even if it's not desirable. Even the best software fails sometimes. The only question is how it fails: disastruously or gracefully ?

        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