Solved

urgent form handle question

Posted on 2004-09-06
5
207 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
  • 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 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now