Hi all,
I'm trying to put a simple program together without using MFC whatsoever. In other words, by using the box-standard WIndowsAPI calls. However, I've run into a stumbling block when it comes to double-buffering to avoid flicker on the window during drawing. Funny thing is I haven't had any problems at all doing this with MFC but when I use standard API calls in the equivalent everything goes bananas.
Here's the code I'm using:
[tt]
// get the HDC for this window
HDC hDC = ::GetWindowDC(m_hWnd);
RECT rc;
// get the window rectangle
::GetClientRect(m_hWnd,&rc);
// create compatible HDC & HBITMAP and
// select the bmp into the offscreen HDC
HDC gwDC = ::CreateCompatibleDC(hDC);
HBITMAP gwBMP = ::CreateCompatibleBitmap(hDC,rc.right-rc.left,
rc.bottom-rc.top);
HBITMAP oldBMP = (HBITMAP)::SelectObject(gwDC,gwBMP);
// draw something to the offscreen HDC
::InflateRect(&rc,-50,-50);
::Rectangle(gwDC,rc.left,rc.top,rc.right,rc.bottom);
// BitBlt the image from the offscreen HDC
// to the window's HDC
::BitBlt(hDC,0,0,rc.right-rc.left,
rc.bottom-rc.top,gwDC,0,0,SRCCOPY);
// clean up everything
::ReleaseDC(m_hWnd,hDC);
::SelectObject(gwDC,oldBMP);
:
eleteObject(gwBMP);
:
eleteDC(gwDC);[/tt]
It seems to me that I must be missing a step or doing something incorrect. Using the MFC equivalents this works great but when I use the above code in a simple dialog it draws to the top left of the title bar rather than the client area AND it tends to lock up also.
What's going on and how do I correct it?
programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
I'm trying to put a simple program together without using MFC whatsoever. In other words, by using the box-standard WIndowsAPI calls. However, I've run into a stumbling block when it comes to double-buffering to avoid flicker on the window during drawing. Funny thing is I haven't had any problems at all doing this with MFC but when I use standard API calls in the equivalent everything goes bananas.
Here's the code I'm using:
[tt]
// get the HDC for this window
HDC hDC = ::GetWindowDC(m_hWnd);
RECT rc;
// get the window rectangle
::GetClientRect(m_hWnd,&rc);
// create compatible HDC & HBITMAP and
// select the bmp into the offscreen HDC
HDC gwDC = ::CreateCompatibleDC(hDC);
HBITMAP gwBMP = ::CreateCompatibleBitmap(hDC,rc.right-rc.left,
rc.bottom-rc.top);
HBITMAP oldBMP = (HBITMAP)::SelectObject(gwDC,gwBMP);
// draw something to the offscreen HDC
::InflateRect(&rc,-50,-50);
::Rectangle(gwDC,rc.left,rc.top,rc.right,rc.bottom);
// BitBlt the image from the offscreen HDC
// to the window's HDC
::BitBlt(hDC,0,0,rc.right-rc.left,
rc.bottom-rc.top,gwDC,0,0,SRCCOPY);
// clean up everything
::ReleaseDC(m_hWnd,hDC);
::SelectObject(gwDC,oldBMP);
:
:
It seems to me that I must be missing a step or doing something incorrect. Using the MFC equivalents this works great but when I use the above code in a simple dialog it draws to the top left of the title bar rather than the client area AND it tends to lock up also.
What's going on and how do I correct it?
![[bugeyed] [bugeyed] [bugeyed]](/data/assets/smilies/bugeyed.gif)

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.