1 year ago
#330306
Mateusz
How to proper draw in multiple windows in winapi?
I was told recently that in WM_PAINT:
message I should only use BeginPaint()
and EndPaint()
.
But what when I need multiple windows with bitmaps or drawings in my main window? How should I manage this in proper way?
So far I was using this routines, that worked for me and was logic for me. Is it wrong? What is the proper way?
Thank You in advance.
case WM_PAINT:
{
// main window - that contains other sub windows
PAINTSTRUCT ps;
HDC hdc = BeginPaint(_hwnd, &ps);
EndPaint(_hwnd, &ps);
// a window that shows a 256x256 texture:
PAINTSTRUCT ps_texture_256;
HDC hdc_texture_256 = BeginPaint(GetDlgItem(_hwnd, IDS_DC_TEXTURE_256), &ps_texture_256);
HDC hdc_tmp_256 = CreateCompatibleDC(hdc_texture_256);
SelectObject(hdc_tmp_256, convert_hbm_texture_256);
BitBlt(hdc_texture_256, 0, 0, 256, 256, hdc_tmp_256, 0, 0, SRCCOPY);
DeleteObject(convert_hbm_texture_256);
DeleteDC(hdc_tmp_256);
EndPaint(GetDlgItem(_hwnd, IDS_DC_TEXTURE_256), &ps_texture_256);
// a smaller window that shows 128x128 texture:
PAINTSTRUCT ps_texture_128;
HDC hdc_texture_128 = BeginPaint(GetDlgItem(_hwnd, IDS_DC_TEXTURE_128), &ps_texture_128);
HDC hdc_tmp_128 = CreateCompatibleDC(hdc_texture_128);
SelectObject(hdc_tmp_128, convert_hbm_texture_128);
BitBlt(hdc_texture_128, 0, 0, 128, 128, hdc_tmp_128, 0, 0, SRCCOPY);
DeleteObject(convert_hbm_texture_128);
DeleteDC(hdc_tmp_128);
EndPaint(GetDlgItem(_hwnd, IDS_DC_TEXTURE_128), &ps_texture_128);
return (INT_PTR)TRUE;
}
windows
winapi
gdi
0 Answers
Your Answer