LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

destroywindow API

The attached VI tries to use destroyWindow API.  It does something but not everything.  Need helps!
 
1.  Run the VI
2.  Click File->New VI, a window called "Untitled1..."
     is opened.  Once the vi detects the window in
     focus, it destroys the window, so you can not
     open a new vi when this vi is running.
3.  If you run Notepad, a window named "Untitled..."
     is also detected by the vi, and DestroyWindow API
     is also executed, but the window does not get
     destroyed.  I guess the reason is just that Notepad
     is another application, i.e. another process.
Now the question:
How should we do or what API should we use if we
want to destroy any window in focus and named
"Untitled...."?
0 Kudos
Message 1 of 11
(4,345 Views)
As the MSDN documentation on DestroyWindow states:
A thread cannot use DestroyWindow to destroy a window created by a different thread.
That's why you can't use it to destroy a Notepad window.

Just out of curiosity, why do you want to do this? I ask because usually when questions like this come up after finding out the "why" there's usually an alternative way of accomplishing the goal.
0 Kudos
Message 2 of 11
(4,312 Views)

You are correct!  destroywindow can only work within the same application.  But the thing is I like the similar thing to work on a child window of a different application.

There are some places I would use the techniques.  I initiate an application (.exe) from my labview program using execute without waiting to end.  This application run on its own thread irrelevant to labview and it is a third party program thus I can't modify it.  At a point of time, the application popup a model window stating its progress and it should ideally close after certain seconds and keep the application running, but it does not and keeps on waiting for user to click on a button or close it.  Once the window is closed, the application save a bundle of data into a file from which my labview software can start reading the data and process it and so forth.  So without the destroywindow facility, the whole application halts till someone clicks.  Because there are a few in the process and their timing are so uncertain and lengthy that an automation is demanded.

Instead of doing destroywindow or the like, I guess we can do sendinput().  Unfortunately, I am scared of dealing with data structures, UNION and this sort of things in LabView, so I like to avoid from it and take the easy route, which, as you can see, was not very successful.  Anyway, sendinput() may not work if the application blocks messages, which we don't know yet.

Anyhow, I believe there must be a way to deal with it. So......

 

0 Kudos
Message 3 of 11
(4,293 Views)

Maybe you can build it into an exe & test it, if it serves its purpose...

Even if it fails, then some experts ve to shed light on it, I suppose...

- Partha ( CLD until Oct 2027 🙂 )
Message 4 of 11
(4,284 Views)
How do you shut down this window manually? Is there a way to shut it down using the only the keyboard?
You may be able to output key presses to the window to make it shut down, like 'esc' for example.
I've done that once before to automatically install third party drivers during install. (Output keypresses to close the window upon completion.)
Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
0 Kudos
Message 5 of 11
(4,280 Views)
You can also try sending it a WM_Quit message (although I don't think that would work on modal dialogs, since that would be a child window).
 
There should be some VIs for handling windows messaging around (I believe LVWinutil32 does it with a custom DLL, but I believe there are also others around).
 
As for sendinput, building the structures looks relatively simple (you use clusters with the right data type), but getting all the values right and calculating the size would require some work. You could also try using attachthreadinput to use keybd_event (which is much simpler) to send a click to the other thread (assuming the dialog has focus).

___________________
Try to take over the world!
Message 6 of 11
(4,271 Views)
As Troy mentioned, if there's a way to hit a key on the keyboard to dismiss the dialog this would be an easy way to acknowledge the dialog. Attached is your example modified to use a DLL that sends just about any keys you want to an active window. I got the DLL from another thread on this board. If you try it with Notepad you'll see the Enter key repeatedly pressed in the window and the caret moving down the document.
0 Kudos
Message 7 of 11
(4,257 Views)

You can also make a call to a standard windows dll to output key presses like in this vi.

 

Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
0 Kudos
Message 8 of 11
(4,233 Views)

Thanks guys,  the DLL works well in one of the child windows which takes Enter to close, but not for the rest, since they only take mouse click on X.  And one of them requires mouse click on one of the button which does not associate with any hot key.  Well we are progressing.

Message Edited by jcai on 07-01-2007 08:07 PM

0 Kudos
Message 9 of 11
(4,198 Views)
Search this forum and you'll find a number of examples on simulating mouse clicks. Most of them use the old API function "mouse_input". MSDN has deprecated this function in favor of the more generic SendInput, but I don't recall recent examples using that function. The old one still works. You can also search for examples that use AutoIt, which is a program that allows you to automate tasks. I know I posted an example that shows how to use that program to automate the task of doing something outside of LabVIEW.
0 Kudos
Message 10 of 11
(4,174 Views)