Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

urgent form handle question

Posted on 2004-09-06
5
Medium Priority
?
251 Views
Last Modified: 2010-08-05
HI experts!

i have a window in an MDI with the handle XXXXX

I want to access this window programmatically and close it by referring to the windows handle

any way to do this??

Thanks!
0
Comment
Question by:OptionsMM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 11992636
Is the window in your application, or in another one (running in Windows somewhere)?
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 2000 total points
ID: 11992668
Use these declarations:

  [System.Runtime.InteropServices.DllImport("user32.dll")]
  static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam);
  const int WM_CLOSE = 0x10;
  const int WM_DESTROY = 0x2;

And then call this code, where handle is the handle to the window you want to close/destroy:

  // IntPtr handle = new IntPtr(XXXXX);

  SendMessage(handle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
or
  SendMessage(handle, WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
0
 

Author Comment

by:OptionsMM
ID: 11992868
Sorry I messed the question up.  

I want to be able to turn the windows visible and invisible.

how can I do that??

Thanks for the fast reply it is very appreciated!
0
 

Author Comment

by:OptionsMM
ID: 11993007
Also,

The "handle" is stored as a string, how can I convert this to the correct type?

Thanks!!
0
 

Author Comment

by:OptionsMM
ID: 11993088
Got it!

Thanks a million!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question