2012-09-21 28 views
1

所有窗口,我試着檢索一些信息(X,Y,寬度,高度和標題)在Windows上所有打開的窗口中有一個簡單的C++代碼(見下文):檢索打開在Windows

#include <iostream> 
#include <windows.h> 
using namespace std; 

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam); 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int  iCmdShow) 
{ 
    EnumWindows(EnumWindowsProc, NULL); 
    //system("PAUSE"); 
    return 0; 
} 

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) 
{ 
char class_name[255]; 
char title[255]; 
int tmpWidth; 
int tmpHeight; 
HWND currenthwnd; 
RECT WindowRect; 

GetClassName(hwnd,class_name, sizeof(class_name)); 
GetWindowText(hwnd,title,sizeof(title)); 
GetWindowRect(hwnd,&WindowRect); 

//if(WindowRect.left>-50 && title != "" && title != NULL && strlen(title)>0){ 
    tmpHeight = WindowRect.bottom - WindowRect.top; 
    tmpWidth = WindowRect.right - WindowRect.left; 
    cout <<"@@##@@"<<title<<",(@@#@@)"; 
    cout <<WindowRect.left<<",(@@#@@)"; 
    cout <<WindowRect.top<<",(@@#@@)"; 
    cout <<tmpWidth<<",(@@#@@)"; 
    cout <<tmpHeight<<",(@@#@@)"; 
    currenthwnd=GetForegroundWindow(); 
    if (currenthwnd!=hwnd){ 
     cout <<title<<",(@@#@@)false"; 
    }else{ 
     cout <<title<<",(@@#@@)true"; 
    } 
//} 

return TRUE; 
} 

但我遇到了這個代碼的一些問題,我也嘗試使用Get-Process函數的PowerShell,但是這個函數不會返回所有打開的窗口,而是返回所有現有的進程。

如何檢索標題,x,y,所有打開窗口的高度?

感謝您的幫助

+5

你遇到了什麼問題? – Default

+0

你能更具體一點'我遇到了這個代碼的一些問題'? –

回答

2

在PowerShell中您可以使用WASP模塊並寫了這樣的事情:

Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | 
% {$_.processname + "-" + $_.mainwindowtitle; 
     Get-WindowPosition -Window $_.handle } 

這是我的實際PowerShell的窗口結果例子:

powershell - Posh - Admin 
Location : {X=4,Y=44} 
Size  : {Width=885, Height=129} 
X  : 4 
Y  : 44 
Width : 885 
Height : 129 
Left  : 4 
Top  : 44 
Right : 889 
Bottom : 173 
IsEmpty : False 
+0

感謝您的幫助:) – eldondano

相關問題