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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get hWnd in MFC?

How to get hWnd in MFC?

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsjsontutorialquestion
3 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.
  • B Offline
    B Offline
    bankai123
    wrote on last edited by
    #1

    Using the Win32 API here he is some sample code to get the device context and create a bitmap HDC hBackDC=NULL; HDC hdc=GetDC(hWnd); hBackDC=CreateCompatibleDC(hdc); BITMAPINFO bmpInfo; ZeroMemory(&bmpInfo,sizeof(bmpInfo)); bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biBitCount=32; bmpInfo.bmiHeader.biCompression=BI_RGB; bmpInfo.bmiHeader.biSizeImage=320*240*4; bmpInfo.bmiHeader.biPlanes=1; bmpInfo.bmiHeader.biHeight=240; bmpInfo.bmiHeader.biWidth=320; hBackBitmap=CreateDIBSection(hBackDC,&bmpInfo,DIB_RGB_COLORS,&pBits,NULL,NULL); where "hWnd" is from LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) I'm wondering how I get the handle of the window (hWnd) in MFC? Thanks

    H P 2 Replies Last reply
    0
    • B bankai123

      Using the Win32 API here he is some sample code to get the device context and create a bitmap HDC hBackDC=NULL; HDC hdc=GetDC(hWnd); hBackDC=CreateCompatibleDC(hdc); BITMAPINFO bmpInfo; ZeroMemory(&bmpInfo,sizeof(bmpInfo)); bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biBitCount=32; bmpInfo.bmiHeader.biCompression=BI_RGB; bmpInfo.bmiHeader.biSizeImage=320*240*4; bmpInfo.bmiHeader.biPlanes=1; bmpInfo.bmiHeader.biHeight=240; bmpInfo.bmiHeader.biWidth=320; hBackBitmap=CreateDIBSection(hBackDC,&bmpInfo,DIB_RGB_COLORS,&pBits,NULL,NULL); where "hWnd" is from LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) I'm wondering how I get the handle of the window (hWnd) in MFC? Thanks

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      bankai123 wrote:

      I'm wondering how I get the handle of the window (hWnd) in MFC?

      See CWnd::GetSafeHwnd()[^]


      WhiteSky


      1 Reply Last reply
      0
      • B bankai123

        Using the Win32 API here he is some sample code to get the device context and create a bitmap HDC hBackDC=NULL; HDC hdc=GetDC(hWnd); hBackDC=CreateCompatibleDC(hdc); BITMAPINFO bmpInfo; ZeroMemory(&bmpInfo,sizeof(bmpInfo)); bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biBitCount=32; bmpInfo.bmiHeader.biCompression=BI_RGB; bmpInfo.bmiHeader.biSizeImage=320*240*4; bmpInfo.bmiHeader.biPlanes=1; bmpInfo.bmiHeader.biHeight=240; bmpInfo.bmiHeader.biWidth=320; hBackBitmap=CreateDIBSection(hBackDC,&bmpInfo,DIB_RGB_COLORS,&pBits,NULL,NULL); where "hWnd" is from LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) I'm wondering how I get the handle of the window (hWnd) in MFC? Thanks

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #3

        bankai123 wrote:

        HDC hdc=GetDC(hWnd);

        There are wrapper classes for such win32 functionalities in MFC. In this case you can use CDC or derived class.


        Prasad MS MVP -  VC++

        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