Clan x86

Technical (Development, Security, etc.) => General Programming => Topic started by: abc on January 01, 2009, 01:39:45 PM

Title: [C#] OnPaint (Other hwnd)
Post by: abc on January 01, 2009, 01:39:45 PM
I was curious to know how/if it's possible to go about forcing the OnPaint() event or the Update() function to be called through another application; I have the hwnd, and hdc of my control.
Title: Re: [C#] OnPaint (Other hwnd)
Post by: MyndFyre on January 04, 2009, 04:35:42 AM
It's probably not possible to do this if the handle is in another application, but you could try Control.FromHandle(IntPtr).

You can also call into InvalidateRect (http://msdn.microsoft.com/en-us/library/ms534893(VS.85).aspx), but once again, it may not work in another application.
Title: Re: [C#] OnPaint (Other hwnd)
Post by: iago on January 04, 2009, 11:09:00 AM
The normal way of getting those types of events from another application is by using system hooks (look up SetWindowsHookEx, iirc). Those functions implicitly use DLL injection to accomplish it.

At least, that's how it was done in C/C++. .NET may not be the same.
Title: Re: [C#] OnPaint (Other hwnd)
Post by: abc on January 04, 2009, 11:19:07 PM
Thank you both.  :)
Title: Re: [C#] OnPaint (Other hwnd)
Post by: MyndFyre on January 06, 2009, 02:20:10 AM
Quote from: Dale on January 04, 2009, 11:19:07 PM
Thank you both.  :)
What are the results?
Title: Re: [C#] OnPaint (Other hwnd)
Post by: iago on January 06, 2009, 08:27:46 AM
Quote from: MyndFyre on January 06, 2009, 02:20:10 AM
Quote from: Dale on January 04, 2009, 11:19:07 PM
Thank you both.  :)
What are the results?
He gave up because it's too complicated.

(At least, that's what I would have done :D)
Title: Re: [C#] OnPaint (Other hwnd)
Post by: MyndFyre on January 06, 2009, 11:34:11 AM
Quote from: iago on January 04, 2009, 11:09:00 AM
The normal way of getting those types of events from another application is by using system hooks (look up SetWindowsHookEx, iirc). Those functions implicitly use DLL injection to accomplish it.

At least, that's how it was done in C/C++. .NET may not be the same.

I don't think he was trying to hook the events, merely that he was trying to get them to occur by sending the WM_PAINT message to the window.

Quote from: iago on January 06, 2009, 08:27:46 AM
Quote from: MyndFyre on January 06, 2009, 02:20:10 AM
Quote from: Dale on January 04, 2009, 11:19:07 PM
Thank you both.  :)
What are the results?
He gave up because it's too complicated.

(At least, that's what I would have done :D)
Yeah, ok.... (http://www.skullsecurity.org/wiki/index.php/Starcraft_Warden) :p
Title: Re: [C#] OnPaint (Other hwnd)
Post by: iago on January 06, 2009, 11:43:32 AM
Quote from: MyndFyre on January 06, 2009, 11:34:11 AM
I don't think he was trying to hook the events, merely that he was trying to get them to occur by sending the WM_PAINT message to the window.
Ah, good call, I misread the original post.

Quote from: iago on January 06, 2009, 08:27:46 AM
Yeah, ok.... (http://www.skullsecurity.org/wiki/index.php/Starcraft_Warden) :p
Note how I didn't finish it, I only went so far. ;)
Title: Re: [C#] OnPaint (Other hwnd)
Post by: abc on January 06, 2009, 05:20:37 PM
Well, I tried what you suggested earlier Mynd.. However no luck in it working. So I just left it the way it is now, pretty ugly but I'll get it working sometime.
Title: Re: [C#] OnPaint (Other hwnd)
Post by: Warrior on January 06, 2009, 05:36:59 PM
Not sure, but maybe UpdateWindow (http://msdn.microsoft.com/en-us/library/ms534874(VS.85).aspx) will work.

Dunno, maybe you can try it in conjunction with InvalidateRect which adds the region to the update queue. I'm not certain if UpdateWindow will send a WM_PAINT regardless.

Edit: Now I'm not so sure, it seems that UpdateWindow immediately sends WM_PAINT to the message pump which redraws dirty regions, while InvalidateRect queues a WM_PAINT to the message queue..hmm

In theory UpdateWindow should immediately cause the rect you invalidate to draw, but InvalidateRect should work on it's own (albeit it does not do so immediately).

Post code?