LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MessageBox/MsgBox for LabVIEW

I tried to post this code in the code library and couldn't find it after it supposedly submitted. Perhaps it did, perhaps it didn't, but if I can't find it probably no one else will either. I thought I would write up this post for others who are searching for something similiar--a VI that calls the built in windows message dialog box.

The attached VI calls the MessageBoxA function of User32.dll. I believe it is referenced as MessageBox and MsgBox in Visual C++ and Visual Basic. Whatever it is called, it is not the dialog that comes with LabVIEW and definitely has more functionality. I know that someone else MUST have coded the same exact thing but I could not find it. The VI also determines the refnum of the calling window as
long as it is in the same directory, and passes it on to the MessageBoxA function so that modal functionality will work correctly (I believe this is what it's for).
Message 1 of 11
(6,876 Views)
That is super cool. Now, how do I specify a User Icon?

Daniel L. Press
PrimeTest Corp.
www.primetest.com
0 Kudos
Message 2 of 11
(6,876 Views)
Good question. I found no reference to a user icon in the Microsoft help files but WinUser.H had the constant listed so I threw it in there. I would be interested in finding out myself.
0 Kudos
Message 3 of 11
(6,876 Views)
Here's a link to a VB example where they talk about using a Windows hook to intercept messages "and thereby manipulate the dialog". They then seem to be loading an icon image from a file and setting the icon with SendMessage. If they say so...
http://www.pacificdb.com.au/MVP/Code/XMsgBox.htm
You VI is pretty cool. Thanks for posting it. I don't think you need any of the sequence structures. It doesn't look to me like they're controlling anything. I deleted all of them and the VI still worked.
0 Kudos
Message 4 of 11
(6,876 Views)
Alright from that link these lines below would be the way to set the icon... use the LoadImage/SendMessage functions. Not sure that I have enough expertise to implement that yet but that's how you'd do it 🙂

The sequence structures are unnecessary as stated but that's my personal programming style. They make moving and arranging chunks of code a lot easier as well as cut & paste ops into other vi's.


============================================
hIcon = LoadImage(0&, sIcon, IMAGE_ICON, IMG_DEFAULT_WIDTH, _IMG_DEFAULT_HEIGHT, LR_LOADFROMFILE)
If hIcon <> 0 Then
lRetVal = SendMessage(hWnd, WM_SETICON, ICON_SMALL, ByVal hIcon)
End If
============================================
0 Kudos
Message 5 of 11
(6,875 Views)
Here is what you are looking for. Unfortunately is it commented in french but I think it should not be too difficult to translate.

You will find information about the MessageBoxA in the LV Advanced Course Manual version 6.0 (pages 7-6 to 7-12). I took the course some years ago and the manual may have changed at this time.
Message 6 of 11
(6,875 Views)
The message box is excellent! I really needed it.
Thanks,
Prasun Mital
0 Kudos
Message 7 of 11
(6,876 Views)

Old thread...but relevant to the MessageBox.vi in question so let me try here:

I often use the MessageBox.vi to get a more native dialog box with icons etc, and the modality is most often set to the default which is "Application". However, the behavior of this seems to have changed on Windows 10, it will no longer stay modal/ on top of the calling VI as it should. Has anyone else noticed and found a fix to this (or a workaround, like a replacement function with the same funtionality (icon etc.)? Using System Modality is not a solution as I do not want to have it disturb anything but the application itself.

0 Kudos
Message 8 of 11
(4,638 Views)

I figured out a solution to the modality issue on Windows 10.

 

The problem with the original MessageBox.vi on Windows 10 is that it will only set the modality right if the window handle to the caller is correct, and the way that handle is retrieved does not actually work in built applications.

 

The way to eliminate the problem is to get the caller's reference like this:

 

Windowhandlecorrectlyretrieved.PNG

 

 

 

 

Message 9 of 11
(4,612 Views)

Yes the old way of getting the HWND was flawed, and your method is better but this also relies on windows not sharing the same title and a few other small issues.  Luckily NI has a couple of methods (one deprecated one private) that will return an HWND given a VI reference.  Attached is a better way to get the HWND of a VI reference which I've used in applications with success.  Here is a discussion on these methods on LAVA.

 

https://lavag.org/topic/13803-getting-the-window-handle-for-a-fp-with-no-title-bar/

 

Something I can't seem to find at the moment is I remember someone using more features of the system dialog box for things like changing the button text, and a few other features...but I can't find it at the moment.

Message 10 of 11
(4,597 Views)