?
Solved

urgent form handle question

Posted on 2004-09-06
5
Medium Priority
?
246 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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!
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

771 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