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++delphigraphicshelpquestion
2 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.
  • M Offline
    M Offline
    Manu81
    wrote on last edited by
    #1

    hai, I want to attach a bitmap to my button using subclass.I'm using win32 vc++. I have subclassed my button(IDC_BUTTON1). ie. i have done lpfnOldWndProc = (WNDPROC)SetWindowLong( GetDlgItem(hDialog,IDC_BUTTON1),GWL_WNDPROC,(DWORD)SubClassFunc); ...... LONG FAR PASCAL SubClassFunc(HWND hWnd, UINT uMsg, WPARAM wParam, LONG lParam) { } but inside this SubClassFunc what should I do to attach the bitmap(IDB_BITMAP1)? Can anyone help?

    A 1 Reply Last reply
    0
    • M Manu81

      hai, I want to attach a bitmap to my button using subclass.I'm using win32 vc++. I have subclassed my button(IDC_BUTTON1). ie. i have done lpfnOldWndProc = (WNDPROC)SetWindowLong( GetDlgItem(hDialog,IDC_BUTTON1),GWL_WNDPROC,(DWORD)SubClassFunc); ...... LONG FAR PASCAL SubClassFunc(HWND hWnd, UINT uMsg, WPARAM wParam, LONG lParam) { } but inside this SubClassFunc what should I do to attach the bitmap(IDB_BITMAP1)? Can anyone help?

      A Offline
      A Offline
      Antti Keskinen
      wrote on last edited by
      #2

      Subclassing is quite powerful, actually. Not only can you get a pre-sniff on what is going to happen, you can get a post-sniff as well. The trick with post-sniffing is that you call the original window procedure first and save it's return value into a local variable. When this is done, check the uMsg parameter. If it is 'WM_PAINT', then enter a handler. In this handler, get the button's DC (You have the HWND, so just use GetDC). Then create a compatible DC with this one. Load the bitmap from file/resource. Select the bitmap into the memory DC. Blit from the memory DC into the button's DC so, that the starting point of the blit operation is NOT in point 0,0, but somewhere more to the middle. How middle it is is determined by the size of the bitmap and where you want it on the button. Use GetWindowRect to get the bouding rectangle of the button's DC. Then do math :) But, all in all, the idea is to first allow the original window procedure to run, then do post-processing by applying the bitmap. Allowing the original procedure to run first ensures that the borders and the button state (normal/sunken) are drawn correctly. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

      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