11-29-2010 07:43 AM
Hello all,
I am trying to disable the close button of a third party console application that I am invoking through LabVIEW. I tried using GetSystemMenu() and DeleteSystemMenu() from user32.dll, but somewhere I am doing it wrong.
Can anyone can suggest a solution to this?
Thanks!
FraggerFox
Solved! Go to Solution.
11-29-2010 09:01 AM - edited 11-29-2010 09:03 AM
Do you have the handle to Window? Off hand, I don't know how to delete it, but here is some C# code that I used to grey out the close window button in another project:
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
private static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem,
uint uEnable);
private const Int32 SC_CLOSE = 0xF060;
private const UInt32 MF_BYCOMMAND =0x00000000;
private const UInt32 MF_ENABLED = 0x00000000;
private const UInt32 MF_GRAYED = 0x00000001;
private const UInt32 MF_DISABLED = 0x00000002;
private void EnableClose(bool enable)
{
IntPtr pSysMenu = GetSystemMenu(Handle, false);
if (pSysMenu != null)
{
EnableMenuItem(pSysMenu, SC_CLOSE, MF_BYCOMMAND | (enable ? MF_ENABLED : MF_DISABLED));
}
}
This was fairly easy to convert over once I had the handle (this is from a library I picked up somewhere).
Hope this helps.
A
11-29-2010 09:32 AM
If the window has a name (look at titlebar) you can get the handle by window name using a user32.dll find window (I think this is the function, havent used it is a while)
11-29-2010 10:27 AM
Yeah, that is the API I was using from the Library I passed on.
A
11-29-2010 11:33 PM - edited 11-29-2010 11:37 PM
@A:
The VI you attached works!
But I didn't understand one thing. I used the same logic, but I was providing PID of the command prompt/console application window, and not the reference which is coming out which is coming using the WINLLB function. Now when we say a "Handle" to the window, we mean that we are referring to the PID of that application, right?
Correct me if I am wrong.
Thanks!
FraggerFox
11-30-2010 12:26 AM
^ ^
Ok, I got that PID and handle are two different things.
One more thing, if anyone can explain. If user does CTRL+C even when the close button is disabled on the command prompt, it will close the console application/command prompt. How can we disable this?
Fragger Fox
11-30-2010 10:13 AM - edited 11-30-2010 10:14 AM
The Ctrl-C is to be trapped by the console app. You can't (to my knowledge) trap that signal OUTSIDE of the app and keep it from captureing it UNLESS you spawn it (IIR unix correctly), in which case it is not exaclty outside and the parent could shelter the child from the Ctrl-C. So you would have to make a console app that would capture and withhold the Ctrl-C and then spawn this other console app you are talking about. IIRC, this can be done in shell script, but if you are using windows, you will probably need to roll your own or get cygwin or other unix emulator. This is going way off topic from LV though.
Alternatively, why not just hide the consloe window? Probably much easier unless you need the console for something. Haven't tried, but I think there is a Hide window.vi in that library I gave you.
A
11-30-2010 10:36 AM
It is possible to make the labview window the parent of the console window. I played with this in the past, might cause other problems though.
11-30-2010 10:52 AM - edited 11-30-2010 10:52 AM
No, not parent window, parent process (which it already is if it is the spawer of the process) and capture the Ctlr-C (which I don't think LV will do).
A
11-30-2010 11:13 AM
Do you have access to the code for the console app? You could disable the break via the winapi SetConsoleCtrlHandler() as discribed here:
and here:
http://msdn.microsoft.com/en-us/library/ms686016%28VS.85%29.aspx
A