更新時(shí)間:2022-09-08 10:57:31 來源:動(dòng)力節(jié)點(diǎn) 瀏覽2476次
Java獲取當(dāng)前窗口句柄的方法有哪些?動(dòng)力節(jié)點(diǎn)小編來告訴大家。
示例:使用FindWindow函數(shù)獲取窗口句柄,然后獲得窗口大小和標(biāo)題,并且移動(dòng)窗口到指定位置。
#include
#include
#include
#include
int main(int argc, char* argv[])
{
//根據(jù)窗口名獲取QQ游戲登錄窗口句柄
HWND hq=FindWindow(NULL,"QQ2012");
//得到QQ窗口大小
RECT rect;
GetWindowRect(hq,&rect);
int w=rect.right-rect.left,h=rect.bottom-rect.top;
cout<
//移動(dòng)QQ窗口位置
MoveWindow(hq,100,100,w,h,false);
//得到桌面窗口
HWND hd=GetDesktopWindow();
GetWindowRect(hd,&rect);
w=rect.right-rect.left;
h=rect.bottom-rect.top;
cout<
return 0;
}
示例:
#include "stdafx.h"
#include
#include
#include
#include
#include
//EnumChildWindows回調(diào)函數(shù),hwnd為指定的父窗口
BOOL CALLBACK EnumChildWindowsProc(HWND hWnd,LPARAM lParam)
{
char WindowTitle[100]={0};
::GetWindowText(hWnd,WindowTitle,100);
printf("%s\n",WindowTitle);
return true;
}
//EnumWindows回調(diào)函數(shù),hwnd為發(fā)現(xiàn)的頂層窗口
BOOL CALLBACK EnumWindowsProc(HWND hWnd,LPARAM lParam)
{
if (GetParent(hWnd)==NULL && IsWindowVisible(hWnd) ) //判斷是否頂層窗口并且可見
{
char WindowTitle[100]={0};
::GetWindowText(hWnd,WindowTitle,100);
printf("%s\n",WindowTitle);
EnumChildWindows(hWnd,EnumChildWindowsProc,NULL); //獲取父窗口的所有子窗口
}
return true;
}
int main(int argc, _TCHAR* argv[])
{
//獲取屏幕上所有的頂層窗口,每發(fā)現(xiàn)一個(gè)窗口就調(diào)用回調(diào)函數(shù)一次
EnumWindows(EnumWindowsProc ,NULL );
return 0;
}
示例:
#include "stdafx.h"
#include
#include
#include
#include
#include
int main(int argc, _TCHAR* argv[])
{
//得到桌面窗口
HWND hd=GetDesktopWindow();
//得到屏幕上第一個(gè)子窗口
hd=GetWindow(hd,GW_CHILD);
char s[200]={0};
//循環(huán)得到所有的子窗口
while(hd!=NULL)
{
memset(s,0,200);
GetWindowText(hd,s,200);
/*if (strstr(s,"QQ2012"))
{
cout<
SetWindowText(hd,"My Windows");
}*/
cout<
hd=GetNextWindow(hd,GW_HWNDNEXT);
}
return 0;
}
0基礎(chǔ) 0學(xué)費(fèi) 15天面授
有基礎(chǔ) 直達(dá)就業(yè)
業(yè)余時(shí)間 高薪轉(zhuǎn)行
工作1~3年,加薪神器
工作3~5年,晉升架構(gòu)
提交申請(qǐng)后,顧問老師會(huì)電話與您溝通安排學(xué)習(xí)