Solved

urgent form handle question

Posted on 2004-09-06
5
227 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 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