Hello!

I'm writing an MDI application, but I can't put a picture as background. The MDIClient class is painting automatically it's own background, and I can't get rid of it.
My question is that how can I change this behaviour?
I tried to capture the WM_ERASEBKGND message, and to draw a picture, but the picture does not apper, because the MDIClient is painting its own background above it.

Any ideas?

Regards,
bszente
Posted on 2005-02-06 13:37:24 by bszente
I think I found a solution to overcome this problem. Maybe it will help someone. I'm sorry but the code is in C.
I simply changed the WindowProc of the MDIClient Window.
In the main WindowProc I put the following to create the MDI Client window:


case WM_CREATE:
hMainMenu = GetMenu(hWnd);
ClientStruct.hWindowMenu = GetSubMenu(hMainMenu, 1);
ClientStruct.idFirstChild = 100;
hwndClient = CreateWindowEx(
0,
MDIClientName, /* "MDICLIENT" */
NULL,
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hWnd,
NULL,
hInstance,
&ClientStruct);
/* Changing the default MDI Client Window Procedure */
DefMDIClientProc = (WNDPROC) GetWindowLong(hwndClient, GWL_WNDPROC);
SetWindowLong(hwndClient, GWL_WNDPROC, (UINT) MDIClientProc);

/* Initialize MDICREATESTRUCT */
mdicreate.szClass = MDIChildClassName;
mdicreate.szTitle = MDIChildTitle;
mdicreate.hOwner = hInstance;
mdicreate.x = CW_USEDEFAULT;
mdicreate.y = CW_USEDEFAULT;
mdicreate.cx = CW_USEDEFAULT;
mdicreate.cy = CW_USEDEFAULT;
break;

And as for the custom MDIClient WindowProc I wrote this:


LRESULT CALLBACK MDIClientProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC memDC;
HGDIOBJ hOld;
RECT Rect;

switch (uMsg)
{
/* Capture this message */
case WM_ERASEBKGND:
memDC = CreateCompatibleDC((HDC) wParam);
hOld = SelectObject(memDC, hBitmap);
GetClientRect(hWnd, &Rect);
StretchBlt((HDC) wParam, 0, 0, Rect.right, Rect.bottom, memDC, 0, 0, 379, 404, SRCCOPY);
SelectObject((HDC) wParam, hOld);
DeleteDC(memDC);
return 1;
case WM_PAINT:
/* Do whatever you want */
break;
default:
/* Call the original MDIClient WindowProc */
return CallWindowProc(DefMDIClientProc, hWnd, uMsg, wParam, lParam);
}
return 0;
}

This way I succeed to capture the critical background painting messages, and to draw a picture as a background.
Maybe this isn't the most elegant way, but at this point I don't know any other solution.
I welcome your opinions, solutions.

Regard,
bszente
Posted on 2005-02-06 16:40:56 by bszente