Tech Support > Microsoft Windows > Development Resources > Subclassing problem
Subclassing problem
Posted by IckyPoo on July 27th, 2003


Hi there, I've got:


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
lParam){

switch(uMsg){
case WM_NCACTIVATE:
if((BOOL)wParam==FALSE){
DefWindowProc(hwnd, uMsg, wParam, lParam);
CreateText(hwnd);

return TRUE;
}
case WM_NCPAINT:
DefWindowProc(hwnd, uMsg, wParam, lParam);
CreateText(hwnd);
break;
}

DefWindowProc(hwnd, uMsg, wParam, lParam);
}

void CreateText(HWND hwnd){
HDC hDC = GetWindowDC(hwnd);

int x,y;
RECT rc1,rc2;
GetWindowRect(hwnd, (LPRECT)&rc2 );

x = GetSystemMetrics(SM_CXSIZE) + GetSystemMetrics(SM_CXBORDER) +
GetSystemMetrics(SM_CXFRAME);
y = GetSystemMetrics(SM_CYFRAME);
rc1.left = x;
rc1.top = y;

rc1.right = rc2.right - rc2.left - 2*x - GetSystemMetrics(SM_CXFRAME);
rc1.bottom = GetSystemMetrics(SM_CYSIZE);

SetBkColor( hDC, GetSysColor(COLOR_ACTIVECAPTION) );
DrawText(hDC,(LPSTR)"Left Justified Caption",-1,(LPRECT)&rc1,DT_LEFT);
ReleaseDC(hwnd,hDC);
}


The thing is painting the text but it is not painting the rest of the
window, which really messes up the program...any ideas please? Thanks in
advance...

Ickis


Posted by Tim Robinson on July 27th, 2003


1. You're returning junk from WindowProc. Change the last line to read
"return DefWindowProc...".
2. In the WM_NCPAINT case, you're calling DefWindowProc twice. Change the
"break" to "return".
3. Since this is a subclassed window, you shouldn't be calling DefWindowProc
at all. Everywhere you call DefWindowProc, call the old window proc using
CallWindowProc instead.

--
Tim Robinson (MVP, Windows SDK)
http://www.themobius.co.uk/

"IckyPoo" <icky@poo.com> wrote in message
news:JbXUa.16064$T77.1847019@newsfep2-win.server.ntli.net...



Similar Posts