试试 int GetClassName( HWND hWnd, // handle of window LPTSTR lpClassName, // address of buffer for class name int nMaxCount // size of buffer, in characters );
End Sub //CALLBACK函数 Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim strTemp As String On Error GoTo Err
If (IsWindowVisible(hwnd)) And (GetWindowLong(hwnd, GWL_HWNDPARENT) = 0) _ And ((GetWindowLong(hwnd, GWL_EXSTYLE) And WS_EX_TOOLWINDOW) = 0) Then strTemp = "Handle:" & hwnd & ",Title:" & GetText(hwnd) frmTaskBar.cmbList.AddItem strTemp End If EnumWindowsProc = True Exit Function Err: MsgBox Err.Description Err.Clear EnumWindowsProc = TrueEnd Function
我用liaoxw81(liao)的方法,写了VC程序,如下: int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs cerr << _T("Fatal Error: MFC initialization failed") << endl; nRetCode = 1; } else { // TODO: code your application's behavior here. EnumWindows(EnumWindowsProc, 0); } return nRetCode; }BOOL CALLBACK EnumWindowsProc( HWND hwnd, // handle to parent window LPARAM lParam) // application-defined value { char className[250] = ""; char winTitle[250] = ""; LONG exStyle = 0; if ( IsWindowVisible(hwnd) && (GetParent(hwnd) == NULL) ) { exStyle = GetWindowLong(hwnd, GWL_EXSTYLE); if ( !(exStyle & WS_EX_TOOLWINDOW) ) { GetWindowText(hwnd, winTitle, sizeof(winTitle)); GetClassName(hwnd, className, sizeof(className)); printf("Windows Class Name : %s\n", className); printf("Windows Title : %s\n\n", winTitle); } } return true; }但是在运行FoxMail程序时,再运行该程序,得到的窗口列表不正确,Foxmail有两个窗口。 运行结果如下: Windows Class Name : ConsoleWindowClass Windows Title : C:\WINNT\system32\cmd.exe - testWindows Class Name : TFoxmail_Main Windows Title : FoxmailWindows Class Name : TApplication Windows Title : Foxmail .........截断............
int GetClassName(
HWND hWnd, // handle of window
LPTSTR lpClassName, // address of buffer for class name
int nMaxCount // size of buffer, in characters
);
我要的功能与金山游侠2002中点击搜索,弹出的程序列表窗口相同,它只取得在任务栏中
显示的窗口,不包括隐藏窗口。在有办法吗?
Public Sub ListWindow()
Call EnumWindows(AddressOf EnumWindowsProc, 0&)
End Sub
//CALLBACK函数
Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim strTemp As String On Error GoTo Err
If (IsWindowVisible(hwnd)) And (GetWindowLong(hwnd, GWL_HWNDPARENT) = 0) _
And ((GetWindowLong(hwnd, GWL_EXSTYLE) And WS_EX_TOOLWINDOW) = 0) Then
strTemp = "Handle:" & hwnd & ",Title:" & GetText(hwnd)
frmTaskBar.cmbList.AddItem strTemp
End If
EnumWindowsProc = True
Exit Function
Err:
MsgBox Err.Description
Err.Clear
EnumWindowsProc = TrueEnd Function
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0; // initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
EnumWindows(EnumWindowsProc, 0);
} return nRetCode;
}BOOL CALLBACK EnumWindowsProc(
HWND hwnd, // handle to parent window
LPARAM lParam) // application-defined value
{
char className[250] = "";
char winTitle[250] = "";
LONG exStyle = 0; if ( IsWindowVisible(hwnd)
&& (GetParent(hwnd) == NULL) )
{
exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
if ( !(exStyle & WS_EX_TOOLWINDOW) )
{
GetWindowText(hwnd, winTitle, sizeof(winTitle));
GetClassName(hwnd, className, sizeof(className));
printf("Windows Class Name : %s\n", className);
printf("Windows Title : %s\n\n", winTitle);
}
} return true;
}但是在运行FoxMail程序时,再运行该程序,得到的窗口列表不正确,Foxmail有两个窗口。
运行结果如下:
Windows Class Name : ConsoleWindowClass
Windows Title : C:\WINNT\system32\cmd.exe - testWindows Class Name : TFoxmail_Main
Windows Title : FoxmailWindows Class Name : TApplication
Windows Title : Foxmail
.........截断............
int i,index;
DWORD dwStyle;
HWND hTempWnd; hTempWnd=::FindWindowEx(NULL,NULL,NULL,NULL); count=0;
while(hTempWnd!=NULL)
{
if(IsWindow(hTempWnd)&&::IsWindowVisible(hTempWnd))
{
dwStyle=GetWindowLong(hTempWnd,GWL_EXSTYLE);
if(!(dwStyle&WS_EX_TOOLWINDOW))
{
::GetWindowText(hTempWnd,wininfo[count].Title,255);
if(strlen(wininfo[count].Title)>0&&strcmp("AutoHide 1.01",wininfo[count].Title)!=0)
{
wininfo[count].hWndProc=hTempWnd;
count++;
if(count>=TOTALWINDOW)
break;
}
}
}
hTempWnd=::FindWindowEx(NULL,hTempWnd,NULL,NULL);
}