|
Joined: Mar 2003
Posts: 187
Vogon poet
|
OP
Vogon poet
Joined: Mar 2003
Posts: 187 |
Ok, I'm just trying to draw a .bmp onto an MDI Client background. Here is my code. which isn't working. Need to know why.
//globals
HBITMAP hbmp;
BITMAP bm;
WNDPROC oldproc;
//the function commands
//mdi client retrieval here blah.
//mdi is the hwnd
hbmp = (HBITMAP)LoadImage(NULL,data, IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
ZeroMemory(&bm, sizeof(BITMAP));
GetObject(hbmp, sizeof(BITMAP), (LPVOID)&bm);
//subclassing the mdi
oldproc = (WNDPROC)GetWindowLong(mdi, GWL_WNDPROC);
SetWindowLong(mdi, GWL_WNDPROC, (LONG)Newproc);
//the subclassed proc
LRESULT CALLBACK Newproc(HWND hwnd,
UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg) {
case WM_SIZE:
SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)GetDC(hwnd), 0);
return 1;
break;
case WM_ERASEBKGND:
HDC hdc = (HDC)wp;
RECT rect;
GetClientRect(hwnd,&rect);
HDC hcompdc = CreateCompatibleDC(NULL);
HBITMAP oldbmp = NULL;
UINT width = rect.right - rect.left;
UINT height = rect.bottom - rect.top;
oldbmp = (HBITMAP) SelectObject(hcompdc,hbmp);
UINT nx, ny;
for(nx = 0; nx < width; nx += bm.bmWidth)
for (ny = 0; ny < height; ny += bm.bmHeight)
BitBlt(hdc,nx,ny,bm.bmWidth,bm.bmHeight,hcompdc,0,0,SRCCOPY);
SelectObject(hcompdc,oldbmp);
return 1;
break;
return CallWindowProc(oldproc, hwnd, msg, wp, lp);
}
return CallWindowProc(oldproc, hwnd, msg, wp, lp);
}
so why isnt this working? Thanks
|
|
|
|
Joined: Jun 2004
Posts: 14
Pikka bird
|
Pikka bird
Joined: Jun 2004
Posts: 14 |
A few things...
When you process WM_SIZE, there's no need to send the WM_ERASEBKGND message yourself. The system does that.
In this case, you don't need to process the WM_ERASEBKGND message at all. Since you're repainting the entire window, there's no need to erase any part of it first. Just process the WM_PAINT message and return zero to indicate that you've processed it.
Be sure to cleanup after yourself. Delete the GDI objects you've created after you're done using them.
|
|
|
|
Joined: Mar 2003
Posts: 187
Vogon poet
|
OP
Vogon poet
Joined: Mar 2003
Posts: 187 |
so get rid of WM_SIZE, and replace WM_ERASEBKGND with WM_PAINT?
|
|
|
|
Joined: Jun 2004
Posts: 14
Pikka bird
|
Pikka bird
Joined: Jun 2004
Posts: 14 |
WM_SIZE is still a good place to resize your memory DC and selected bitmap object. Then in WM_PAINT, all you have to do is BitBlt your memory DC to your window DC.
|
|
|
|
Joined: Jun 2004
Posts: 14
Pikka bird
|
Pikka bird
Joined: Jun 2004
Posts: 14 |
Here's a sample I made for someone a couple years ago. It's not exactly what you're trying to do but maybe it'll be helpful.
// Sample assumes: // // HDC g_hdcMem already created with CreateCompatibleDC() before subclassing the MDI window. // Be sure to delete g_hdcMem when your application is done with it. // // HBITMAP g_hbmMem created/deleted when processing WM_SIZE. // // HFONT BigFont created before subclassing the MDI window. // // MDI client window subclassed. OldProc = (WNDPROC)SetWindowLong(hwndMdiClient, GWL_WNDPROC, (LONG)MdiClientProc); // // This sample does no error checking. Be careful.
void DoGradient(HDC hdc, int cx, int cy) { TRIVERTEX vert[3][2]; GRADIENT_RECT Rect;
vert[0][0].x = 0; vert[0][0].y = 0; vert[0][0].Red = 0x0000; vert[0][0].Green = 0x0000; vert[0][0].Blue = 0x0000; vert[0][0].Alpha = 0x0000;
vert[0][1].x = cx; vert[0][1].y = cy/2; vert[0][1].Red = 0xdd00; vert[0][1].Green = 0xee00; vert[0][1].Blue = 0xff00; vert[0][1].Alpha = 0x0000;
vert[1][0].x = 0; vert[1][0].y = cy/2; vert[1][0].Red = 0xdd00; vert[1][0].Green = 0xee00; vert[1][0].Blue = 0xff00; vert[1][0].Alpha = 0x0000;
vert[1][1].x = cx; vert[1][1].y = cy; vert[1][1].Red = 0x0000; vert[1][1].Green = 0x0000; vert[1][1].Blue = 0x0000; vert[1][1].Alpha = 0x0000;
vert[2][0].x = 0; vert[2][0].y = 0; vert[2][0].Red = 0x000; vert[2][0].Green = 0x0000; vert[2][0].Blue = 0x0000; vert[2][0].Alpha = 0x0000;
vert[2][1].x = cx; vert[2][1].y = cy; vert[2][1].Red = 0xdd00; vert[2][1].Green = 0xee00; vert[2][1].Blue = 0xff00; vert[2][1].Alpha = 0x0000;
Rect.UpperLeft = 0; Rect.LowerRight = 1;
GradientFill(hdc, vert[0], 2, &Rect, 1, GRADIENT_FILL_RECT_V); GradientFill(hdc, vert[1], 2, &Rect, 1, GRADIENT_FILL_RECT_V);
RECT r = {0, cy-20, cx, cy};
SelectObject(hdc, BigFont); SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, RGB(150, 175, 200)); DrawText(hdc, "My Sample", -1, &r, DT_RIGHT|DT_BOTTOM|DT_SINGLELINE); }
LRESULT CALLBACK MdiClientProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps;
switch (uMsg) { case WM_SIZE: if (wParam == SIZE_MINIMIZED) break; hdc = GetDC(hWnd); if (g_hbmMem) DeleteObject(g_hbmMem); g_hbmMem = CreateCompatibleBitmap(hdc, LOWORD(lParam), HIWORD(lParam)); ReleaseDC(hWnd, hdc); SelectObject(g_hdcMem, g_hbmMem); DoGradient(g_hdcMem, LOWORD(lParam), HIWORD(lParam)); DeleteObject(g_hbmMem); g_hbmMem = 0; InvalidateRect(hWnd, NULL, 0); break;
case WM_PAINT: { hdc = BeginPaint(hWnd, &ps); BitBlt(hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, g_hdcMem, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); EndPaint(hWnd, &ps); } return 0L;
default: return CallWindowProc(OldProc, hWnd, uMsg, wParam, lParam); } return CallWindowProc(OldProc, hWnd, uMsg, wParam, lParam); }
|
|
|
|
Joined: Mar 2003
Posts: 187
Vogon poet
|
OP
Vogon poet
Joined: Mar 2003
Posts: 187 |
everything I try still isnt working.
|
|
|
|
|