#ifndef __CFindEnumWindow_H #define __CFindEnumWindow_H //--------------------------------------------------------------------------- // ÁöÁ¤ÇÑ Å¬·¡½º¿Í ƯÁ¤ ¹®ÀÚ¿­À» Æ÷ÇÔÇÏ´Â À©µµ ã±â Ŭ·¡½º // º¹¼ö°³¸¦ ã¾ÆÁִµ¥, ÇÚµé, ±× À©µµ Ŭ·¡½º¸í, À©µµ ĸ¼Ç¸íÀ» ½±°Ô Á¶È¸ÇÒ ¼ö ÀÖ´Ù. // // Written by KTS class CFindEnumChildWindow { private: HWND hParent; TList *List; char *sClassName; bool bClassNameSubString; char *sTitle; bool bTitleSubString; char Buffer[1024]; private: static BOOL CALLBACK EnumChildWndProc(HWND hwnd, LPARAM lParam) { CFindEnumChildWindow *This = reinterpret_cast(lParam); char *text = This->Buffer; if (This->sClassName != NULL) { if (GetClassName(hwnd, text, 1023)) { //TRACE("%s", text); if ((!This->bClassNameSubString && !strcmp(text, This->sClassName)) || (This->bClassNameSubString && strstr(text, This->sClassName))) { if (This->sTitle != NULL) { text[0] = 0; GetWindowText(hwnd, text, 1023); if ((!This->bTitleSubString && !strcmp(text, This->sTitle)) || (This->bTitleSubString && strstr(text, This->sTitle))) { This->List->Add(hwnd); } } else This->List->Add(hwnd); } } } else { if (This->sTitle != NULL) { text[0] = 0; GetWindowText(hwnd, text, 1023); if ((!This->bTitleSubString && !strcmp(text, This->sTitle)) || (This->bTitleSubString && strstr(text, This->sTitle))) { This->List->Add(hwnd); } } } return TRUE; } int GetCount() { return List->Count; } HWND GetHandle(int index) { if (index >= List->Count || List->Count <= 0) return NULL; return List->Items[index]; } String _GetClassName(int index) { if (index >= List->Count || List->Count <= 0) return NULL; char *text = Buffer; GetClassName(Handles[index], text, 1023); return text; } String _GetWindowText(int index) { if (index >= List->Count || List->Count <= 0) return NULL; char *text = Buffer; GetWindowText(Handles[index], text, 1023); return text; } public: CFindEnumChildWindow() { List = new TList; } ~CFindEnumChildWindow() { delete List; } bool Scan(HWND parent, char *class_name, char *title, bool class_substring = true, bool title_substring = true) { List->Clear(); hParent = parent; sClassName = class_name; sTitle = title; bClassNameSubString = class_substring; bTitleSubString = title_substring; return EnumChildWindows(hParent, (FARPROC)EnumChildWndProc, (long)this); } // ãÀº µ¥ÀÌŸ Çڵ鸵. // __property String ClassName[int index] = { read=_GetClassName }; __property String WindowText[int index] = { read=_GetWindowText }; __property HWND Handles[int index] = { read=GetHandle }; __property int Count = { read=GetCount }; }; class CFindEnumWindow { private: TList *List; char *sClassName; bool bClassNameSubString; char *sTitle; bool bTitleSubString; char Buffer[1024]; private: static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lParam) { CFindEnumWindow *This = (CFindEnumWindow *)lParam; char *text = This->Buffer; if (This->sClassName != NULL) { if (GetClassName(hwnd, text, 1023)) { if ((!This->bClassNameSubString && !strcmp(text, This->sClassName)) || (This->bClassNameSubString && strstr(text, This->sClassName))) { if (This->sTitle != NULL) { text[0] = 0; GetWindowText(hwnd, text, 1023); if ((!This->bTitleSubString && !strcmp(text, This->sTitle)) || (This->bTitleSubString && strstr(text, This->sTitle))) { This->List->Add(hwnd); } } else This->List->Add(hwnd); } } } else { if (This->sTitle != NULL) { text[0] = 0; GetWindowText(hwnd, text, 1023); if ((!This->bTitleSubString && !strcmp(text, This->sTitle)) || (This->bTitleSubString && strstr(text, This->sTitle))) { This->List->Add(hwnd); } } } return TRUE; } int GetCount() { return List->Count; } HWND GetHandle(int index) { if (index >= List->Count || List->Count <= 0) return NULL; return List->Items[index]; } String _GetClassName(int index) { if (index >= List->Count || List->Count <= 0) return NULL; char *text = Buffer; GetClassName(Handles[index], text, 1023); return text; } String _GetWindowText(int index) { if (index >= List->Count || List->Count <= 0) return NULL; char *text = Buffer; GetWindowText(Handles[index], text, 1023); return text; } public: CFindEnumChildWindow Child; public: CFindEnumWindow() { List = new TList; } ~CFindEnumWindow() { delete List; } bool Scan(char *class_name, char *title, bool class_substring = true, bool title_substring = true) { List->Clear(); sClassName = class_name; sTitle = title; bClassNameSubString = class_substring; bTitleSubString = title_substring; return EnumWindows((FARPROC)EnumWndProc, (long)this); } // ãÀº µ¥ÀÌŸ Çڵ鸵. // __property String ClassName[int index] = { read=_GetClassName }; __property String WindowText[int index] = { read=_GetWindowText }; __property HWND Handles[int index] = { read=GetHandle }; __property int Count = { read=GetCount }; }; #endif