Re: Get Control From Handle

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



If you want to get your own main form, you are probably right, the best way would be to have a static reference to your form somewhere in your app.

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

"jonfroehlich" <jonfroehlich@xxxxxxxxx> wrote in message news:1170223710.203468.24400@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have not yet determined a clean way to invoke code on the UI thread
without access to a Form/Control. The Process class has a property
called "MainWindowHandle," which returns the window handle of the main
window of the associated process. So, for example,
Process.GetCurrentProcess().MainWindowHandle would return a Handle
(HWND) to the main window. But how can we translate a window handle to
a Form?

In .NET 2.0, this is relatively easy, we can simply call
Control.FromHandle(IntPtr handle). Thus, receiving access to the main
window is simply:
(Form)Control.FromHandle(Process.GetCurrentProcess().MainWindowHandle)

Unfortunately, however, .NET CF 2.0 does not expose the
Control.FromHandle method. I have not found anyone on the web who has
solved this problem. Given the limitations of CF, one hacky way to do
this would be to expose a static property on the MainForm class which
would return a reference to itself.

I was wondering if anyone else has come up with a separate solution.
Basically, I need to marshal calls into my UI thread, but I don't want
to pass around a reference to a From/Control.

A few relevant links:

1. https://forums.microsoft.com/MSDN/ShowPost.aspx?
PostID=855352&SiteID=1
2. http://groups.google.com/group/microsoft.public.dotnet.general/
browse_frm/thread/c65f0b7d652c3c3d/a9c80f50dd05af20?
lnk=st&q=MainWindowHandle+Form&rnum=4#a9c80f50dd05af20
3.
http://groups.google.com/group/microsoft.public.dotnet.framework.compactframework/browse_frm/thread/d6509bd2852d8b20/3ee2c216071da85b?lnk=gst&q=FromHandle&rnum=1#3ee2c216071da85b


.



Relevant Pages

  • Re: Get Control From Handle
    ... way would be to have a static reference to your form somewhere in your app. ... window of the associated process. ... Unfortunately, however, .NET CF 2.0 does not expose the ... this would be to expose a static property on the MainForm class which ...
    (microsoft.public.dotnet.framework.compactframework)
  • Get Control From Handle
    ... The Process class has a property ... window of the associated process. ... Unfortunately, however, .NET CF 2.0 does not expose the ... to pass around a reference to a From/Control. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Newbie Qs: references, scopes, overwrites
    ... from the window after appending the file". ... I am not familiar with SVG, but will try and give you some pointers regarding your questions below. ... Received commands can range from "display a view which you will build using this HTML", to "here's an image, use it as a reference when building the current view", or "here comes a .stuff file, do something about it". ... What's important here is that the browser maintains a view with which the user can interact. ...
    (comp.lang.javascript)
  • Re: Calls between windows
    ... These object reference variables are exactly like character memory ... be based on the Collection base class. ... Your top-most level form class would ... The scenario is that if specific window is opened and a process ...
    (microsoft.public.fox.programmer.exchange)
  • Re: dont understand namespaces...
    ... I think I do not yet have a good understanding of namespaces. ... instantiate a class that defines a Frame in the root window ... And the caller gets a return value from the constructor, which is a downward reference. ...
    (comp.lang.python)