Force messagebox to foreground - vbscript

I've got a VBScript that calls a Visual FoxPro Instance and runs a VFP program. Part of this program produces a messagebox. However, if my script is run from the Windows GUI (rather than a Command Prompt), then the message box produced doesn't necessarily come to the foreground.
In VBScript I have the following code:
Set oVFP = CreateObject("VisualFoxPro.Application")
oVFP.DoCmd("Messagebox('Hello World')")
Set oVFP = Nothing
When I run this script from a DOS prompt, the message box pops to the foreground. When I double-click on the script in Explorer, the Explorer window may be covering the produced messagebox. There is no indication (no extra buttons on Start bar, for example) that the messagebox is hiding back behind the Explorer window waiting for user action.
Is there a way to force the produced messagebox to the foreground?

Add the undocumented 'System Modal' flag to the MessageBox options:
Set oVFP = CreateObject("VisualFoxPro.Application")
oVFP.DoCmd("Messagebox('Hello World', 4096)")
Set oVFP = Nothing

Related

I want to prevent a window from opening when an application launches

I have a program the opens a window, reads a config file, then closes the window a fraction of a second later, then continues running in background. I want to be able to start this program one way or another without the window appearing in the first place.
Is there a way for me to launch the program (preferably on PC startup) but suppress any windows it creates?
I do not have the source code for the program in question. In that regard I am an end-user.
use a vbs script to open it:
set obj = createobject("wscript.shell")
obj.run "prog.exe",0,false
call that prog.vbs or whatever, and put it in:
"%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup"

how to hide cmd from appearing at the back of your .vbs application?

I am new to building apps using simple .vbs coding, whenever I build a .exe file using visual basic script command prompt opens along with the application at the background. so how to hide the command prompt from appearing??
and also how to set a background image in a pop up or input box?
To your first question, it depends on how you are calling the vbs. Windows allow to execute tasks with hidden windows. If you can not create a hidden window and you doesn't need the console, instead of using cscript as the executable for the vbs, use wscript.
Popup and input box from vbscript are standard elements of the system. AFAIK no way of change background of them.

disable message box for programs that was run from cmd

I have util which at the end of it's work shows message box with notification and OK button. I run it under command line and would like to disable all message boxes that can break my process and require user reaction. Does any way to accoplish this task?
I would recommend just adding a --quiet command line switch instead, so users have better control over this kind of thing.
If you want to try to do it automatically, you can check the parent PID right when your app launches, and see if it's cmd.exe. Of course this is not 100% accurate because there are more scenarios where users don't want user interaction.
Well... you could use VBScript to automatically click or press ENTER on the messagebox. But you'll need to know the window name or number of the messagebox.
This code will bring focus to a Window called MESSAGEBOXNAME, and the press ENTER.
Set oShell = CreateObject("WScript.Shell")
oShell.AppActivate("MESSAGEBOXNAME")
WScript.Sleep 500
oShell.SendKeys "~"
Where MESSAGEBOXNAME is the Window Name of the MessageBox, that should be in the upper right corner of the messagebox.

how to launch Print dialog from application as like from word pad in wince

I am trying to launch default print dialog from application , but it is not coming up. I am able to launc print dialog from wordpad application it is also printing the decument but, when i am trying to do the same nothing is happn. here is code for show print dialog:-
PAGESETUPDLG printDialog;
ZeroMemory(&printDialog, sizeof(printDialog));
printDialog.lStructSize = sizeof(printDialog);
printDialog.hwndOwner = NULL; //or = NULL
PageSetupDlg(&printDialog);
pls tell me how to achive this...
regards,
Mukesh
The code you posted runs fine in a test app I knocked up, so technically there's nothing wrong with the code.
If you specify the hwndOwner as NULL, as in your example code, the print dialog opens as a modeless dialog, which could be opening behind your application's GUI - your code may therefore be correctly opening the dialog, you're just not seeing it. As a modeless dialog doesn't stop you interacting with the window that spawned it, you would be able to fully interact with your main GUI, not realising the print dialog is sitting behind it.
Can you not specify the hwndOwner? It should really be the handle of the window that's opening the print dialog, so that, as I mention above, it stops the user interacting with the main window whilst the printer settings are configured.

How to bring a CMD.EXE window to top

How to bring CMD.EXE window to top? (I would prefer a command or script without a need to compile anything).
The Wscript.Shell object accessible from Windows Script Host (either VBS or JS) has a method called "AppActivate" which, when passed a window title, will attempt to "activate" (which may bring it to the foreground if it's not minimised).
The following code snippet in VBScript worked on my machine:
Set WShell = CreateObject("WScript.Shell")
WShell.AppActivate "Command Prompt"
(Edited: Initially I hadn't tried it. Then I did)
With compiling:
Easy, just use Win32 API to FindWindow according to its title or class and then send it a message or bring it to the front.
Without compiling:
I'd suggest you'd find a command line utility that can do the equivalent of FindWindow and SetForgroundWindow, so you could call it from a batch file or any other script.
You can make an AutoHotkey Script:
^SPACE:: Winset, Alwaysontop, , Ahere
Return
Save it as a .ahk file. Run it after you've installed Autohotkey. Now click the window of your choice and hit CTRL+Space and the window should be always on top

Resources