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. PreTranslateMessage and WM_SETFOCUS

PreTranslateMessage and WM_SETFOCUS

Scheduled Pinned Locked Moved C / C++ / MFC
c++javascriptquestion
5 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.
  • J Offline
    J Offline
    Jim Crafton
    wrote on last edited by
    #1

    I have an MFC app and I'd like to get notified whenever a any of several possible child windows recv focus. I thought I could just override the main window's PreTranslateMessage() function and simply check the pMsg->message value and if it's a WM_SETFOCUS and the pMsg->hWnd is one of the windows I care about then react accordingly. However I never get ANY WM_SETFOCUS messages! Am I misunderstanding how PreTranslateMessage is supposed to be used or is there an alternate approach? I'd prefer not to have to subclass each of the controls, but I will if I have to.

    ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

    P W 3 Replies Last reply
    0
    • J Jim Crafton

      I have an MFC app and I'd like to get notified whenever a any of several possible child windows recv focus. I thought I could just override the main window's PreTranslateMessage() function and simply check the pMsg->message value and if it's a WM_SETFOCUS and the pMsg->hWnd is one of the windows I care about then react accordingly. However I never get ANY WM_SETFOCUS messages! Am I misunderstanding how PreTranslateMessage is supposed to be used or is there an alternate approach? I'd prefer not to have to subclass each of the controls, but I will if I have to.

      ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      AFAIK the WM_* messages are sent to the pMsg->hWnd window. If that window does not handle the message then it is sent to the parent of that window and on up the parent chain until one of the windows actually handles the message (returns TRUE), or the there are no more parent windows. So the only way the main window will get the WM_SETFOCUS message is if none of the child windows handle it, or they return false if they do. See CWnd::WalkPretranslateTree() and AfxInternalPreTranslateMessage() in the MFC sources for more details (Set a breakpoint in your PreTranslateMessage() function and use the call stack)


      You may be right
      I may be crazy
      -- Billy Joel --

      Within you lies the power for good, use it!!!

      1 Reply Last reply
      0
      • J Jim Crafton

        I have an MFC app and I'd like to get notified whenever a any of several possible child windows recv focus. I thought I could just override the main window's PreTranslateMessage() function and simply check the pMsg->message value and if it's a WM_SETFOCUS and the pMsg->hWnd is one of the windows I care about then react accordingly. However I never get ANY WM_SETFOCUS messages! Am I misunderstanding how PreTranslateMessage is supposed to be used or is there an alternate approach? I'd prefer not to have to subclass each of the controls, but I will if I have to.

        ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

        W Offline
        W Offline
        William Wang
        wrote on last edited by
        #3

        the problem is not from the way u try to catch the message, but from the message u want to catch, WM_SETFOCUS cound't be caught, I tried to catch it in the simplest window's program. catch this message before TranslateMessage calls, but still, couldn't get it. somebody knows why?

        life is like a box of chocolate,you never know what you r going to get.

        1 Reply Last reply
        0
        • J Jim Crafton

          I have an MFC app and I'd like to get notified whenever a any of several possible child windows recv focus. I thought I could just override the main window's PreTranslateMessage() function and simply check the pMsg->message value and if it's a WM_SETFOCUS and the pMsg->hWnd is one of the windows I care about then react accordingly. However I never get ANY WM_SETFOCUS messages! Am I misunderstanding how PreTranslateMessage is supposed to be used or is there an alternate approach? I'd prefer not to have to subclass each of the controls, but I will if I have to.

          ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          Jim, did you get a solution for this without rewriting all your child controls? You may find that setting up a WH_CALLWNDPROC hook is the easiest way to be notified when a window in your app recieves the WM_SETFOCUS message.


          You may be right
          I may be crazy
          -- Billy Joel --

          Within you lies the power for good, use it!!!

          J 1 Reply Last reply
          0
          • P PJ Arends

            Jim, did you get a solution for this without rewriting all your child controls? You may find that setting up a WH_CALLWNDPROC hook is the easiest way to be notified when a window in your app recieves the WM_SETFOCUS message.


            You may be right
            I may be crazy
            -- Billy Joel --

            Within you lies the power for good, use it!!!

            J Offline
            J Offline
            Jim Crafton
            wrote on last edited by
            #5

            No, in the end I just added the OnSetFocus() methods to the various controls. :) Wasn't that big of a deal, just annoying. But then that pretty much sums up MFC development, for me at least :)

            ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

            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