oodControl_t control2controlType(HWND hControl) { oodControl_t type = winUnknown; TCHAR buf[64]; if ( RealGetWindowClass(hControl, buf, RXITEMCOUNT(buf)) ) { type = winName2controlType(buf); if ( type == winPushButton ) { BUTTONTYPE buttonType = getButtonInfo(hControl, NULL, NULL); if ( buttonType == check ) { type = winCheckBox; } else if ( buttonType == radio ) { type = winRadioButton; } else if ( buttonType == group ) { type = winGroupBox; } } } return type; }
void GetWindowInformation() { TCHAR buf[256]; GetCursorPos (&g_ptMouse); memset(&g_WinInfo, 0, sizeof(g_WinInfo)); g_WinInfo.hwnd = WindowFromPoint(g_ptMouse); RealGetWindowClass(g_WinInfo.hwnd , g_WinInfo.szWindowClass, sizeof(g_WinInfo.szWindowClass)); GetWindowInfo(g_WinInfo.hwnd , &g_WinInfo.wi ); int id = GetDlgCtrlID(g_WinInfo.hwnd ); HWND hwndEdit = GetDlgItem(g_hWndMain,ID_EDITCHILD); _stprintf_s(buf, _T("「WindowClass」=%s 「CtrlID」=0x%p 「Location」=%d,%d"), g_WinInfo.szWindowClass, id, g_WinInfo.wi.rcWindow.right - g_WinInfo.wi.rcWindow.left , g_WinInfo.wi.rcWindow.bottom - g_WinInfo.wi.rcWindow.top); // Add text to the window. //SendMessage(hwndEdit, WM_SETTEXT, 0, (LPARAM) buf); InvalidateRect(g_hWndMain,NULL,FALSE); }
void AttachWindowProc(HWND hWnd) { if (hWnd == NULL || s_hUiInputWnd != NULL) return; TCHAR szBuffer[MAX_PATH]; RealGetWindowClass(hWnd, szBuffer, MAX_PATH); TheLogger.Debug(L"Window class: %s", szBuffer); if (_wcsicmp(szBuffer, INPUTUI_CLASS_NAME) == 0) { s_hUiInputWnd = hWnd; s_pPreUiInputWindowProc = (WNDPROC)::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)UiInputWindowProc); } }
static void ShowWindowInfo(HWND hWnd) { if (hWnd == NULL || !::IsWindow(hWnd)) return; TCHAR szBuffer[MAX_PATH]; RealGetWindowClass(hWnd, szBuffer, MAX_PATH); TheLogger.Debug(L"Window class: %s", szBuffer); GetWindowText(hWnd, szBuffer, MAX_PATH); TheLogger.Debug(L"Window text: %s", szBuffer); RECT rect; GetWindowRect(hWnd, &rect); TheLogger.Debug(L"Window rect. : hWnd=%x, left=%d, top=%d, right=%d, bottom=%d", hWnd, rect.left, rect.top, rect.right, rect.bottom); }
BOOL WINAPI FindExcelWindowCallback(HWND hwnd, LPARAM lParam) { FindExcelWindowParam* pParam = (FindExcelWindowParam*)lParam; DWORD processId = 0; GetWindowThreadProcessId(hwnd, &processId); if (processId == pParam->processId) { wchar_t className[11]; DWORD count = RealGetWindowClass(hwnd, className, 10); if (_tcsncmp(className, L"XLMAIN", 6)) { pParam->hwndFound = hwnd; SetLastError(0); return FALSE; } } return TRUE; }
BOOL WINAPI FindExcelWindowCallback(HWND hwnd, LPARAM lParam) { FindExcelWindowParam* pParam = (FindExcelWindowParam*)lParam; DWORD processId = 0; GetWindowThreadProcessId(hwnd, &processId); if (processId == pParam->processId) { CString className; LPTSTR pBuffer = className.GetBuffer(10); DWORD count = RealGetWindowClass(hwnd, pBuffer, 10); className.ReleaseBuffer(count); if (className == L"XLMAIN") { pParam->hwndFound = hwnd; SetLastError(0); return FALSE; } } return TRUE; }
void TfrmMain::SetTargetWindow(HWND hwnd) { if(!hwnd) { POINT point; GetCursorPos(&point); hwnd=WindowFromPoint(point); // if(!((GetAsyncKeyState(VK_SHIFT)|GetAsyncKeyState(VK_MENU))&0x8000)) for(HWND hTMP; (hTMP=GetParent(hwnd)); hwnd=hTMP); } m_hTargetWindow=hwnd; int len=GetWindowTextLength(m_hTargetWindow)+1; LPTSTR lpTitle; if(len>1) { lpTitle=(LPTSTR)mir_alloc(len*sizeof(TCHAR)); GetWindowText(m_hTargetWindow,lpTitle,len); } else { //no WindowText present, use WindowClass lpTitle=(LPTSTR)mir_alloc(64*sizeof(TCHAR)); RealGetWindowClass(m_hTargetWindow,lpTitle,64); } SetDlgItemText(m_hwndTabPage,ID_edtCaption,lpTitle); mir_free(lpTitle); edtSizeUpdate(m_hTargetWindow,m_opt_chkClientArea,m_hwndTabPage,ID_edtSize); }
/** * Determine if a dialog control belongs to the specified dialog control class. * * @param hControl Handle to the control. * @param control One of the oodControl types specifying the class to check * for. * * @return True if the dialog control is the type specified, otherwise false. */ bool isControlMatch(HWND hControl, oodControl_t control) { rxcharT buf[64]; const rxcharT *pClass = controlType2winName(control); if ( ! RealGetWindowClass(hControl, buf, RXITEMCOUNT(buf)) || _tcscmp(buf, pClass) != 0 ) { return false; } if ( control == winCheckBox || control == winRadioButton || control == winGroupBox ) { BUTTONTYPE type = getButtonInfo(hControl, NULL, NULL); switch ( control ) { case winCheckBox : if ( type != check ) { return false; } break; case winRadioButton : if ( type != radio ) { return false; } break; case winGroupBox : if ( type != group ) { return false; } break; } } return true; }
BOOL CALLBACK Notify::windowEnumerator(HWND hwnd, LPARAM lParam) { WindowInformation* info = reinterpret_cast<WindowInformation*>(lParam); DWORD processId; char windowClass[256]; RealGetWindowClass(hwnd, windowClass, sizeof(windowClass)); char windowName[256]; if (!GetWindowText(hwnd, windowName, sizeof(windowName))) { return TRUE; } GetWindowThreadProcessId(hwnd, &processId); if (processId == info->m_pid) { info->m_result = hwnd; return FALSE; } return TRUE; }
IWindow::IWindow(HWND hWnd) { DWORD dwError = 0; this->hWnd = hWnd; if(hWnd == 0) { hWndRoot = 0; hWndParent = 0; wndText = new TCHAR[1]; wndText[0] = _T('\0'); wndInfo = WINDOWINFO(); // _tprintf(_T("wndInfo.cbSize = %i\n"), wndInfo.cbSize); // _tprintf(_T("wndInfo.dwStyle = %i\n"), wndInfo.dwStyle); wndWidth = 0; wndHeight = 0; wndPos = POINT(); wndID = 0; className = new TCHAR[1]; className[0] = _T('\0'); realClassName = new TCHAR[1]; realClassName[0] = _T('\0'); dwThreadID = 0; dwProcessID = 0; hWndDC = NULL; hBufferDC = NULL; hWndBitmap = NULL; hWndBitmap = NULL; return; } hWndRoot = GetAncestor(hWnd, GA_ROOT); hWndParent = GetAncestor(hWnd, GA_PARENT); // _tprintf(_T("hWndRoot = 0x%08X\n"), hWndRoot); // _tprintf(_T("hWndParent = 0x%X\n"), hWndParent); int strLen = (int)SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1; // _tprintf(_T("dwBuffSize = %i\n"), dwBuffSize); wndText = new TCHAR[strLen]; SendMessage(hWnd, WM_GETTEXT, strLen, (LPARAM)wndText); wndInfo.cbSize = sizeof(WINDOWINFO); GetWindowInfo(hWnd, &wndInfo); GetWindowRect(hWnd, &wndRect); wndWidth = wndRect.right - wndRect.left; wndHeight = wndRect.bottom - wndRect.top; if(hWndRoot == hWnd) { wndPos.x = wndRect.left; wndPos.y = wndRect.top; } else { WINDOWINFO rootWndInfo = {sizeof(WINDOWINFO)}; GetWindowInfo(hWndRoot, &rootWndInfo); wndPos.x = wndRect.left - rootWndInfo.rcClient.left; wndPos.y = wndRect.top - rootWndInfo.rcClient.top; } wndID = GetWindowLong(hWnd, GWL_ID); className = new TCHAR[MAX_WND_CLASSNAME + 1]; if(!GetClassName(hWnd, className, MAX_WND_CLASSNAME + 1)) { dwError = GetLastError(); _tprintf(_T("GetClassName: dwError = %i \n"), dwError); className[0] = _T('\0'); } realClassName = new TCHAR[MAX_WND_CLASSNAME + 1]; if(!RealGetWindowClass(hWnd, realClassName, MAX_WND_CLASSNAME + 1)) { dwError = GetLastError(); _tprintf(_T("RealGetWindowClass: dwError = %i \n"), dwError); realClassName[0] = _T('\0'); } // _tprintf(_T("realClassNameLen = %i\n"), realClassNameLen); // _tprintf(_T("RealGetWindowClass: realClassName = 0x%X\n"), realClassName); dwThreadID = GetWindowThreadProcessId(hWnd, &dwProcessID); }
void Test_RealGetWindowClass() { int testNo; UINT Result; CHAR Buffer[1024]; Result = RealGetWindowClass( NULL, Buffer, ARRAY_SIZE(Buffer) ); ok(Result == 0, "Result = %d\n", Result); ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "GetLastError() = %ld\n", GetLastError()); for (testNo = 0; testNo < ARRAY_SIZE(RealClassTestData); testNo++) { ATOM atom; WNDCLASSA cls; HWND hWnd; /* Register classes, "derived" from built-in dialog, with and without the DLGWINDOWEXTRA flag set */ GetClassInfoA(0, "#32770", &cls); if (RealClassTestData[testNo].OverrideWndProc) cls.lpfnWndProc = DefWindowProcA; cls.lpszClassName = RealClassTestData[testNo].ClassName; cls.cbWndExtra &= ~RealClassTestData[testNo].WndExtra; atom = RegisterClassA (&cls); if (atom == 0) return; /* Create a window */ hWnd = CreateWindowEx( WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT | WS_EX_APPWINDOW, RealClassTestData[testNo].ClassName, RealClassTestData[testNo].ClassName, WS_POPUPWINDOW | WS_CLIPSIBLINGS | WS_DLGFRAME | WS_OVERLAPPED | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | DS_3DLOOK | DS_SETFONT | DS_MODALFRAME, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, 0, 0); /* Do we expect a HWND at all? */ if (RealClassTestData[testNo].ExpectsHwnd) { ok(hWnd != NULL, "\n"); if (hWnd != NULL) { /* Get the "real" class name */ Result = RealGetWindowClass( hWnd, Buffer, ARRAY_SIZE(Buffer) ); printf("Buffer: %s\nExpectedClassNameBefore(%d): %s\n", Buffer, testNo, RealClassTestData[testNo].ExpectedClassNameBefore); ok( Result != 0, "\n" ); ok( strcmp( Buffer, RealClassTestData[testNo].ExpectedClassNameBefore ) == 0, "\n" ); /* Call a function that requires a dialog window */ DefDlgProcA( hWnd, DM_SETDEFID, IDCANCEL, 0 ); /* Get the "real" class name again */ Result = RealGetWindowClass( hWnd, Buffer, ARRAY_SIZE(Buffer) ); printf("Buffer: %s\nExpectedClassNameAfter(%d): %s\n", Buffer, testNo, RealClassTestData[testNo].ExpectedClassNameAfter); ok( Result != 0, "\n" ); ok( strcmp( Buffer, RealClassTestData[testNo].ExpectedClassNameAfter ) == 0, "\n" ); } } else { ok(hWnd == NULL, "\n"); } /* Cleanup */ DestroyWindow(hWnd); UnregisterClass(RealClassTestData[testNo].ClassName, 0); } }