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. subclassing in win32

subclassing in win32

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

    hai, I want to attach a bitmap to my button control.I'm using win32 vc++ and I am just the beginner to vc++. I used loadbitmap() and sendmessage() to button control.It worked.But I was requested to do with subclassing. I pretty much have no idea.I tried MSDN. It's there for MFC (subclassdlgitem())but I want to do in win32.Can anyone help me?

    P A 2 Replies Last reply
    0
    • M Manu81

      hai, I want to attach a bitmap to my button control.I'm using win32 vc++ and I am just the beginner to vc++. I used loadbitmap() and sendmessage() to button control.It worked.But I was requested to do with subclassing. I pretty much have no idea.I tried MSDN. It's there for MFC (subclassdlgitem())but I want to do in win32.Can anyone help me?

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

      Subclassing in Win32 requires that you write your own window procedure (see WindowProc in MSDN) and specify it as the lpfnWndProc parameter in the WNDCLASS structure you use to register your window class. You use the class name you used in the WNDCLASS structure in your call to CreateWindow when you want to create your button. see MSDN for: WindowProc, WNDCLASS, RegisterClass, CreateWindow.


      [

      ](http://www.canucks.com)"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

      1 Reply Last reply
      0
      • M Manu81

        hai, I want to attach a bitmap to my button control.I'm using win32 vc++ and I am just the beginner to vc++. I used loadbitmap() and sendmessage() to button control.It worked.But I was requested to do with subclassing. I pretty much have no idea.I tried MSDN. It's there for MFC (subclassdlgitem())but I want to do in win32.Can anyone help me?

        A Offline
        A Offline
        A T I F
        wrote on last edited by
        #3

        You can try to do something like this.... WNDPROC wpOrigButtonProc; LRESULT APIENTRY DlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HWND hwndButton; switch(uMsg) { case WM_INITDIALOG: // Retrieve the handle to the edit control. hwndButton = GetDlgItem(hwndDlg, ID_BUTTON); // Subclass the edit control. wpOrigButtonProc = (WNDPROC) SetWindowLong(hwndButton, GWL_WNDPROC, (LONG) ButtonSubclassProc); // // Continue the initialization procedure. // return TRUE; case WM_DESTROY: // Remove the subclass from the edit control. SetWindowLong(hwndButton , GWL_WNDPROC, (LONG) wpOrigButtonProc); // // Continue the cleanup procedure. // break; } return FALSE; UNREFERENCED_PARAMETER(lParam); } // Subclass procedure LRESULT APIENTRY ButtonSubclassProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case .... /* Process the messages you want here */ } /* else pass it to the original handler */ return CallWindowProc(wpOrigButtonProc, hwnd, uMsg, wParam, lParam); } I hope this helps you out.

        M 1 Reply Last reply
        0
        • A A T I F

          You can try to do something like this.... WNDPROC wpOrigButtonProc; LRESULT APIENTRY DlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HWND hwndButton; switch(uMsg) { case WM_INITDIALOG: // Retrieve the handle to the edit control. hwndButton = GetDlgItem(hwndDlg, ID_BUTTON); // Subclass the edit control. wpOrigButtonProc = (WNDPROC) SetWindowLong(hwndButton, GWL_WNDPROC, (LONG) ButtonSubclassProc); // // Continue the initialization procedure. // return TRUE; case WM_DESTROY: // Remove the subclass from the edit control. SetWindowLong(hwndButton , GWL_WNDPROC, (LONG) wpOrigButtonProc); // // Continue the cleanup procedure. // break; } return FALSE; UNREFERENCED_PARAMETER(lParam); } // Subclass procedure LRESULT APIENTRY ButtonSubclassProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case .... /* Process the messages you want here */ } /* else pass it to the original handler */ return CallWindowProc(wpOrigButtonProc, hwnd, uMsg, wParam, lParam); } I hope this helps you out.

          M Offline
          M Offline
          Manu81
          wrote on last edited by
          #4

          hai, Thanks a lot.I understood your code.But inside this subclass procedure what I should do to attach my bitmap to the button? thanks.

          A 1 Reply Last reply
          0
          • M Manu81

            hai, Thanks a lot.I understood your code.But inside this subclass procedure what I should do to attach my bitmap to the button? thanks.

            A Offline
            A Offline
            A T I F
            wrote on last edited by
            #5

            Well catch WM_PAINT or something and use StretchBlt or BitBlt to draw the image in the button window. You will have to check if WM_PAINT is the most appropriate message to use here...

            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