Author Topic: [C#] OnPaint (Other hwnd)  (Read 5811 times)

0 Members and 1 Guest are viewing this topic.

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
[C#] OnPaint (Other hwnd)
« 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.

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C#] OnPaint (Other hwnd)
« Reply #1 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, but once again, it may not work in another application.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [C#] OnPaint (Other hwnd)
« Reply #2 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.

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: [C#] OnPaint (Other hwnd)
« Reply #3 on: January 04, 2009, 11:19:07 pm »
Thank you both.  :)

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C#] OnPaint (Other hwnd)
« Reply #4 on: January 06, 2009, 02:20:10 am »
Thank you both.  :)
What are the results?
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [C#] OnPaint (Other hwnd)
« Reply #5 on: January 06, 2009, 08:27:46 am »
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)

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C#] OnPaint (Other hwnd)
« Reply #6 on: January 06, 2009, 11:34:11 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.

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.... :p
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [C#] OnPaint (Other hwnd)
« Reply #7 on: January 06, 2009, 11:43:32 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.

Yeah, ok.... :p
Note how I didn't finish it, I only went so far. ;)

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: [C#] OnPaint (Other hwnd)
« Reply #8 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.

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: [C#] OnPaint (Other hwnd)
« Reply #9 on: January 06, 2009, 05:36:59 pm »
Not sure, but maybe UpdateWindow 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?
« Last Edit: January 06, 2009, 05:44:33 pm by Warrior »
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling