日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MFC 获取窗口句柄

發布時間:2024/8/1 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MFC 获取窗口句柄 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、使用FindWindow函數獲取窗口句柄

示例:使用FindWindow函數獲取窗口句柄,然后獲得窗口大小和標題,并且移動窗口到指定位置。

#include <Windows.h> #include <stdio.h> #include <string.h> #include <iostream.h>int main(int argc, char* argv[]) {//根據窗口名獲取QQ游戲登錄窗口句柄HWND hq=FindWindow(NULL,"QQ2012"); //得到QQ窗口大小RECT rect; GetWindowRect(hq,&rect); int w=rect.right-rect.left,h=rect.bottom-rect.top;cout<<"寬:"<<w<<" "<<"高:"<<h<<endl;//移動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<<"寬:"<<w<<" "<<"高:"<<h<<endl;return 0; }

2、使用EnumWindows和EnumChildWindows函數以及相對的回調函數EnumWindowsProc和EnumChildWindowsProc獲取所有頂層窗口以及它們的子窗口(有些窗口做了特殊處理,比如QQ是不能通過這個方法獲得的)

示例:

#include "stdafx.h" #include <Windows.h> #include <stdio.h> #include <tchar.h> #include <string.h> #include <iostream.h>//EnumChildWindows回調函數,hwnd為指定的父窗口 BOOL CALLBACK EnumChildWindowsProc(HWND hWnd,LPARAM lParam) {char WindowTitle[100]={0}; ::GetWindowText(hWnd,WindowTitle,100);printf("%s\n",WindowTitle);return true; }//EnumWindows回調函數,hwnd為發現的頂層窗口 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[]) {//獲取屏幕上所有的頂層窗口,每發現一個窗口就調用回調函數一次EnumWindows(EnumWindowsProc ,NULL );return 0; }

3、使用GetDesktopWindow和GetNextWindow函數得到所有的子窗口

示例:

#include "stdafx.h" #include <Windows.h> #include <stdio.h> #include <tchar.h> #include <string.h> #include <iostream.h>int main(int argc, _TCHAR* argv[]) { //得到桌面窗口HWND hd=GetDesktopWindow();//得到屏幕上第一個子窗口hd=GetWindow(hd,GW_CHILD);char s[200]={0};//循環得到所有的子窗口while(hd!=NULL){memset(s,0,200);GetWindowText(hd,s,200);/*if (strstr(s,"QQ2012")){cout<<s<<endl;SetWindowText(hd,"My Windows");}*/cout<<s<<endl;hd=GetNextWindow(hd,GW_HWNDNEXT);}return 0; }

?

總結

以上是生活随笔為你收集整理的MFC 获取窗口句柄的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。