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. subclass a button, how let it know CLICK event

subclass a button, how let it know CLICK event

Scheduled Pinned Locked Moved C / C++ / MFC
c++
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.
  • H Offline
    H Offline
    HOW WHAT
    wrote on last edited by
    #1

    NOT MFC

    N S 2 Replies Last reply
    0
    • H HOW WHAT

      NOT MFC

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      when a button is clicked, the parent of the button will receive WM_COMMAND message. Check whether the high-order word of the wparam is BN_CLICKED. if( message == WM_COMMAND && BN_CLICKED == HIWORD( wParam)) { // button is clicked. } the lparam will be having the handle of button.

      nave

      H 1 Reply Last reply
      0
      • H HOW WHAT

        NOT MFC

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

        The basic technique used to subclass a window using straight Win32 is as follows: - Declare a variable of type WNDPROC to point to the old window procedure before subclassing. i.e. WNDPROC g_pSuperClass; - Write a replacement window procedure which defers all unhandled messages to the old one. i.e. LRESULT CALLBACK MyWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {     return CallWindowProc(g_pSuperClass, hwnd, uMsg, wParam, lParam); } - Now subclass the window with code like this: g_pSuperClass = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hwndButton, GWLP_WNDPROC)); SetWindowLongPtr(hwndButton, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&MyWindowProc)); Now to specialize the window alter the code in MyWindowProc. To handle the click event however you don't need to subclass the window. The button sends the BN_CLICK notification to its parent when it's clicked. This messages is packaged in a WM_COMMAND message.

        Steve

        1 Reply Last reply
        0
        • N Naveen

          when a button is clicked, the parent of the button will receive WM_COMMAND message. Check whether the high-order word of the wparam is BN_CLICKED. if( message == WM_COMMAND && BN_CLICKED == HIWORD( wParam)) { // button is clicked. } the lparam will be having the handle of button.

          nave

          H Offline
          H Offline
          HOW WHAT
          wrote on last edited by
          #4

          but i want my button handle click, only use itself message. LRESULT ButtonProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { ........ } return DefWindowProc(message, wParam, lParam); }

          N 1 Reply Last reply
          0
          • H HOW WHAT

            but i want my button handle click, only use itself message. LRESULT ButtonProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { ........ } return DefWindowProc(message, wParam, lParam); }

            N Offline
            N Offline
            Naveen
            wrote on last edited by
            #5

            in that case u must find the click event by handling the WM_LBUTTONDOWN and WM_LBUTTOUP messages.

            nave

            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