JJ8XNP_program
Delphi6でプログラムしています。
ハムログ、CTESTWIN、DSCWのコントロールのハンドルを取得する方法について
クラスネームやTEXT文字から取得できるのは限られていて全てを取得することはできないので
コントロールの位置から取得することを考えてみた。
CTESTWINの場合、フォームのサイズを変更するとコントロールの位置も変わってしまうため
Left:=0;Top:=0;Width:=500;Heigth:=300;のように変えてコントロールの位置から取得し、
その後、戻す事でハンドルを取得した。
DSCWではパネルにあるコントロールはこの方法ではできないようなので
共有メモリーを使用して取得した。
例
function TForm1.GetHamlogHandle(HandleName:String):HWnd;
var
hWindow:HWnd; R:TRect; i:Integer; ParentLeft,ParentTop:Integer; hLogA : HWND;
begin
Result:=0;
ListBox3.Clear; ListBox4.Clear;
hLogA := FindWindow('TForm_A',nil ); if hLogA = 0 then exit;
if GetWindowRect(hLogA, R) then else ShowMessage('Hamlog親Window位置取得失敗');
ParentLeft:=R.Left;
ParentTop:=R.Top;
hWindow :=GettopWindow(hLogA);
if GetWindowRect(hWindow, R) then else Memo2.Text:=Memo2.Text + 'GetWindowRect=False';
if (R.Left-ParentLeft) = 18 then begin ListBox3.Items.Add('hCallSign'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 132 then begin ListBox3.Items.Add('hDate'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 226 then begin ListBox3.Items.Add('hTime'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 300) and ((R.Top-ParentTop) = 88) then begin ListBox3.Items.Add('hHis'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 344) and ((R.Top-ParentTop) = 88) then begin ListBox3.Items.Add('hMy'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 388 then begin ListBox3.Items.Add('hFreq'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 472 then begin ListBox3.Items.Add('hMode'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 526 then begin ListBox3.Items.Add('hCode'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 600 then begin ListBox3.Items.Add('hGL'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 674 then begin ListBox3.Items.Add('hQSL'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 93 ) and ((R.Top-ParentTop) = 131) then begin ListBox3.Items.Add('hName'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 353 then begin ListBox3.Items.Add('hQTH'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 93 ) and ((R.Top-ParentTop) = 166) then begin ListBox3.Items.Add('hRem1'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 93 )and ((R.Top-ParentTop) = 201) then begin ListBox3.Items.Add('hRem2'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 655 then begin ListBox3.Items.Add('hSaveBut'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 371 then begin ListBox3.Items.Add('hCkCQ'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 423 then begin ListBox3.Items.Add('hCk1'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 463 then begin ListBox3.Items.Add('hCk2'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 88 then begin ListBox3.Items.Add('hCkDX'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 123 then begin ListBox3.Items.Add('hListCall'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 300) and ((R.Top-ParentTop) = 34) then begin ListBox3.Items.Add('hListFreq'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 344) and ((R.Top-ParentTop) = 34) then begin ListBox3.Items.Add('hListR1'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 155 then begin ListBox3.Items.Add('hListR2'); ListBox4.Items.Add(IntToStr(hWindow)); end;
for i:=2 to 23 do
begin
hWindow :=GetNextWindow(hWindow, GW_HWNDNEXT);
GetWindowRect(hWindow, R);
if (R.Left-ParentLeft) = 18 then begin ListBox3.Items.Add('hCallSign'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 132 then begin ListBox3.Items.Add('hDate'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 226 then begin ListBox3.Items.Add('hTime'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 300) and ((R.Top-ParentTop) = 88) then begin ListBox3.Items.Add('hHis'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 344) and ((R.Top-ParentTop) = 88) then begin ListBox3.Items.Add('hMy'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 388 then begin ListBox3.Items.Add('hFreq'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 472 then begin ListBox3.Items.Add('hMode'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 526 then begin ListBox3.Items.Add('hCode'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 600 then begin ListBox3.Items.Add('hGL'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 674 then begin ListBox3.Items.Add('hQSL'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 93 ) and ((R.Top-ParentTop) = 131) then begin ListBox3.Items.Add('hName'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 353 then begin ListBox3.Items.Add('hQTH'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 93 ) and ((R.Top-ParentTop) = 166) then begin ListBox3.Items.Add('hRem1'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 93 )and ((R.Top-ParentTop) = 201) then begin ListBox3.Items.Add('hRem2'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 655 then begin ListBox3.Items.Add('hSaveBut'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 371 then begin ListBox3.Items.Add('hCkCQ'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 423 then begin ListBox3.Items.Add('hCk1'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 463 then begin ListBox3.Items.Add('hCk2'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 88 then begin ListBox3.Items.Add('hCkDX'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 123 then begin ListBox3.Items.Add('hListCall'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 300) and ((R.Top-ParentTop) = 34) then begin ListBox3.Items.Add('hListFreq'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if ((R.Left-ParentLeft) = 344) and ((R.Top-ParentTop) = 34) then begin ListBox3.Items.Add('hListR1'); ListBox4.Items.Add(IntToStr(hWindow)); end;
if (R.Left-ParentLeft) = 155 then begin ListBox3.Items.Add('hListR2'); ListBox4.Items.Add(IntToStr(hWindow)); end;
end;
for i:=0 to ListBox3.Count-1 do if HandleName= ListBox3.Items[i] then Result:=StrToInt(ListBox4.Items[i]);
end;
function TForm1.GetCTestWinHandle():String;
var
hWindow:HWnd; R:TRect; i:Integer; ParentLeft,ParentTop,ParentRight,ParentBottom:Integer;
Child01L, Child01T :Integer; NowLeft,NowTop,NowRight,NowBottom:Integer;
hLogA,hCallSign,hHis,hRegistration,hDup: HWND;
PC:PChar; Len:integer; name:string;
begin
hLogA:=0;hCallSign:=0;hHis:=0;hRegistration:=0;
hLogA := FindWindow('Ctestwin',nil ); if hLogA = 0 then begin ShowMessage('FindWindow(Ctestwin)=0'); exit; end; // 元に戻すため保存
if GetWindowRect(hLogA, R) then else ShowMessage('CTestWin親Window位置取得失敗1');
NowLeft:=R.Left;NowTop:=R.Top; NowRight:= R.Right; NowBottom:=R.Bottom; //SetWindowPos(hLogA,0, NowLeft,NowTop,NowRight-NowLeft, NowBottom-NowTop,0);
if SetWindowPos(hLogA,0, 1, 5,1650, 736,0) then else ShowMessage('CTestWinサイズ変更失敗');
ListBox31.Clear; ListBox32.Clear; Memo31.Text:='';
if GetWindowRect(hLogA, R) then else ShowMessage('CTestWin親Window位置取得失敗2'); //親のLeft,Topが求まる
ParentLeft:=R.Left;ParentTop:=R.Top; ParentRight:= R.Right; ParentBottom:=R.Bottom;
hWindow :=GettopWindow(hLogA); //#32770//指定された親ウィンドウが持つ子ウィンドウの Z オーダーを調べ、Z オーダーが一番上の子ウィンドウのハンドルを返します。
hWindow :=GettopWindow(hWindow); //Button
if GetWindowRect(hWindow, R) then else Memo31.Text:=Memo31.Text + 'GetWindowRect=False'; //1番目のコントロールのLeft,Topが求まる
Memo31.Text:=Memo31.Text + 'Left=' + IntTOStr(R.Left-ParentLeft) + ' Top=' + IntTOStr(R.Top-ParentTop) ;
if ((R.Left-ParentLeft) = 670) and ((R.Top-ParentTop) =604) then //Top=708 ParentLeft=1 ParentTop=5 ParentRight=1651 ParentBottom=741
begin //の時の値につきサイズ変更で変わる
hHis:=hWindow;
end;
if ((R.Left-ParentLeft) = 114) and ((R.Top-ParentTop) =604) then
begin
hCallSign:=hWindow;
end;
if ((R.Left-ParentLeft) = 362) and ((R.Top-ParentTop) =569) then
begin
hRegistration:=hWindow;
end;
if ((R.Left-ParentLeft) = 18) and ((R.Top-ParentTop) =569) then
begin
hDup:=hWindow;
end;
for i:=2 to 29 do
begin
hWindow :=GetNextWindow(hWindow, GW_HWNDNEXT); //23回
GetWindowRect(hWindow, R); //1番目のコントロールのLeft,Topが求まる
Child01L:= R.Left;
Child01T:= R.Top;
Memo31.Text:=Memo31.Text + #$D#$A + 'Left=' + IntTOStr(R.Left-ParentLeft) + ' Top=' + IntTOStr(R.Top-ParentTop) ;
if ((R.Left-ParentLeft) = 670) and ((R.Top-ParentTop) =604) then //Top=708 ParentLeft=1 ParentTop=5 ParentRight=1651 ParentBottom=741
begin //の時の値につきサイズ変更で変わる
hHis:=hWindow;
end;
if ((R.Left-ParentLeft) = 114) and ((R.Top-ParentTop) =604) then
begin
hCallSign:=hWindow;
end;
if ((R.Left-ParentLeft) = 362) and ((R.Top-ParentTop) =569) then
begin
hRegistration:=hWindow;
end;
if ((R.Left-ParentLeft) = 18) and ((R.Top-ParentTop) =569) then
begin
hDup:=hWindow; //ListBox31.Items.Add('hCallSign :=' + IntToStr(hWindow));
end;
end;
SetWindowPos(hLogA,0, NowLeft,NowTop,NowRight-NowLeft, NowBottom-NowTop,0);
Result:= IntToStr(hCallSign) + #$D#$A + IntToStr(hHis) + #$D#$A + IntToStr( hRegistration) + #$D#$A + IntToStr( hDup);
end;
例
function TForm1.GetDSCWHandle():String;
var
hNow,hWindow:HWnd; R:TRect; i:Integer; ParentLeft,ParentTop,ParentRight,ParentBottom:Integer;
Child01L, Child01T :Integer; NowLeft,NowTop,NowRight,NowBottom:Integer;
hLogA,hCallSign,hHis,hRegistration,hDup: HWND;
PC:PChar; Len:integer; Classname, name:string;
begin
Result:='';
ListBox61.Clear; ListBox62.Clear; Memo61.Text:='';
hLogA:=0;hCallSign:=0;hHis:=0;hRegistration:=0;
hLogA := FindWindow('hWndDSCW',nil );// FindWindow('hWndDSCW','DigitalSoundCW V17.00.00 [Link to Turbo HamLog]' ); //元に戻すため保存
hNow:= hLogA;
if GetWindowRect(hLogA, R) then else ShowMessage('親Window位置取得失敗DSCW_A'); //親のLeft,Topが求まる
NowLeft:=R.Left; NowTop:=R.Top; NowRight:= R.Right; NowBottom:=R.Bottom;
if SetWindowPos(hLogA,0, 0,0,R.Right-R.Left,R.Bottom-R.Top,0) then begin end else ShowMessage('X');
if GetWindowRect(hLogA, R) then else ShowMessage('親Window位置取得失敗DSCW_B'); //親のLeft,Topが求まる
ParentLeft:=R.Left;ParentTop:=R.Top; ParentRight:= R.Right; ParentBottom:=R.Bottom; //ParentLeft=960 ParentTop=600 ParentRight=960 ParentBottom=600
hLogA := FindWindow('hWndDSCW',nil );
hLogA := FindWindowEX(hLogA,0,'#32770',nil);
hLogA := GettopWindow(hLogA);
GetMem(PC, 100);
Len :=GetClassName(hLogA, PC, 100);
SetString(Classname, PC, Len);
FreeMem(PC);
if Classname = 'Button' then
begin
if GetWindowRect(hLogA, R) then else ShowMessage('親Window位置取得失敗DSCW1');
Memo61.Text:=Memo61.Text + 'Left=' + IntTOStr(R.Left-ParentLeft) + ' Top=' + IntTOStr(R.Top-ParentTop) ;
if ((R.Left-ParentLeft) = 375) and ((R.Top-ParentTop) = 247) then
begin hCallSign:=hLogA; ListBox61.Items.Add('hCallSignR:=' + IntToStr(hCallSign)); Edit61.Text:=IntToStr(hCallSign); end;
if ((R.Left-ParentLeft) = 778) and ((R.Top-ParentTop) = 249) then
begin hCallSign:=hLogA; ListBox61.Items.Add('hCallSignL:=' + IntToStr(hCallSign)); Edit61.Text:=IntToStr(hCallSign); end;
end;
for i:=2 to 132 do
begin
hLogA := GetNextWindow(hLogA, GW_HWNDNEXT);
GetMem(PC, 100);
Len :=GetClassName(hLogA, PC, 100);
SetString(Classname, PC, Len);
FreeMem(PC);
if Classname = 'Button' then
begin
if GetWindowRect(hLogA, R) then else ShowMessage('親Window位置取得失敗' + IntToStr(i));
Memo61.Text:=Memo61.Text + 'Left=' + IntTOStr(R.Left-ParentLeft) + ' Top=' + IntTOStr(R.Top-ParentTop) ;
if ((R.Left-ParentLeft) = 375) and ((R.Top-ParentTop) = 247) then
begin hCallSign:=hLogA; ListBox61.Items.Add('hCallSignR:=' + IntToStr(hCallSign)); Edit61.Text:=IntToStr(hCallSign); end;
if ((R.Left-ParentLeft) = 778) and ((R.Top-ParentTop) = 249) then
begin hCallSign:=hLogA; ListBox61.Items.Add('hCallSignL:=' + IntToStr(hCallSign)); Edit61.Text:=IntToStr(hCallSign); end;
end;
end;
Memo61.Text:=Memo61.Text + #$D#$A + 'ParentLeft=' + IntTOStr(ParentLeft) + ' ParentTop=' + IntTOStr(ParentTop)
+' ' + 'ParentRight='+ IntTOStr(ParentRight) + ' ParentBottom=' + IntToStr(ParentBottom) ;
SetWindowPos(hNow,0, NowLeft,NowTop,NowRight-NowLeft, NowBottom-NowTop,0);
Result:= IntToStr(hCallSign);
end;
//■■■■■■■■■■■ JARL会員検索結果取得 ■■■■■■■■■■■■■■■
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate(
'https://www.jarl.com/Page/Search/MemberSearch.aspx?Language=Jp');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
IEObj : InternetExplorer;
Doc2 : IHtmlDocument2;
iInputElement : IHTMLInputElement;
iButtonElement : DispHTMLButtonElement;
IEElement : IHTMLElement;
begin
IEObj := WebBrowser1.Application as InternetExplorer;
Doc2 := IEObj.Document as IHTMLDocument2;
//iButtonElement:= Doc2.all.item('btnClear', 0) as DispHTMLButtonElement;
//iButtonElement.click; //クリアボタン押す
iInputElement := Doc2.All.Item ('txtCallSign',0) as iHTMLInputElement;
iInputElement.value := 'JJ8JJJ'; //調べたいコールサイン
iButtonElement:= Doc2.all.item('btnSearch', 0) as DispHTMLButtonElement;
iButtonElement.click; //検索ボタン押す
while WebBrowser1.ReadyState < READYSTATE_COMPLETE do
begin Application.ProcessMessages; end;
IEElement := (WebBrowser1.Document as IHTMLDocument2).body.parentElement;
if Pos('87ceeb' ,IEElement.outerHTML)<>0 then begin end
else
begin
if Pos('○ No' ,IEElement.outerHTML)<>0 then Edit1.Text := '△'
else if (Pos('○ Yes',IEElement.outerHTML)<>0)
and (Pos('○ Yes',IEElement.outerHTML)<5100) then Edit1.Text := '○'
else Edit1.Text := '×';
end;
end;
//■■■■■■■■■■■ 別の方法 JARL会員検索結果取得 ■■■■■■■■■■■
function TForm1.Search_JARL:String;
var
S:UTF8String; ST:String; i:Integer; FCallStr:String;
begin
FCallStr:='JJ8XNP';
S:=GetUrlContent('https://www.jarl.com/Page/Search/MemberSearch.aspx?'
+ '__LASTFOCUS=&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKLTI3MzIwMzYwNw9kFgICAw9kFg4CCQ8PZBYCHgVzdHlsZQUNZGlzc'
+'GxheTpub25lO2QCCw8UKwACD2QWAh8ABQ1kaXNwbGF5Om5vbmU7ZGQCDQ8UKwACD2QWAh4FU3R5bGUFDWRpc3BsYXk6bm9uZTtkZAIPDxYCHwAFDWRpc3BsYX'
+'k6bm9uZTtkAhEPFgIfAAUNZGlzcGxheTpub25lO2QCFQ8PFgYeB1Rvb2xUaXBlHglCYWNrQ29sb3IKpAEeBF8hU0ICCGRkAh8PD2QWAh8ABQ1kaXNwbGF5Om5'
+'vbmU7ZBgCBQlMaXN0VmlldzIPZ2QFCUxpc3RWaWV3MQ9nZBS04f3o0OTe1PM%2F4%2F7V68O9BPqvnOlkHdkTqe0BsGEz&__VIEWSTATEGENERATOR=097A74'
+'EB&__EVENTVALIDATION=%2FwEdAAaY%2F8%2BnpNbuk6x7UF4RCvwhkWpkX9aHnOz47z3JMElG1Y7U3Vc0WZ%2BwxclqyPFfzmN13HaNCmKPXwtSIMJvlpwq'
+'H%2FvOWBNEQxsmmy2gqOzbi6C3b14QOYyPtGyysa3RdBU7vpuUgVC0GgHQ7JWPHOI9mnW5LyiaOX3DGVMQSmSsSw%3D%3D&txtCallSign='
+ FCallStr
+ '&btnSearch=%E6%A4%9C%E3%80%80%E7%B4%A2&hdnMemberType=Jp'
); //ここがもし変わった場合、変更
ST:=UTF8Decode(S); //文字化け解消
ST:= Copy( ST, 1 , Pos('id="JpGuidLine"' , ST) -5 +1 ); //id="JpGuidLine" 以下を削除
if (Pos('○ No' ,ST)<>0) then Result:='△' else
if (Pos('○ Yes',ST)<>0) then Result:='○' else
if (Pos('×' ,ST)<>0) then Result:='X' else
Result:='?';
end;
function TForm1.SearchCSV(CS:String;Num:Integer):String; //カンマの何個目の要素を取り出す関数
var
i:Integer; S:String; SL:TStringList; //SearchCSV(SL[0],2); //局数 SearchCSV(SL[1],21); //Callsign
begin
S:=CS;
SL:=TStringList.Create;
try
SL.Text:='';
while Pos(',',S)<>0 do
begin
SL.Append( Copy( S ,1, Pos(',',S) -1 ) );
S:=Copy( S , Pos(',',S)+1,Length(S) -Pos(',',S) );
end;
SL.Append(S); //最後は「,」がないので足す
Result:=SL[Num-1];
if Copy(Result,1,1)='"' then Result:=Copy(Result,2,Length(Result)-1); //先頭「"」を除去
if Copy(Result,Length(Result),1)='"' then Result:=Copy(Result,1,Length(Result)-1); //末尾「"」を除去
finally
SL.Free;
end;
end;