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. ON_CONTROL_RANGE and BN_PUSHED

ON_CONTROL_RANGE and BN_PUSHED

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpquestion
2 Posts 1 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.
  • S Offline
    S Offline
    Scott H Settlemier
    wrote on last edited by
    #1

    Darn, sometimes something that should be easy gets complicated. I have a modeless dialog that send messages to its parent window. These are WM_COMMAND messages for BN_CLICKED, BN_PUSHED, and BN_UNPUSHED. e.g.

    GetParent()->SendMessage(WM_COMMAND,(WPARAM)(BN_PUSHED<<16|nID),0);

    To the parent window's message map I have added the entries:

    ON_CONTROL_RANGE(BN_CLICKED,ID_0,ID_N,OnClickX)
    ON_CONTROL_RANGE(BN_PUSHED,ID_0,ID_N,OnPushedX)
    ON_CONTROL_RANGE(BN_UNPUSHED,ID_0,ID_N,OnUnpushedX)

    However, OnClickX is called to for BN_CLICKED, BN_PUSHED, and BN_UNPUSHED. I walked through with the debugger and the correct message is sent (WM_COMMAND with BN_CLICKED, BN_PUSHED, or BN_CLICKED) but the wrong handler is invoked. (I stopped short of trying to walk through the CCmdTarget's use of the message map (that is some seriously ugly code to walk through.) in the hope that someone will have some knowledge here. Am I doing something wrong? missing something here? I tried changing the order of the message map entries in case there was a problem

    S 1 Reply Last reply
    0
    • S Scott H Settlemier

      Darn, sometimes something that should be easy gets complicated. I have a modeless dialog that send messages to its parent window. These are WM_COMMAND messages for BN_CLICKED, BN_PUSHED, and BN_UNPUSHED. e.g.

      GetParent()->SendMessage(WM_COMMAND,(WPARAM)(BN_PUSHED<<16|nID),0);

      To the parent window's message map I have added the entries:

      ON_CONTROL_RANGE(BN_CLICKED,ID_0,ID_N,OnClickX)
      ON_CONTROL_RANGE(BN_PUSHED,ID_0,ID_N,OnPushedX)
      ON_CONTROL_RANGE(BN_UNPUSHED,ID_0,ID_N,OnUnpushedX)

      However, OnClickX is called to for BN_CLICKED, BN_PUSHED, and BN_UNPUSHED. I walked through with the debugger and the correct message is sent (WM_COMMAND with BN_CLICKED, BN_PUSHED, or BN_CLICKED) but the wrong handler is invoked. (I stopped short of trying to walk through the CCmdTarget's use of the message map (that is some seriously ugly code to walk through.) in the hope that someone will have some knowledge here. Am I doing something wrong? missing something here? I tried changing the order of the message map entries in case there was a problem

      S Offline
      S Offline
      Scott H Settlemier
      wrote on last edited by
      #2

      Ah, I found the problem. If I didn't pass the button's window handle in the lParam, then the CWnd's OnCommand handler, zeros the nCode parameter, effectively making everything into a BN_CLICKED. So I need to do:

      GetParent()->SendMessage(WM_COMMAND,(WPARAM)(BN_PUSHED<<16|nID),hBtn);

      Should I have known that? (i.e. what purpose does that zeroing serve in OnCommand?)

      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