void CAxControl::OnShowWindow(BOOL bShowing, int nReason) { if(bShowing == TRUE) { if(m_time == 0) if(m_url != L"") { CComVariant var; m_time = 1; m_pCore->m_pWebBrowser2->Navigate((BSTR)m_url.c_str(), &var, &var, &var, &var); } LONG style = ::GetWindowLongW(m_hWnd, GWL_STYLE); if((style & WS_VISIBLE) == WS_VISIBLE) { HWND TChild, MChild, BChild; TChild = FindWindowExW(m_hWnd , NULL, L"Shell Embedding", NULL); if(TChild != NULL) { MChild = FindWindowExW(TChild, NULL, L"Shell DocObject View", NULL); if(MChild != NULL) { BChild = FindWindowExW(MChild, NULL, L"Internet Explorer_Server", NULL); if(BChild != NULL) { ::SetFocus(BChild); } } } } } }
/* * @implemented */ HWND WINAPI FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow) { LPWSTR titleW = NULL; HWND hwnd = 0; if (lpszWindow) { DWORD len = MultiByteToWideChar( CP_ACP, 0, lpszWindow, -1, NULL, 0 ); if (!(titleW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return 0; MultiByteToWideChar( CP_ACP, 0, lpszWindow, -1, titleW, len ); } if (!IS_INTRESOURCE(lpszClass)) { WCHAR classW[256]; if (MultiByteToWideChar( CP_ACP, 0, lpszClass, -1, classW, sizeof(classW)/sizeof(WCHAR) )) hwnd = FindWindowExW( hwndParent, hwndChildAfter, classW, titleW ); } else { hwnd = FindWindowExW( hwndParent, hwndChildAfter, (LPCWSTR)lpszClass, titleW ); } HeapFree( GetProcessHeap(), 0, titleW ); return hwnd; }
void WINAPI refresh_tray(void) { HWND hwnd ; /* tray hwnd */ RECT m_trayToolBar; int x; hwnd = FindWindowW(L"Shell_TrayWnd", NULL); hwnd = FindWindowExW(hwnd, 0, L"TrayNotifyWnd", NULL); hwnd = FindWindowExW(hwnd, 0, L"SysPager", NULL); hwnd = FindWindowExW(hwnd, 0, L"ToolbarWindow32", NULL); GetClientRect(hwnd, &m_trayToolBar); for(x = 1; x < m_trayToolBar.right - 1; x++) { int y = m_trayToolBar.bottom / 2; PostMessage(hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y)); } }
static BOOL winpidgin_set_running(BOOL fail_if_running) { HANDLE h; if ((h = CreateMutexW(NULL, FALSE, L"pidgin_is_running"))) { DWORD err = GetLastError(); if (err == ERROR_ALREADY_EXISTS) { if (fail_if_running) { HWND msg_win; printf("An instance of Pidgin is already running.\n"); if((msg_win = FindWindowExW(NULL, NULL, L"WinpidginMsgWinCls", NULL))) if(SendMessage(msg_win, PIDGIN_WM_FOCUS_REQUEST, (WPARAM) NULL, (LPARAM) NULL)) return FALSE; /* If we get here, the focus request wasn't successful */ MessageBoxW(NULL, L"An instance of Pidgin is already running", NULL, MB_OK | MB_TOPMOST); return FALSE; } } else if (err != ERROR_SUCCESS) printf("Error (%u) accessing \"pidgin_is_running\" mutex.\n", (UINT) err); } return TRUE; }
BOOL init_bosskey(LPWNDINFO pInfo) { WCHAR win_titiles[BUFSIZE+1]; while ( !pInfo->hFF ) /* 等待主窗口并获取句柄 */ { HWND hwnd_pre = FindWindowExW( NULL, NULL, L"MozillaWindowClass", NULL ); while (NULL != hwnd_pre) { int n = GetWindowTextW(hwnd_pre, win_titiles, BUFSIZE); if ( n>0 && n < BUFSIZE) { win_titiles[n] = L'\0'; if ( stristrW(win_titiles, L"- Mozilla Thunderbird") ) { /* 获取thunderbird窗体句柄 */ pInfo->hFF = is_thunderbird()?hwnd_pre:NULL; } else { /* 获取firefox窗体句柄 */ pInfo->hFF = is_browser()?hwnd_pre:NULL; } } if (pInfo->hFF) { break; } hwnd_pre = FindWindowExW(NULL, hwnd_pre, L"MozillaWindowClass", NULL); } Sleep(800); } if ( pInfo->hFF ) { WCHAR atom_str[VALUE_LEN+1] = {0}; GetModuleFileNameW(NULL,atom_str,VALUE_LEN); GetWindowThreadProcessId(pInfo->hFF, &pInfo->pFF); pInfo->atom_str = GlobalAddAtomW(atom_str)-0xC000; } return RegisterHotKey(NULL, pInfo->atom_str, pInfo->key_mod, pInfo->key_vk); }
void ScriptFindWindow(ScriptValue &s, ScriptValue *args) { wchar_t *p1 = 0, *p2 = 0; if (args[0].stringVal->len) { p1 = UTF8toUTF16Alloc(args[0].stringVal->value); } if (args[1].stringVal->len) { p2 = UTF8toUTF16Alloc(args[1].stringVal->value); } __int64 res = (__int64)FindWindowExW((HWND)args[2].intVal, (HWND)args[3].intVal, p1, p2); if (res) { CreateIntValue(s, res); } if (p1) free(p1); if (p2) free(p2); }
extern "C" __declspec(dllexport) LRESULT CALLBACK RedrawProc(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode >= HC_ACTION) { auto msg = reinterpret_cast<CWPSTRUCT*>(lParam); if ((msg->message == WM_WINDOWPOSCHANGING || msg->message == WM_WINDOWPOSCHANGED || msg->message == WM_NCPAINT)) { auto hWnd = FindWindowW(L"Shell_SecondaryTrayWnd", nullptr); hWnd = FindWindowExW(hWnd, nullptr, L"WorkerW", nullptr); if (msg->hwnd == hWnd) { SetWindowPos(hWnd, nullptr, 0, 0, 0, 0, 1); } } } return CallNextHookEx(nullptr, nCode, wParam, lParam); }
static void hugsprim_FindWindowExW_26(HugsStackPtr hugs_root) { HsPtr arg1; HsPtr arg2; HsPtr arg3; HsPtr arg4; HsPtr res1; arg1 = hugs->getPtr(); arg2 = hugs->getPtr(); arg3 = hugs->getPtr(); arg4 = hugs->getPtr(); res1 = FindWindowExW(arg1, arg2, arg3, arg4); hugs->putPtr(res1); hugs->returnIO(hugs_root,1); }
/* * @implemented */ HWND WINAPI FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName) { /* There was a FIXME here earlier, but I think it is just a documentation unclarity. FindWindow only searches top level windows. What they mean is that child windows of other windows than the desktop can be searched. FindWindowExW never does a recursive search. / Joakim */ return FindWindowExW(NULL, NULL, lpClassName, lpWindowName); }
HWND UserImp::findWindowEx(HWND hwndParent, HWND hwndChildAfter, LPCTSTR lpszClass, LPCTSTR lpszWindow) { if (!bUserLoaded && !loadExports(bAllowLoadLibrary)) { _ASSERTEX(hUser32!=NULL); return NULL; } HWND hRc = FindWindowExW(hwndParent, hwndChildAfter, lpszClass, lpszWindow); /* if (findWindowEx_f) { hRc = findWindowEx_f(hwndParent, hwndChildAfter, lpszClass, lpszWindow); } else { _ASSERTEX(findWindowEx_f!=NULL); } */ return hRc; }
HWND PkyWindowSearch::FindMessageWindowClass( HWND wnd, const wchar_t* pszWndClass ) { return FindWindowExW( HWND_MESSAGE, wnd, pszWndClass, nullptr ); }
HWND PkyWindowSearch::FindMessageWindow( HWND wnd, const wchar_t* pszWndClass, const wchar_t* pszWndText ) { return FindWindowExW( HWND_MESSAGE, wnd, pszWndClass, pszWndText ); }
static void handle_protocol(wchar_t *cmd) { char *remote_msg, *utf8msg; wchar_t *tmp1, *tmp2; int len, wlen; SIZE_T len_written; HWND msg_win; DWORD pid; HANDLE process; /* The start of the message */ tmp1 = cmd + wcslen(PROTO_HANDLER_SWITCH); /* The end of the message */ if ((tmp2 = wcschr(tmp1, L' '))) wlen = (tmp2 - tmp1); else wlen = wcslen(tmp1); if (wlen == 0) { printf("No protocol message specified.\n"); return; } if (!(msg_win = FindWindowExW(NULL, NULL, L"WinpidginMsgWinCls", NULL))) { printf("Unable to find an instance of Pidgin to handle protocol message.\n"); return; } len = WideCharToMultiByte(CP_UTF8, 0, tmp1, wlen, NULL, 0, NULL, NULL); if (len) { utf8msg = malloc(len * sizeof(char)); len = WideCharToMultiByte(CP_UTF8, 0, tmp1, wlen, utf8msg, len, NULL, NULL); } if (len == 0) { printf("No protocol message specified.\n"); return; } GetWindowThreadProcessId(msg_win, &pid); if (!(process = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, pid))) { DWORD dw = GetLastError(); const wchar_t *err_msg = get_win32_error_message(dw); wprintf(L"Unable to open Pidgin process. (%u) %s\n", (UINT) dw, err_msg); return; } wprintf(L"Trying to handle protocol message:\n'%.*s'\n", wlen, tmp1); /* MEM_COMMIT initializes the memory to zero * so we don't need to worry that our section of utf8msg isn't nul-terminated */ if ((remote_msg = (char*) VirtualAllocEx(process, NULL, len + 1, MEM_COMMIT, PAGE_READWRITE))) { if (WriteProcessMemory(process, remote_msg, utf8msg, len, &len_written)) { if (!SendMessageA(msg_win, PIDGIN_WM_PROTOCOL_HANDLE, len_written, (LPARAM) remote_msg)) printf("Unable to send protocol message to Pidgin instance.\n"); } else { DWORD dw = GetLastError(); const wchar_t *err_msg = get_win32_error_message(dw); wprintf(L"Unable to write to remote memory. (%u) %s\n", (UINT) dw, err_msg); } VirtualFreeEx(process, remote_msg, 0, MEM_RELEASE); } else { DWORD dw = GetLastError(); const wchar_t *err_msg = get_win32_error_message(dw); wprintf(L"Unable to allocate remote memory. (%u) %s\n", (UINT) dw, err_msg); } CloseHandle(process); free(utf8msg); }
/************************************************************************* * Shell_NotifyIconW [SHELL32.298] */ BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW nid) { HWND tray; COPYDATASTRUCT cds; struct notify_data data_buffer; struct notify_data *data = &data_buffer; BOOL ret; TRACE("dwMessage = %d, nid->cbSize=%d\n", dwMessage, nid->cbSize); /* Validate the cbSize so that WM_COPYDATA doesn't crash the application */ if (nid->cbSize != NOTIFYICONDATAW_V1_SIZE && nid->cbSize != NOTIFYICONDATAW_V2_SIZE && nid->cbSize != NOTIFYICONDATAW_V3_SIZE && nid->cbSize != sizeof(NOTIFYICONDATAW)) { NOTIFYICONDATAW newNid; WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n", nid->cbSize, NOTIFYICONDATAW_V1_SIZE); CopyMemory(&newNid, nid, NOTIFYICONDATAW_V1_SIZE); newNid.cbSize = NOTIFYICONDATAW_V1_SIZE; return Shell_NotifyIconW(dwMessage, &newNid); } tray = FindWindowExW(0, NULL, classname, NULL); if (!tray) return FALSE; cds.dwData = dwMessage; cds.cbData = sizeof(*data); memset( data, 0, sizeof(*data) ); /* FIXME: if statement only needed because we don't support interprocess * icon handles */ if (nid->uFlags & NIF_ICON) { ICONINFO iconinfo; BITMAP bmMask; BITMAP bmColour; LONG cbMaskBits; LONG cbColourBits = 0; char *buffer; if (!GetIconInfo(nid->hIcon, &iconinfo)) goto noicon; if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) || (iconinfo.hbmColor && !GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour))) { DeleteObject(iconinfo.hbmMask); if (iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor); goto noicon; } cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel + 15) / 16 * 2; if (iconinfo.hbmColor) cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel + 15) / 16 * 2; cds.cbData = sizeof(*data) + cbMaskBits + cbColourBits; buffer = HeapAlloc(GetProcessHeap(), 0, cds.cbData); if (!buffer) { DeleteObject(iconinfo.hbmMask); if (iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor); return FALSE; } data = (struct notify_data *)buffer; memset( data, 0, sizeof(*data) ); buffer += sizeof(*data); GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer); if (!iconinfo.hbmColor) { data->width = bmMask.bmWidth; data->height = bmMask.bmHeight / 2; data->planes = 1; data->bpp = 1; } else { data->width = bmColour.bmWidth; data->height = bmColour.bmHeight; data->planes = bmColour.bmPlanes; data->bpp = bmColour.bmBitsPixel; buffer += cbMaskBits; GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer); DeleteObject(iconinfo.hbmColor); } DeleteObject(iconinfo.hbmMask); } noicon: data->hWnd = HandleToLong( nid->hWnd ); data->uID = nid->uID; data->uFlags = nid->uFlags; if (data->uFlags & NIF_MESSAGE) data->uCallbackMessage = nid->uCallbackMessage; if (data->uFlags & NIF_TIP) lstrcpynW( data->szTip, nid->szTip, sizeof(data->szTip)/sizeof(WCHAR) ); if (data->uFlags & NIF_STATE) { data->dwState = nid->dwState; data->dwStateMask = nid->dwStateMask; } if (data->uFlags & NIF_INFO) { lstrcpynW( data->szInfo, nid->szInfo, sizeof(data->szInfo)/sizeof(WCHAR) ); lstrcpynW( data->szInfoTitle, nid->szInfoTitle, sizeof(data->szInfoTitle)/sizeof(WCHAR) ); data->u.uTimeout = nid->u.uTimeout; data->dwInfoFlags = nid->dwInfoFlags; } if (data->uFlags & NIF_GUID) data->guidItem = nid->guidItem; if (dwMessage == NIM_SETVERSION) data->u.uVersion = nid->u.uVersion; /* FIXME: balloon icon */ cds.lpData = data; ret = SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds); if (data != &data_buffer) HeapFree( GetProcessHeap(), 0, data ); return ret; }