Results 1 to 14 of 14

Thread: Intercept WM_PAINT in remote process...?

  1. #1

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Intercept WM_PAINT in remote process...?

    Is it possible to intercept the WM_PAINT message passed to an external process' window(s)?? I can't seem to catch it - I can get most other messages (using a SetWindowsHookEx call) but the WM_PAINT message eludes me....??
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Intercept WM_PAINT in remote process...?

    Have you looked at moeur's codebank entry - "Subclassing external program done for you", or such. It has a C++ dll that you can use to subclass an external program and catch the message you need.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Re: Intercept WM_PAINT in remote process...?

    Had a look, but couldn't see where this particular message was being called. Really need to do this myself rather than use another control (architecture/IP issues...)
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Intercept WM_PAINT in remote process...?

    But he does include the source code for the demo project and the C++ dll source code. I figured that the C++ code would be the most relevant part for you.

    http://www.vbforums.com/showthread.php?t=322261
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Re: Intercept WM_PAINT in remote process...?

    Ta, browsing it now. :-p
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  6. #6

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Re: Intercept WM_PAINT in remote process...?

    Hmmm.... still can't work out why that particular message can't be captured. Nothing I can see in his code that is different from what I'm doing....
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  7. #7
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Intercept WM_PAINT in remote process...?

    Perhaps you could show us what you are doing...

  8. #8

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Re: Intercept WM_PAINT in remote process...?

    The problem I'm trying to solve is manipulating the display in another applications dialog boxes (for example). i.e; I want to draw directly to another window (and eventually, take over control of a particular control - a listview in a popup box). I can do this.

    What I can't do is keep what I've drawn into that Window to stay there. I figure to capture WM_PAINT events, which will let me keep my own drawn UI in place. I haven't yet gone into maintaining control of that listview, but I imagine this will be OK (based on what I already understand). It's just the drawing I can't do.

    I've written the following method into a C++ .dll;

    Code:
    hHook = SetWindowsHookEx(
    		WH_CALLWNDPROC, 
    		(HOOKPROC) CallWndProc, 
    		NULL, 
    		GetCurrentThreadId()));
    This is part of a method called by a VB app to kick off the hooking. My CallWndProc implementation is as follows;

    Code:
    LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) 
    {
    	if (nCode < 0) // do not process message 
            return CallNextHookEx(hHook, nCode, wParam, lParam); 
    
    	// cast our message info for use in here
    	CWPSTRUCT* msgDetail = (CWPSTRUCT*) lParam;
    
    	if (msgDetail->message == WM_PAINT) {
    		TCHAR szBuf[80]; 
    		wsprintf(szBuf, "Got WM_PAINT from hWnd[%x]\n", msgDetail->hwnd);
    		OutputDebugString(szBuf);
    	}
    
    	TCHAR szBuf[80]; 
    	wsprintf(szBuf, "Comparing %x = %x\n", WM_PAINT, msgDetail->message);
    	OutputDebugString(szBuf);
    
    
    	wsprintf(szBuf, "CallWndProc called, checking hWnd...[%x==%x]\n", hWndDlg,  msgDetail->hwnd);
    	OutputDebugString(szBuf);
    
    	// check the hWnd from the receiving window...
    
    	if (msgDetail->hwnd != hWndDlg) // do not process message 
            return CallNextHookEx(hHook, nCode, wParam, lParam); 
    
    	wsprintf(szBuf, "CallWndProc called, checking message...\n", hWndDlg);
    	OutputDebugString(szBuf);
    
    	// check the message type now
    	if (msgDetail->message != WM_PAINT) // do not process message 
            return CallNextHookEx(hHook, nCode, wParam, lParam); 
    
    
    	wsprintf(szBuf, "CallWndProc called, checking wParam...\n", hWndDlg);
    	OutputDebugString(szBuf);
    
    	// check that the window is being activated
    	if (msgDetail->wParam == TRUE) // do not process message 
            return CallNextHookEx(hHook, nCode, wParam, lParam); 
    
    	wsprintf(szBuf, "CallWndProc called, running!\n", hWndDlg);
    	OutputDebugString(szBuf);
    	
    	// All good
    	DrawMyWindow(hWndDlgFileView);
    
    
    	return 0; //CallNextHookEx(hHook, nCode, wParam, lParam); 
    }

    Two problems I have; firstly, the hWnd of the app I actually want to look for never shows up, and secondly, WM_PAINT messages never show up. (Plenty of other messages do though...)
    Last edited by rjlohan; Nov 16th, 2005 at 02:25 AM.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  9. #9
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Intercept WM_PAINT in remote process...?

    I'm a bit confused by your hook setting procedure.
    If you call this from VB, then you are hooking your own thread and not an external process' thread.

    What OS are you running on?

  10. #10

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Re: Intercept WM_PAINT in remote process...?

    Ok, I'm probably a bit confused about it too then! :-D How do I hook messages (specifically WM_PAINT) in another process? (WinXP)
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  11. #11
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Intercept WM_PAINT in remote process...?

    See the thread that RobDog pointed out to you. It has an in depth explanation as well as example code.

  12. #12
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Intercept WM_PAINT in remote process...?

    WM_PAINT is a somewhat unusual message (also WM_TIMER is but that is a story for another day) as it only gets posted to a window by the system when there are no other messages in the queue...this may cause problems later on.

    Also the hook that you are setting is a local hook. To hook another application (process) you must pass its module handle in the hMod parameter (the third one).

  13. #13

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Re: Intercept WM_PAINT in remote process...?

    Thanks for that, I got it to work now. I am now able to draw what I want into the ListView control on an Open dialog.
    My next issue is that parts of the parent dialog (e.g; some of the buttons), and the application window are not refreshed until I move the dialog. So, switchin application context leaves small parts of the display un-drawn... any ideas?
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  14. #14
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Intercept WM_PAINT in remote process...?

    why would it do that?

    Care to post the code you are using?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width