Home > Back-end >  How do you use the SetForegroundWindow in a 64 - bit Windows?
How do you use the SetForegroundWindow in a 64 - bit Windows?

Time:10-05

I designed a program to open the two game software, automatic playing chess, one of the top window with SetForegroundWindow function, and then simulate the mouse button, automatically move later, at a certain position in the program in Windows XP and can run 32-bit Windows 7 system, in a 64 - bit Windows have a problem, such as "ground city go," city SetForegroundWindow function can implement window is placed at the top, but is not active, so the mouse action can perform,

Excuse me: in a 64 - bit Windows, SetForegroundWindow function how to use? Want complement some code or use other function? Master please help,

Other: BringWindowToTop, SetActiveWindow function are tried, such as null and void, also checked a lot of information online, didn't find the effective solutions, Delphi

I attached a more see posts online, but I am clumsy, really don't understand,

The HWND HWND=: : FindWindow (_T (" # 32770 "), _T (" test "));

If (hWnd)
{
HWND hForeWnd=: : GetForegroundWindow ();
DWORD dwForeID=: : GetWindowThreadProcessId (hForeWnd, NULL);
DWORD dwCurID=: : GetCurrentThreadId ();
: : AttachThreadInput (dwCurID dwForeID, TRUE);
: : ShowWindow (hWnd, SW_SHOWNORMAL);
: : SetWindowPos (hWnd HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
: : SetWindowPos (hWnd HWND_NOTOPMOST, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
: : SetForegroundWindow (hWnd);
: : AttachThreadInput (dwCurID dwForeID, FALSE);
return 0;
}

CodePudding user response:

The use of API, Delphi is also can be the same

CodePudding user response:

Don't know what is the difference between 32-bit and 64 - bit down, I also have no a 64 - bit system test

CodePudding user response:

It can help me put on the code above rewritten into Delphi format?

The HWND HWND=: : FindWindow (_T (" # 32770 "), _T (" test "));

If (hWnd)
{
HWND hForeWnd=: : GetForegroundWindow ();
DWORD dwForeID=: : GetWindowThreadProcessId (hForeWnd, NULL);
DWORD dwCurID=: : GetCurrentThreadId ();
: : AttachThreadInput (dwCurID dwForeID, TRUE);
: : ShowWindow (hWnd, SW_SHOWNORMAL);
: : SetWindowPos (hWnd HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
: : SetWindowPos (hWnd HWND_NOTOPMOST, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
: : SetForegroundWindow (hWnd);
: : AttachThreadInput (dwCurID dwForeID, FALSE);
return 0;
}

CodePudding user response:

 
Var
Hw, hForeWnd: HWND;
DwForeID dwCurID: dwords.
The begin
.
Hw:=FindWindow (' # 32770 ', 'test');
If (hw & gt; 0) then
The begin
DwForeID:=GetWindowThreadProcessId (hForeWnd, nil);
DwCurID:=GetCurrentThreadId;
ShowWindow (hw, SW_SHOWNORMAL);
SetWindowPos (hw, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
SetWindowPos (hw, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
The SetForegroundWindow (hw);
AttachThreadInput (dwCurID dwForeID, False);
Result:=0;
The Exit;
end;
.
end;

CodePudding user response:

The above code must be within a particular function, otherwise there is no Result

CodePudding user response:

The SetForegroundWindow (hd0);
Now find the set-top and activate this function can put the window, but perform t:=SetCursorPos (500500); , they found some window T value is true, some window T return value to false?

I use the silver star city go go and implement two test interface, silver star go T the return value is true; Implement city go t return values for the falsh, SetCursorPos use is wrong?

CodePudding user response:

Don't know the silver star city, go, go and implement various software on UI, drawing and so on all may have their own way to handle it, use the API to control them is not always effective, depending on the software works, to understand their working principle and targeted treatment,

CodePudding user response:

Find this BBS is becoming more and more cold and cheerless, looking forward to the emergence of you, it's already dusk,

Is the window of the city in 64 - bit Windows system implement go Style different from ordinary window, thus lead to SetCursorPos function effect?

CodePudding user response:

If you even tried AttachThreadInput function, still not solve, so, I suggest you on a 64 - bit operating system, shilling minimize, restore again, so it must be the current window, in order to replace the SetForegroundWindow, a minimization function, a reduction of window function, use Delphi for a long time, can't remember what is minimized function, but we use openicon function restore Windows,

CodePudding user response:

references 9 f mwy654321 response:
if you even tried AttachThreadInput function, still not solve, so, I suggest you on a 64 - bit operating system, shilling minimize, restore again, so it must be the current window, in order to replace the SetForegroundWindow, a minimization function, a reduction of window function, use Delphi for a long time, can't remember what is minimized function, but restore Windows is using openicon function,




I found the problem in SetCursorPos now, rather than the SetForegroundWindow

CodePudding user response:

Fortunately, Windows provides us with AttachThreadInput, it can be a thread of input processing mechanism attached to another thread, so we have the following code:
//get created the foreground window thread
DWORD dwThread=GetWindowThreadProcessId (GetForegroundWindow (), NULL);
//to the foreground window attached to the current thread thread (that is, the program of the calling thread A)
AttachThreadInput (dwThread, GetCurrentThreadId (), TRUE);
//get focus window handle
HWND hFocus=GetFocus ();
//remove attached with a
AttachThreadInput (dwThread, GetCurrentThreadId (), FALSE);
//send a message
PostMessage (hFocus, WM_KEYDOWN, VK_TAB, 0);
.

CodePudding user response:

64 in principle, can run 32-bit programs, but if the program involves hardware (parameters) to read and write API, not be the same way, especially the way of assembly data, there is no, don't run or crash, if you want to satisfy your program run on 64 - bit, the best solution, is to use a 64 - bit Delphi compiler, for example, XE,
The above code is calling the API, you can't change, only change the compiler environment, upgrade using XE, some success,

CodePudding user response:

SetForegroundWindow impression does in a 64 - bit code fails, it will make the window on the status line, and can't let it come to the front desk
Just checked the previous code, need to perform before the
SetWindowPos twice, once with HWND_TOPMOST parameters, another with HWND_NOTOPMOST parameters,
Then with the SetForegroundWindow
This method should be both 32-bit and 64 - bit dizzy that is efficient to death

CodePudding user response:

CKC quote 13 floor response:
SetForegroundWindow impression does in a 64 - bit code fails, it will make the window on the status line, and can't let it come to the front desk
Just checked the previous code, need to perform before the
SetWindowPos twice, once with HWND_TOPMOST parameters, another with HWND_NOTOPMOST parameters,
nullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related