06-22-2011 10:30 PM - edited 06-22-2011 10:33 PM
I made a dialog box message using user32.dll messagebox function and figured out how to make it come to the foreground of all other windows, but the problem I am having now is that I need to make it the active (focus) window. How do I go about doing that (as simple as possible)?
06-22-2011 10:47 PM
I want to make sure I understand your issue. Are you saying if your application is active, the dialog box comes up without focus (i.e. you application GUI still has focus), or are you saying that if your application is not active, the dialog box doesn't appear over top of the active application and take focuus?
You have two items to play with - hWnd and modality. You did not specify a window handle. You may need to grab the open VIs window handle using FindWindow to pass into the MessageBox call. You can also play with the modality settings (currently you have is set to the default, application). Using system will cause the box to pop-up in front of everything. Using task will cause it to jump in front off all processes of your application with a null hWnd.
http://msdn.microsoft.com/en-us/library/ms645505%28v=vs.85%29.aspx
06-22-2011 11:50 PM
The subroutine that I posted is a small part of a larger application (compiled to an exe) that runs in conjunction with in-house test software. While the test software is running in the foreground, an alert needs to be conveyed to the operator, and that is when the messagebox gets invoked and I have it successfully move to the front, but the window does not become the active window.
06-23-2011 12:10 AM
In the link I provided, there is a setting for uType:
MB_SETFOREGROUND (0x00010000)
It states it will set the dialog to the foreground and activate the window by calling the SetForegroundWindow function.
Assuming your constant is in hex, it does not appear you are using this setting.
You can also try using the System modality by using MB_SYSTEMMODAL (0x00001000), as I mentioned in my first reply.
06-23-2011 12:43 AM - edited 06-23-2011 12:48 AM
I had tried MB_SETFOREGROUND (0x00010000) and MB_SYSTEMMODAL (0x00001000).
They both bring the message window to the foreground but it is not the active window until you manually select it.
06-23-2011 12:55 AM
What is the active window?
Can you create an example so someone can see the behavior?
If you use the built-in LV dialog box, do you see the same behavior?
Have you tried passing a valid window handle instead of null?
06-23-2011 01:06 AM
One other thing. I made an assumption your constant is hex, but you are not displaying the radix for the constant.
The 20040 constant in your image has had its radix changed to hexadecimal, correct?
06-23-2011 02:18 AM - edited 06-23-2011 02:21 AM
06-23-2011 02:18 AM - edited 06-23-2011 02:20 AM
The active window is an in-house developed software front end we use for product testing.
I am not sure what example you would like me to create. Did you want the actual vi?
The built in dialog box did not offer much parameter settings to accomplish what I needed it to do as I am using LV 6 (due to compatibility with external interfaces).
I have not tried to pass a valid window handle as I was unable to ascertain such information.
I had googled how to acquire hWnd handle ID information but the examples provided pointed to the process ID which did not succeed in making the dialog box the active window.
06-23-2011 07:44 AM
As I mentioned in my first reply, FindWindow (http://msdn.microsoft.com/en-us/library/ms633499%28v=vs.85%29.aspx) will give you a window handle. All you need to know is the title of the open window.
You can use this to make the dialog modal to your in-house software. It is possible that this software is causing you some problems as well. Does it behave like a normal window, or does it have a special setup, such as Always on Top, etc.?
If you run your VI without the other software, does the dialog work? An example would be something that demonstrates the same problem, so someone can reproduce on their machine and can try get a solution for you without throwing ideas into the air to see if they work.
I am not saying to use the LV dialog permanently, just as a test to see if it behaves as you desire, as it may give some insight into what is going on.
Did you confirm that your 20040 constant has a radix set to hex and therefore is 0x20040 and not decimal 20,040?