Solved

focusing window by his handle

Posted on 2002-06-28
3
155 Views
Last Modified: 2010-04-04
How can i focus window if i got his handle?
i mean, like u use alt+tab to focus other window.

Thanks in advance,
        Daniel Leicht.
0
Comment
Question by:tomerlei
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Expert Comment

by:TOndrej
ID: 7116261
See SetForegroundWindow API in MSDN.
Note the differences on various Windows platforms.
0
 
LVL 4

Author Comment

by:tomerlei
ID: 7116291
what is the exact procedure?
0
 
LVL 7

Accepted Solution

by:
Cynna earned 50 total points
ID: 7116396
tomerlei,

Here's slightly modyfied version of Yorai Aminov's code:


function ForceForegroundWindow(Const hWnd: THandle): Boolean;
var hCurWnd: THandle;
begin
    Result := False;
    if not isWindow(hWnd) then Exit;
    hCurWnd := GetForegroundWindow;
    if (hCurWnd=hWnd) then begin
        Result := True;
        Exit;
    end;
    if (GetWindowLong( hWnd, GWL_STYLE ) and WS_MINIMIZE)<>0 then ShowWindow(hWnd, SW_SHOWNOACTIVATE);
    AttachThreadInput(GetWindowThreadProcessId(hCurWnd, nil),GetCurrentThreadId,True);
    Application.ProcessMessages; // !!!
    SetForegroundWindow(hWnd);
    AttachThreadInput(    GetWindowThreadProcessId(hCurWnd, nil),GetCurrentThreadId, False);
    Result := GetForegroundWindow=hWnd;
end;




DEMO:
-------
(place one Button on the form and start Notepad)


procedure TForm1.Button11Click(Sender: TObject);
begin
  ForceForegroundWindow(FindWindow('Notepad',nil));
end;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question