Home » Community » Newbie corner » check if application is running
Re: check if application is running [message #55667 is a reply to message #55665] |
Sun, 29 November 2020 04:28   |
BetoValle
Messages: 204 Registered: September 2020 Location: Brasil Valinhos SP
|
Experienced Member |
|
|
Hi,
I'm sorry to disagree and I'm going to demonstrate that it works using SetForegroundWindow.
In the case of the question of this open topic I will state the situation:
I have a compiled application (in U ++) that is only used to load another application in java (jar file), since java does not generate an executable.
So I have App U ++:
pkBack :: pkBack ()
{
/ * int64 n = GetWindowIdFromCaption ("Backup", true); // Backup is the title of the main window
if (n> 0) {
Window_Top (n);
} else {* /
CtrlLayout (* this, "Window title");
Icon (PkBackImg :: icon ());
String dir = AppendFileName (GetCurrentDirectory (), "");
String jre = AppendFileName (GetCurrentDirectory (), "\\ jre \\ bin \\ java.exe");
const String fjar = "BackJPW.jar";
bool c = FileExists (jre);
if (c) {
} else
{
PromptOK ("jre is not present!" + Jre);
}
c = FileExists (fjar);
if (c) {
Upp :: LaunchMy (jre, "- jar" + fjar, dir, 0);
} else
{
PromptOK ("jar is not present!" + Fjar);
}
//}
Upp :: Exit ();
}
GUI_APP_MAIN
{
pkBack (). Run ();
}
what is commented above is because it doesn't work !!!
The above application loaded in java, checks if it is unique
and if it is already loaded, trigger an action so that the
window is in front of the others (This is exactly the objective
with U ++ ie to evaluate before calling the java application)
below the java code that works perfectly
and involves exactly calling the function
SetForegroundWindow (java libraries User32
WinDef ):
private static boolean focusApp () {
// Set focus to App
WinDef.HWND hwnd = User32.INSTANCE.FindWindow (null, "Backup"); // window title
boolean ret = false;
if (hwnd == null) {
} else {
User32.INSTANCE.ShowWindow (hwnd, 9); // SW_RESTORE
User32.INSTANCE.SetForegroundWindow (hwnd); // bring to front
ret = true;
}
return ret;
}
public static void main (String [] args) throws ClassNotFoundException, AlreadyLockedException {
String appId = "appBackid";
boolean alreadyRunning;
try {
JUnique.acquireLock (appId);
alreadyRunning = false;
} catch (AlreadyLockedException e) {
alreadyRunning = true;
}
if (! alreadyRunning) {
fBack form_ = new fBack ();
form_.setVisible (true);
form_.setLocationRelativeTo (null); // centralize form
} else {
focusApp ();
}
}
so my intention is to transfer the code from java to U ++, precisely because the initial load is done in U ++ !!
as I'm a newbie, I still don't have the ability to write the code and transport it to U ++. It is very similar to what was done to produce Window_Top, but I don't know how to do it.
In U ++ I know they are defined in winuser.h / winapifamily.h but in separate groups.
thankful
|
|
|
Goto Forum:
Current Time: Sat Jul 19 12:08:54 CEST 2025
Total time taken to generate the page: 0.02874 seconds
|