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. Windows API
  4. PeekMessage for Parent Window

PeekMessage for Parent Window

Scheduled Pinned Locked Moved Windows API
beta-testingquestioncode-reviewworkspace
3 Posts 2 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.
  • C Offline
    C Offline
    Craig Longman
    wrote on last edited by
    #1

    I'm writing a plug-in for a product that provides extremely little (ie. none) feedback about the window environment. Even something as simple as a resize event is not delivered. So, I'm trying to hook into the parent window(s) to catch messages that they receive and process them appropriately. To that end, I've created a simple class that looks something like this:

    CSizeWatcher::operator()( HWND hWnd )
    {
    MSG zMsg;

    while( true )
    {
    if( ::PeekMessage( &zMsg, hWnd, WM_SIZE, WM_SIZE, PM_NOREMOVE ) )
    {
    if( zMsg.message == WM_QUIT )
    {
    break;
    }

      if( zMsg.message == WM\_SIZE )
      {
        printf( "oh..." );
      }
    }
    

    }
    }

    And it gets invoked from the OnInitDialog method like this (effectively, it is actually instantiated in a separate thread):

    zWatcher( ::GetParent( m_hWnd ) );

    Using Spy++, I see that I do have the correct HWND, but I never seem to get any messages. PeekMessage never returns true. I have tried removing the Min and Max, setting both to zero, but again, no messages. Is this an inappropriate use of PeekMessage? Can one not use it to peek into the queues for parent (or any) windows? Perhaps Hooks are what I need to look at? Thanks, CraigL

    C 1 Reply Last reply
    0
    • C Craig Longman

      I'm writing a plug-in for a product that provides extremely little (ie. none) feedback about the window environment. Even something as simple as a resize event is not delivered. So, I'm trying to hook into the parent window(s) to catch messages that they receive and process them appropriately. To that end, I've created a simple class that looks something like this:

      CSizeWatcher::operator()( HWND hWnd )
      {
      MSG zMsg;

      while( true )
      {
      if( ::PeekMessage( &zMsg, hWnd, WM_SIZE, WM_SIZE, PM_NOREMOVE ) )
      {
      if( zMsg.message == WM_QUIT )
      {
      break;
      }

        if( zMsg.message == WM\_SIZE )
        {
          printf( "oh..." );
        }
      }
      

      }
      }

      And it gets invoked from the OnInitDialog method like this (effectively, it is actually instantiated in a separate thread):

      zWatcher( ::GetParent( m_hWnd ) );

      Using Spy++, I see that I do have the correct HWND, but I never seem to get any messages. PeekMessage never returns true. I have tried removing the Min and Max, setting both to zero, but again, no messages. Is this an inappropriate use of PeekMessage? Can one not use it to peek into the queues for parent (or any) windows? Perhaps Hooks are what I need to look at? Thanks, CraigL

      C Offline
      C Offline
      Craig Longman
      wrote on last edited by
      #2

      Well, absolutely no luck getting the PeekMessage to work, so I've instead gone and sub-classed the window. Although it's far more tricky from c++, it does get what I need.

      S 1 Reply Last reply
      0
      • C Craig Longman

        Well, absolutely no luck getting the PeekMessage to work, so I've instead gone and sub-classed the window. Although it's far more tricky from c++, it does get what I need.

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

        GetMessage[^] and PeekMessage[^] use the message queue: they will only work for messages that were posted (see PostMessage[^]). The WM_SIZE[^] message is sent (see SendMessage[^]). Subclassing or hooking (See SetWindowsHookEx[^]) is the way to go.

        Steve

        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