Я использую Eclipse с Java, чтобы вынести стороннее приложение на передний план. Для этого я использую: < /p>
jna 5.12.1
jna platform jar 5.12.1 < /p>
Однако, когда третья сторона Приложение сводит к минимуму, оно только выделяется на панели задач, а не открывается на переднем плане. Напротив, такие приложения, как блокнот, открытый на переднем плане, как и ожидалось. Передний план, даже когда минимизируется.
в Visual Studio я использовал API setforegroundwindow , который прекрасно работал для восстановления моего приложения, когда оно было Минимизирован. Тем не менее, он только подчеркивает значок панели задач вместо того, чтобы доставить его на передний план. Studio < /p>
my java -образец кода < /p>
package focuswindowtest;
import com.sun.jna.*;
import com.sun.jna.platform.win32.*;
import com.sun.jna.platform.win32.WinDef.*;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.platform.win32.Kernel32;
public class focuswindowtest {
public interface User32 extends Library {
User32 INSTANCE = (User32) Native.load("user32", User32.class);
boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg);
int GetWindowThreadProcessId(HWND hWnd, IntByReference lpdwProcessId);
boolean SetForegroundWindow(HWND hWnd);
boolean ShowWindow(HWND hWnd, int nCmdShow);
boolean AttachThreadInput(int idAttach, int idAttachTo, boolean attach);
HWND GetForegroundWindow();
boolean AllowSetForegroundWindow(int pid);
boolean BringWindowToTop(HWND hWnd);
boolean SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
int WM_SYSCOMMAND = 0x0112;
int SC_RESTORE = 0xF120;
int SW_RESTORE = 9;
void keybd_event(byte bVk, byte bScan, int dwFlags, Pointer dwExtraInfo);
void GetWindowText(HWND hWnd, char[] windowText, int i);
boolean PostMessage(HWND hWnd, int Msg, WPARAM wParam, LPARAM lParam);
WinDef.LRESULT SendMessageW(WinDef.HWND hWnd, int Msg, WinDef.WPARAM wParam, WinDef.LPARAM lParam);
}
public static class WindowFinder implements WinUser.WNDENUMPROC {
private final int targetPid;
private HWND foundHwnd = null;
public WindowFinder(int targetPid) {
this.targetPid = targetPid;
}
@Override
public boolean callback(HWND hWnd, Pointer data) {
IntByReference pid = new IntByReference();
User32.INSTANCE.GetWindowThreadProcessId(hWnd, pid);
if (pid.getValue() == targetPid) {
foundHwnd = hWnd;
return false; // Stop enumeration
}
return true; // Continue enumeration
}
public HWND getFoundWindow() {
return foundHwnd;
}
}
public static HWND findWindowByProcessId(int targetPid) {
WindowFinder finder = new WindowFinder(targetPid);
User32.INSTANCE.EnumWindows(finder, null);
return finder.getFoundWindow();
}
public static final int SWP_TOPMOST = 0x00000008; // Topmost flag
public static final int SWP_NOMOVE = 0x00000002; // Do not change position
public static final int SWP_NOSIZE = 0x00000001; // Do not change size
public static final int SWP_SHOWWINDOW = 0x0040; // Show window
final static byte VK_MENU = 0x12; // ALT key
static int KEYEVENTF_KEYUP = 0x0002;
public static void main(String[] args) throws InterruptedException {
int processId = 17216; // Replace with your actual process ID
// Allow EA's process to set foreground window
User32.INSTANCE.AllowSetForegroundWindow(processId);
HWND hWnd = findWindowByProcessId(processId);
if (hWnd != null) {
//User32.INSTANCE.ShowWindow(hWnd,2);
Thread.sleep(300);
Thread.sleep(300); // Small delay
User32.INSTANCE.ShowWindow(hWnd, User32.SW_RESTORE);
Thread.sleep(300); // Small delay to allow restore
User32.INSTANCE.SetForegroundWindow(hWnd);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... on-to-fore
Java (JNA) против Visual Studio: донесение минимизированного стороннего приложения на передний план ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Назначение приложения iOS: динамически открывать приложение и выводить его на передний план.
Anonymous » » в форуме IOS - 0 Ответы
- 27 Просмотры
-
Последнее сообщение Anonymous
-