#include "stdafx.h" /* 文件名:EnumWindowStations.cpp 功能:枚举当前会话的session->window stations->Desktop->(top-level)Windows->(child)Windows的信息等. made by correy made at 2014.06.16 homepage:http://correy.webs.com */ #ifndef UNICODE #define UNICODE #endif // UNICODE #include <windows.h> //BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) //{ // // //To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE. // return TRUE; //} BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { //fprintf(stderr,"\t\t\tWindows handle:0x%X!\n", hwnd); /* 更多的信息,那就自己动手吧! 如:名字,处理函数等。 还可以EnumChildWindows。 甚至可以EnumThreadWindows(EnumThreadWndProc)。 */ //To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE. return TRUE; } BOOL CALLBACK EnumDesktopProc(IN LPTSTR lpszDesktop,IN LPARAM lParam) { fprintf(stderr,"\t\tDesktop name:%ws!\n", lpszDesktop); HDESK HD = OpenDesktop(lpszDesktop, 0, TRUE, GENERIC_READ); if (HD == NULL) { int x = GetLastError (); return x; } BOOL B = EnumDesktopWindows(HD, EnumWindowsProc, 0); if (!B) { int x = GetLastError (); } B = CloseDesktop(HD); if (!B) { int x = GetLastError (); return FALSE ; } //To continue enumeration, the callback function must return TRUE. To stop enumeration, it must return FALSE. return TRUE; } BOOL CALLBACK EnumWindowStationProc(IN LPTSTR lpszWindowStation,IN LPARAM lParam) { fprintf(stderr,"\tWindowStation name:%ws!\n", lpszWindowStation); HWINSTA Hws = OpenWindowStation(lpszWindowStation, TRUE, GENERIC_READ); if (Hws == NULL) { int x = GetLastError (); return x; } BOOL B = EnumDesktops(Hws, EnumDesktopProc, 0); if (!B) { int x = GetLastError (); } B = CloseWindowStation(Hws); if (!B) { int x = GetLastError (); return FALSE ; } //To continue enumeration, the callback function must return TRUE. To stop enumeration, it must return FALSE. return TRUE ; } int __cdecl main(int argc, char *argv[]) { fprintf(stderr,"当前会话的window stations->Desktop->Windows信息\n"); BOOL B = EnumWindowStations(EnumWindowStationProc, 0);//Enumerates all window stations in the current session if (!B) { int x = GetLastError (); return x; } return 0; }
2014年6月16日星期一
枚举当前会话的窗口站和桌面的信息
订阅:
博文评论 (Atom)
没有评论:
发表评论