How to get the handles of all the windows opened in wince?
-
I want to retrieve handles for all the windows opened in wince machine. Using my application i need to retrieve the handle for the windows that has been opened in desktop and list the title of those windows in a list view . Thanks in Advance.
-
I want to retrieve handles for all the windows opened in wince machine. Using my application i need to retrieve the handle for the windows that has been opened in desktop and list the title of those windows in a list view . Thanks in Advance.
have a look into [EnumWindows^] and [GetWindowText^] and search CP for ListView
-
have a look into [EnumWindows^] and [GetWindowText^] and search CP for ListView
I have tried with the folowing code snippet.Still i am not able to retrieve the handle for the window. WNDENUMPROC lpEnumFunc = &EnumWindowsProc; TCHAR szName[50]; HWND hTempWnd = NULL; lpEnumFunc(hTempWnd,lParam); if(EnumWindows(lpEnumFunc ,LPARAM(hWnd))) MessageBox(hWnd,L"EnumWindows Successful",NULL,0); lpEnumFunc(hTempWnd,lParam); GetWindowText(hTempWnd,szName,50); MessageBox(hTempWnd,szName,szName,0);
-
I have tried with the folowing code snippet.Still i am not able to retrieve the handle for the window. WNDENUMPROC lpEnumFunc = &EnumWindowsProc; TCHAR szName[50]; HWND hTempWnd = NULL; lpEnumFunc(hTempWnd,lParam); if(EnumWindows(lpEnumFunc ,LPARAM(hWnd))) MessageBox(hWnd,L"EnumWindows Successful",NULL,0); lpEnumFunc(hTempWnd,lParam); GetWindowText(hTempWnd,szName,50); MessageBox(hTempWnd,szName,szName,0);
Well, well try, If that API was supposed to work as per your understanding there are possible risks being caught in an infinite loop or referencing a destroyed window handle. Call Back functions of an Windows API are not that supposed to be called by you.
struct MYLISTVIEW
{
};BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
#define MAX_TEXT_LEN 256
MYLISTVIEW *plvData = (MYLISTVIEW *)lParam;
if (plvData)
{
TCHAR szWndText[MAX_TEXT_LEN] = _T("");LONG lStyle = GetWindowLong(hwnd, GWL\_STYLE); LONG lExStyle = GetWindowLong(hwnd, GWL\_EXSTYLE); // filter the window handles depending on your need if (IsWindowVisible(hwnd) && !GetParent(hwnd) && hwnd != GetDesktopWindow() && ( /\*lExStyle & WS\_EX\_APPWINDOW || \*/ !(lExStyle & WS\_EX\_NOACTIVATE || lExStyle & WS\_EX\_TOOLWINDOW))) { RECT rc = {0}; GetWindowRect(hwnd, &rc); if (rc.bottom - rc.top && rc.right - rc.left) { GetWindowText(hwnd, szWndText, MAX\_TEXT\_LEN); // add the text to your view AddWndTextToListView(plvData, szWndText); } } } return TRUE;
}
MYLISTVIEW g_lvData;
void AddOpenedWindowsToListView()
{
EnumWindows(EnumWindowsProc, (LPARAM)&g_lvData);
}