Archived

This topic is now archived and is closed to further replies.

Icky Slap

Problem with painting?

Recommended Posts

Hi all, I'm using a hook (please don't run away yet!) to play with an application. I'm wanting to change the caption of the title bar. I've found the MSDN code and this is what I'm now using:
_declspec(dllexport) LRESULT CALLBACK HProc(int code,WPARAM wParam,LPARAM lParam){
	if(code<0) 
		return(CallNextHookEx(hNP,code,wParam,lParam));
		
	CWPSTRUCT *MessageDetails=(CWPSTRUCT*)lParam;

	if(MessageDetails->hwnd==hMain){

		if(MessageDetails->message==WM_NCPAINT){
			DefWindowProc(hMain,MessageDetails->message,wParam,lParam);
			HDC hDC = GetWindowDC(MessageDetails->hwnd);

			int x,y;
			RECT rc1,rc2;
			GetWindowRect(MessageDetails->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( MessageDetails->hwnd,hDC);
			return FALSE;
		}

		if(MessageDetails->message==WM_NCACTIVATE){
				SendMessage(MessageDetails->hwnd,WM_NCPAINT,1,0);
		}
	}
	
	return(CallNextHookEx(hNP,code,wParam,lParam));
}
   
What's happening is that I only see the custom text when my window is resized. I've read up its and I think its something about the window deactivating as soon as it is activated so only a flash of text is displayed...Can anybody PLEASE (PLEASE PLEASE PLEASE) help? Thanks in advance!!! Icky Slap. [edited by - Icky Slap on July 26, 2003 9:04:01 PM] [edited by - Icky Slap on July 27, 2003 10:40:41 AM]

Share this post


Link to post
Share on other sites
UPDATE

well I''m now subclassing the window and I''m now using:




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);
}



What''s happening now is that it is painting my text, but it doesn''t paint the rest of the window which really messes things up big time ...

Anybody please?

Share this post


Link to post
Share on other sites