Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to get handle of frame1 or image1 or rectangle1 or any other component besides mainwindow.If I want to get handle of mainwindow I can use:

C#
IntPtr windowHandle = new WindowInteropHelper(this).Handle;
Posted
Comments
[no name] 11-Jul-12 16:48pm    
Just out of curiousity why would need to get the handle? What is it that you are trying to do?
Sergey Alexandrovich Kryukov 11-Jul-12 17:18pm    
Something bad, I would guess... :-) Anyway, I provided an answer, please see.
--SA

1 solution

No, not in the sense of window handle you obtain from the WindowInteropHelper. They are not Windows windows. The technology is based on DirectX and provides alternative windowing mechanism inside the WPF window. In a way, the technology is a good attempt to go away from Windows as OS, as most of its implementation is not related to Windows API. And in practice, you never need any window handles.

In principle, you can use any valid windows handle to add or find (if any) child windows, work with them, etc. All you need is pure (unmanaged) Windows API, P/Invoked or obtained using mixed-mode projects using C++/CLI. I would advise to resist this temptation by all means. Should I even explain why it's very bad? WPF is self-contained (except the top-level window) and provides you with everything you need.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900