線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3952
推到 Plurk!
推到 Facebook!

FindWindow的問題

答題得分者是:pceyes
lirick2003
一般會員


發表:17
回覆:16
積分:11
註冊:2007-02-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-07-14 14:32:22 IP:59.104.xxx.xxx 訂閱
我想請問~當Findwindow後...要如何把讀取到的app id顯示在"ID"這個Lable上.?
[code delphi]
procedure TMainForm.Button1Click(Sender: TObject);
begin
hCurrentWindow := Findwindow(nil, PChar(Edit1.Text));
end;
[/code]
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-07-14 21:51:23 IP:220.141.xxx.xxx 訂閱
先看這篇
Win32 API 使用討論區(Delphi) » 如何获取自己在程序中运行的外部EXE的Handle?
http://delphi.ktop.com.tw/board.php?cid=30&fid=72&tid=35055
//
例子整理於后
[code delphi]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
ID: TLabel;
Title: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
PEnumInfo = ^TEnumInfo;
TEnumInfo = record
ProcessID : DWORD;
HWND : THandle;
end;
function EnumWindowsProc(Wnd: DWORD; var EI: TEnumInfo): Bool; stdcall;
var
PID : DWORD;
begin
GetWindowThreadProcessID(Wnd, @PID);
Result := (PID <> EI.ProcessID) or
(not IsWindowVisible(WND)) or
(not IsWindowEnabled(WND));
if not result then EI.HWND := WND;
end;
function FindMainWindow(PID: DWORD): DWORD;
var
EI : TEnumInfo;
begin
EI.ProcessID := PID;
EI.HWND := 0;
EnumWindows(@EnumWindowsProc, Integer(@EI));
Result := EI.HWND;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
SI : TStartupInfo;
PI : TProcessInformation;
H : THandle;
S : String;
begin
ZeroMemory(@SI, SizeOf(SI));
ZeroMemory(@PI, SizeOf(PI));
SI.cb := SizeOf(SI);
if CreateProcess(nil,pchar(edit1.text), nil, nil, FALSE, 0 ,nil,nil, SI, PI) then
begin
WaitForInputIdle(PI.hProcess, INFINITE);
H := FindMainWindow(PI.dwProcessID);
if H > 0 then
begin
SetLength(S, 255);
GetWindowText(H, PChar(S), 255);
SetLength(S, StrLen(PChar(S)));
ID.Caption :='App PID= ' inttostr(PI.dwProcessID);
Title.caption := 'App Title= ' s;
end;
CloseHandle(PI.hProcess);
CloseHandle(PI.hThread);
end;
end;
end.
[/code]
//
dfm

[code delphi]
object Form1: TForm1
Left = 140
Top = 125
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ID: TLabel
Left = 168
Top = 256
Width = 11
Height = 13
Caption = 'ID'
end
object Title: TLabel
Left = 168
Top = 288
Width = 20
Height = 13
Caption = 'Title'
end
object Button1: TButton
Left = 128
Top = 112
Width = 249
Height = 81
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object Edit1: TEdit
Left = 104
Top = 48
Width = 281
Height = 21
TabOrder = 1
Text = 'CALC.EXE'
end
end
[/code]
------
努力會更接近成功
編輯記錄
pceyes 重新編輯於 2008-07-14 22:19:15, 註解 無‧
careychen
尊榮會員


發表:41
回覆:580
積分:959
註冊:2004-03-03

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-07-16 23:31:34 IP:59.126.xxx.xxx 訂閱
基本上來說,你的語法不大對,如果是 FindWindow 的話,要

FindWindow( ClassName, WindowName )

所以依你的問題,假設是讀取小算盤的 APP Handle ,則應該是寫成

ID.Caption := IntToStr(Findwindow(nil, '小算盤'));
------
價值的展現,來自於你用哪一個角度來看待它!!
系統時間:2024-04-29 8:35:03
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!