lnishimura
asked on
Get last window handle?
HI :D
I have a little program that has some shortcuts to windows apps:
I need function to Get the handle of the last program...
Can Somebody Help? please :P
I have a little program that has some shortcuts to windows apps:
I need function to Get the handle of the last program...
Can Somebody Help? please :P
Could you please specify what you mean with "the last program"?
ASKER
All Exe Program Software that creates a window has a handle right?
Ussually an integer... i need to know the handle of the last one...
Got it?
here goes a sample that lists the handles but i cant get the last one opened
procedure LIstApp;
const
MAX_WINDOW = 16364;
var
I : Integer
Caption: Array[0..255]Of Char;
//Lista : TStringList;
begin
//Lista:=TStringList.Creat e;
//Lista.Sorted:=True;
For I:=1 To MAX_WINDOW Do
Begin
If((GetWindowText(I,Captio n,255)<>0) And (GetWindowLong(I,GWL_EXSTY LE)<>0)And
(GetWindowLong(I,GWL_HWNDP ARENT)=0)A nd (GetWindowLong(I,GWL_HINST ANCE)<>0)) Then
If(IsWindowVisible(I))Then begin
form1.Lista.Items.Add(intt ostr(i));
end;
end;
end;
Ussually an integer... i need to know the handle of the last one...
Got it?
here goes a sample that lists the handles but i cant get the last one opened
procedure LIstApp;
const
MAX_WINDOW = 16364;
var
I : Integer
Caption: Array[0..255]Of Char;
//Lista : TStringList;
begin
//Lista:=TStringList.Creat
//Lista.Sorted:=True;
For I:=1 To MAX_WINDOW Do
Begin
If((GetWindowText(I,Captio
(GetWindowLong(I,GWL_HWNDP
If(IsWindowVisible(I))Then
form1.Lista.Items.Add(intt
end;
end;
end;
You should use EnumWindows instead of looping through possible window handles.
ASKER
Any Sample or function i can use?
For EnumWindows you need to write a function that is called when a window is found. Like this:
function EnumWindowsProc(hWnd: HWND; lParam: LParam): Bool;
var
processID, tmpID: DWord;
tmpCaption: array[0..99] of Char;
tmp: String;
begin
Result:= True;
GetWindowThreadProcessID(h
//*** do not get oneself
if processID <> GetCurrentProcessID then
begin
//*** exclude taskbar, desktop and own tray menu
if (hWnd <> FindWindow('Shell_TrayWnd'
(hWnd <> FindWindow('Progman', nil)) and
(hWnd <> Findwindow(nil, 'frmMain.mnuTray')) then
begin
if isWindowVisible(hWnd) then
begin
{ Do something }
end;
end;
end;
end;
Then call EnumWindows like this:
EnumWindows(@EnumWindowsPr
The EnumWindowsProc above is from a prog of me, so the code inside is just an example.
Pleae make that EnumWindowsProc to be "stdcall" !!
You execute these windows Apps from your code.... right ? If so - just when you execute with ShellExecute for example take the result somewhere. It returns Handle ...
ASKER
i Know i can put some thing after ShellExecute...and MarcG is very nice to use too....However
what can i put after shellExecute that returns me the las handle?
what can i put after shellExecute that returns me the las handle?
I don't understand you .... ShellExecute is function - it has result :
HINSTANCE ShellExecute(
HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);
Return Values
If the function succeeds, the return value is the instance handle of the application that was run, or the handle of a dynamic data exchange (DDE) server application.
ASKER
hmn
i will test it
let you know...does it returns the Handle of the soft i opened rght?
i will test it
let you know...does it returns the Handle of the soft i opened rght?
"instance handle of the application that was run"
you can find the declaration of HInst type, which is in fact THandle... Enjoy :)
ASKER
dude.... i'm too much stupid to undersntand your answer(still newbie in delphi)...
Can u post some code that really helps me a lot Thanx :D
Can u post some code that really helps me a lot Thanx :D
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.