void TinyDropTarget::handle_task_timer(void) { KillTimer(m_hwnd, TASK_RISE_TIMER); if (NULL == task_over) return; if (task_over == GetTask(GetActiveTask())) return; DWORD ThreadID1 = GetWindowThreadProcessId(GetForegroundWindow(), NULL); DWORD ThreadID2 = GetCurrentThreadId(); if (ThreadID1 != ThreadID2) { AttachThreadInput(ThreadID1, ThreadID2, TRUE); SetForegroundWindow(m_hwnd); AttachThreadInput(ThreadID1, ThreadID2, FALSE); } PostMessage(GetBBWnd(), BB_BRINGTOFRONT, 0, (LPARAM)task_over); }
BOOL CALLBACK EnumWindowsProc( HWND hwnd, LONG lParam ) { DWORD pid = 0; DWORD i; CHAR buf[TITLE_SIZE]; PTASK_LIST_ENUM te = (PTASK_LIST_ENUM)lParam; PTASK_LIST tlist = te->tlist; DWORD numTasks = te->numtasks; // // get the processid for this window // if (!GetWindowThreadProcessId( hwnd, &pid )) { return TRUE; } // // look for the task in the task list for this window // for (i=0; i<numTasks; i++) { if (tlist[i].dwProcessId == pid) { tlist[i].hwnd = hwnd; // // we found the task so lets try to get the // window text // if (GetWindowText( tlist[i].hwnd, buf, zsizeof(buf) )) { // // got it, so lets save it // strcpy( (LPSTR)tlist[i].WindowTitle, buf ); } break; } } // // continue the enumeration // return TRUE; }
void CALLBACK TimerFunc(HWND hWnd,UINT nMsg,UINT_PTR nTimerid,DWORD dwTime) { (void) hWnd; (void) nMsg; (void) dwTime; DWORD wso; wso = WaitForSingleObject(hSynhroMutex, 0); if (wso == WAIT_OBJECT_0 || wso == WAIT_ABANDONED) { KillTimer(0, nTimerid); TimerID = 0; while( 1 ) { POINT curPt; HWND targetWnd; DWORD winProcessID = 0; if( !GetCursorPos( &curPt ) ) break; if( GlobalData == NULL || GlobalData->LastPt.x != curPt.x || GlobalData->LastPt.y != curPt.y) break; if( ( targetWnd = GetWindowFromPoint( curPt ) ) == NULL ) break; if( GlobalData->LastWND != targetWnd ) break; GetWindowThreadProcessId( targetWnd, &winProcessID ); if( winProcessID != ourProcessID ) { char className[64]; if( !GetClassName( targetWnd, className, sizeof(className) ) ) break; if( lstrcmpi( className, "ConsoleWindowClass" ) != 0 ) break; } SendWordToServer(); break; } ReleaseMutex(hSynhroMutex); } }
void resizeWindow(HWND hWnd, int width, int height) { RECT rClient; GetClientRect(hWnd, &rClient); if (width == rClient.right - rClient.left && height == rClient.bottom - rClient.top) { return; } RECT rWindow; GetWindowRect(hWnd, &rWindow); width += (rWindow.right - rWindow.left) - rClient.right; height += (rWindow.bottom - rWindow.top) - rClient.bottom; // SetWindowPos will hang if this ever happens. assert(GetCurrentThreadId() == GetWindowThreadProcessId(hWnd, NULL)); SetWindowPos(hWnd, NULL, rWindow.left, rWindow.top, width, height, SWP_NOMOVE); }
static BOOL CALLBACK GetConsoleWindowProc(HWND hWnd, LPARAM lParam) { const char cConsoleClassName[] = "ConsoleWindowClass"; DWORD dwPid = (DWORD)-1; char cBuf[sizeof(cConsoleClassName)] = ""; GetWindowThreadProcessId(hWnd, &dwPid); if (dwPid != GetCurrentProcessId()) return TRUE; if (GetClassName(hWnd, cBuf, sizeof cBuf) != sizeof(cConsoleClassName)-1) return TRUE; if (strcmp(cConsoleClassName, cBuf) != 0) return TRUE; *(HWND*)lParam = hWnd; return FALSE; }
FB::VariantList btlauncherAPI::stopRunning(const std::wstring& val) { FB::VariantList list; if (wcsstr(val.c_str(), _T(BT_HEXCODE)) || wcsstr(val.c_str(), _T(BTLIVE_CODE))) { HWND hWnd = FindWindow( val.c_str(), NULL ); DWORD pid; DWORD parent; parent = GetWindowThreadProcessId(hWnd, &pid); HANDLE pHandle = OpenProcess(PROCESS_TERMINATE, NULL, pid); if (! pHandle) { list.push_back("could not open process"); list.push_back(GetLastError()); } else { BOOL result = TerminateProcess(pHandle, 0); list.push_back("ok"); list.push_back(result); } } return list; }
int WriteC3CMemory(uint32_t lpAddress, void *buf, int len) { if (hwnd) { DWORD pid; GetWindowThreadProcessId(hwnd, &pid); HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); SIZE_T wlen; WriteProcessMemory(hProc, (void *) lpAddress, buf, len, &wlen); CloseHandle(hProc); if (len == wlen) { return TRUE; } else { fprintf(stderr, "Memory write error\n"); return FALSE; } } else { return FALSE; } }
BOOL CALLBACK close_alert_window_enum( HWND hwnd, LPARAM lParam ) { char buf[ 7 ] = { 0 }; PROCESS_HANDLE_ID p = *( (PROCESS_HANDLE_ID *)lParam ); DWORD pid = 0; DWORD tid = 0; /* We want to find and close any window that: * 1. is visible and * 2. is a dialog and * 3. is displayed by any of our child processes */ if ( !IsWindowVisible( hwnd ) ) return TRUE; if ( !GetClassNameA( hwnd, buf, sizeof( buf ) ) ) return TRUE; /* Failed to read class name; presume it is not a dialog. */ if ( strcmp( buf, "#32770" ) ) return TRUE; /* Not a dialog */ /* GetWindowThreadProcessId() returns 0 on error, otherwise thread id of * window message pump thread. */ tid = GetWindowThreadProcessId( hwnd, &pid ); if ( tid && is_parent_child( p.pid, pid ) ) { /* Ask really nice. */ PostMessageA( hwnd, WM_CLOSE, 0, 0 ); /* Now wait and see if it worked. If not, insist. */ if ( WaitForSingleObject( p.h, 200 ) == WAIT_TIMEOUT ) { PostThreadMessageA( tid, WM_QUIT, 0, 0 ); WaitForSingleObject( p.h, 300 ); } /* Done, we do not want to check any other window now. */ return FALSE; } return TRUE; }
static BOOL CALLBACK EnumWindowsCallback(HWND windowHandle, LPARAM lParam) { DWORD pid; GetWindowThreadProcessId(windowHandle, &pid); if (pid == lParam) { // This window belongs to the process if (!windowTitle.empty()) return TRUE; TCHAR text[256]; GetWindowText(windowHandle, text, sizeof(text)); if ((GetWindowLong(windowHandle, GWL_STYLE) & WS_VISIBLE)) { windowTitle = text; return FALSE; } } return TRUE; }
void AttachGuiWindow(HWND hOurWindow) { _ASSERTEX(gbAttachGuiClient); // Уже должен был быть установлен? gnAttachMsgId = RegisterWindowMessageW(L"ConEmu:Attach2Gui"); if (gnAttachMsgId) { DWORD nWndTID = GetWindowThreadProcessId(hOurWindow, NULL); ghAttachMsgHook = SetWindowsHookExW(WH_CALLWNDPROC, AttachGuiWindowCallback, NULL, nWndTID); // Поскольку аттач хорошо бы выполнять в той нити, в которой крутится окно - то через хук AttachMsgArg args = {gnAttachMsgId, 0, ghConEmuWnd, hOurWindow}; LRESULT lRc = SendMessageW(hOurWindow, gnAttachMsgId, gnAttachMsgId, (LPARAM)&args); _ASSERTEX(args.Result == gnAttachMsgId); UNREFERENCED_PARAMETER(lRc); UnhookWindowsHookEx(ghAttachMsgHook); ghAttachMsgHook = NULL; } }
BOOL CALLBACK EnumFindProcessWnd(HWND hwnd, LPARAM lParam) { DWORD procid = 0; TCHAR WindowClass [40]; GetWindowThreadProcessId(hwnd, &procid); GetClassName(hwnd, WindowClass, countof(WindowClass)); if (procid == GetCurrentProcessId() && (_tcscmp(WindowClass, _l("MediaPlayerClassicW")) == 0 || // MPC-HC window _tcscmp(WindowClass, _l("WMPlayerApp")) == 0 || // WMPlayer window _tcscmp(WindowClass, _l("eHome Render Window")) == 0 // WMC window ) ) { HWND* pWnd = (HWND*) lParam; *pWnd = hwnd; return FALSE; } return TRUE; }
//! Entrypoint used to make another window become subclassed. bool BlueWindow::SubclassNewWindow(HWND hwnd) { DWORD windowpid; if (hwnd != NULL && IsWindow(hwnd) && GetWindowThreadProcessId(hwnd, &windowpid) && windowpid == GetCurrentProcessId() && OldWindowProcs.find(hwnd) == OldWindowProcs.end()) { // Found the window that is from our process. Subclass it. WNDPROC lpfnOldWindowProc = (WNDPROC) LongToPtr(GetWindowLongPtr(hwnd, GWL_WNDPROC)); OldWindowProcs.insert(std::make_pair<HWND, WNDPROC>(hwnd, lpfnOldWindowProc)); SetWindowLongPtr(hwnd, GWL_WNDPROC, PtrToLong(BlueWindow::SubclassProc)); ForceNonclientRepaint(hwnd); return true; } return false; // could not successfully subclass specified window. }
/* See if we were launched from a console window. */ bool check_console() { /* If we're running in a service context there will be no console window. */ HWND console = GetConsoleWindow(); if (! console) return false; unsigned long pid; if (! GetWindowThreadProcessId(console, &pid)) return false; /* If the process associated with the console window handle is the same as this process, we were not launched from an existing console. The user probably double-clicked our executable. */ if (GetCurrentProcessId() != pid) return true; /* We close our new console so that subsequent messages appear in a popup. */ FreeConsole(); return false; }
bool Input::Initialize() { bool debug = false; int i = 0; while (!Vars.bActive) { if (i >= 300) { MessageBox(0, "Failed to set hooks, exiting!", "D2Etal", 0); return false; } if (fpGetHwnd() && (MENU::ClientState() == ClientStateMenu || MENU::ClientState() == ClientStateInGame)) { if (!Vars.oldWNDPROC) Vars.oldWNDPROC = (WNDPROC)SetWindowLong(fpGetHwnd(), GWL_WNDPROC, (LONG)Input::WndProc); if (!Vars.oldWNDPROC) continue; DWORD _mainThread = GetWindowThreadProcessId(fpGetHwnd(), 0); if (_mainThread) { if (!Vars.hKeybHook) Vars.hKeybHook = SetWindowsHookEx(WH_KEYBOARD, Input::KeyPress, NULL, _mainThread); if (!Vars.hMouseHook) Vars.hMouseHook = SetWindowsHookEx(WH_MOUSE, Input::MouseMove, NULL, _mainThread); } } else continue; if (Vars.hKeybHook && Vars.hMouseHook) { Vars.bActive = TRUE; } if (debug && Vars.oldWNDPROC && Vars.hKeybHook && Vars.hMouseHook) { MessageBox(0, "All Hooks Set!", "D2Etal", 0); } Sleep(50); i++; } return true; }
BOOL LowLevelHook::Initialize(HWND hwndMain) { TRY_CATCH //Store our window's handle g_hwndVNCViewer = hwndMain; if (0 == g_Instances) { ++g_Instances; HINSTANCE hInstance = NULL ; g_fHookActive = TRUE; g_VncProcessID = 0 ; g_HookID = 0 ; g_fGlobalScrollLock = FALSE ; //Receive the HInstacne of this window //(required because LowLevel-Keyboard-Hook must be global, // and need the HMODULE parameter in SetWindowsHookEx) hInstance = (HINSTANCE)GetWindowLong(g_hwndVNCViewer,GWL_HINSTANCE); if (hInstance==NULL) { return FALSE; } //Store the ProcessID of the VNC window. //this will prevent the keyboard hook procedure to interfere //with keypressed in other processes' windows GetWindowThreadProcessId(g_hwndVNCViewer,&g_VncProcessID); //Try to set the hook procedure g_HookID = SetWindowsHookEx(WH_KEYBOARD_LL,VncLowLevelKbHookProc,hInstance,0); if (0 == g_HookID) { Log.WinError(_ERROR_,_T("Failed to SetWindowsHookEx ")); return FALSE ; } return TRUE; } ++g_Instances; return TRUE; CATCH_THROW() }
BOOL LowLevelHook::Initialize(HWND hwndMain) { HINSTANCE hInstance = NULL ; g_hwndVNCViewer = NULL ; g_fHookActive = GetScrollLockState() ; g_VncProcessID = 0 ; g_HookID = 0 ; g_fGlobalScrollLock = FALSE ; //Store our window's handle g_hwndVNCViewer = hwndMain; if (g_hwndVNCViewer==NULL) return FALSE; //Get the HInstacne of this window //(required because LowLevel-Keyboard-Hook must be global, // and need the HMODULE parameter in SetWindowsHookEx) hInstance = helper::SafeGetWindowInstance(g_hwndVNCViewer); if (hInstance==NULL) return FALSE; // //Store the ProcessID of the VNC window. //this will prevent the keyboard hook procedure to interfere //with keypressed in other processes' windows GetWindowThreadProcessId(g_hwndVNCViewer,&g_VncProcessID); //Try to set the hook procedure g_HookID = SetWindowsHookEx(WH_KEYBOARD_LL,VncLowLevelKbHookProc,hInstance,0); if (g_HookID==0) { DWORD dw = GetLastError(); //TODO: //Analyze why the error occured (might be because we're under Win98/95/ME?) return FALSE ; } return TRUE; }
void HookProc( POINT *ppt ) { HWND WND; TCHAR wClassName[64]; DWORD winProcessID; WND = GetWindowFromPoint( *ppt ); if(WND == NULL) return; if ( !GetClassName(WND, wClassName, sizeof(wClassName) / sizeof(TCHAR)) ) return; GetWindowThreadProcessId( WND, &winProcessID ); if( winProcessID != ourProcessID && lstrcmpi( wClassName, _T("ConsoleWindowClass") ) != 0 ) return; if(TimerID && ( GlobalData->LastPt.x != ppt->x || GlobalData->LastPt.y != ppt->y ) ) { KillTimer(0, TimerID); TimerID = 0; } const char* DisableClasses[] = { "gdkWindowChild", "gdkWindowTemp", "Progman", "WorkerW", }; int i; for (i=0; i<4; i++) { if (lstrcmp(wClassName, DisableClasses[i])==0) break; } if (i<4) return; if(GlobalData->LastPt.x != ppt->x || GlobalData->LastPt.y != ppt->y || GlobalData->LastWND != WND ) { GlobalData->LastWND = WND; GlobalData->LastPt = *ppt; TimerID = SetTimer(0, TimerID, MOUSEOVER_INTERVAL, TimerFunc); } }
static BOOL CALLBACK EnumWindowsProc(HWND Window, LPARAM Param) { const auto Info = reinterpret_cast<ProcInfo*>(Param); try { if (!is_alttab_window(Window)) return true; string WindowTitle; os::GetWindowText(Window, WindowTitle); DWORD ProcID; GetWindowThreadProcessId(Window, &ProcID); string MenuItem; if (Info->ShowImage) { if (const auto Process = os::handle(OpenProcess(imports.QueryFullProcessImageNameW? PROCESS_QUERY_LIMITED_INFORMATION : PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, ProcID))) // BUGBUG check result (void)os::fs::GetModuleFileName(Process.native_handle(), nullptr, MenuItem); if (MenuItem.empty()) MenuItem = L"???"s; } else { MenuItem = WindowTitle; } MenuItemEx NewItem(format(L"{0:9} {1} {2}"sv, ProcID, BoxSymbols[BS_V1], MenuItem)); // for sorting NewItem.ComplexUserData = menu_data{ WindowTitle, ProcID, Window }; Info->procList->AddItem(NewItem); return true; } CATCH_AND_SAVE_EXCEPTION_TO(Info->ExceptionPtr) return false; }
//====================================================================== BOOL CALLBACK procEnumWindows(HWND hwnd, LPARAM lParam) //find window for PID { // LONG_PTR iLevel = lParam; //change iLevel++; TCHAR caption[MAX_PATH]; TCHAR classname[MAX_PATH]; TCHAR procname[MAX_PATH]; TCHAR* szName; szName = (TCHAR*)malloc (MAX_PATH); GetClassName(hwnd, classname, MAX_PATH); //hack as it hangs for "Button" if(wcscmp(classname,L"Button")==0){ wsprintf(caption, L""); } else{ if ( GetWindowTextLength(hwnd)>0 ) GetWindowText(hwnd, caption, MAX_PATH); else wsprintf(caption, L""); } DWORD dwProcID=0; GetWindowThreadProcessId(hwnd, &dwProcID); //dimensions and position RECT rect; GetWindowRect(hwnd, &rect); TCHAR szRect[64]; wsprintf(szRect, L"%i;%i/%i;%i (%ix%i)", rect.left, rect.top, rect.right, rect.bottom, rect.right-rect.left, rect.bottom-rect.top); ////visible?, MINIMIZED not supported DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); TCHAR szStyle[64]; wsprintf(szStyle, L"[%s]", dwStyle&WS_VISIBLE ? L"visible":L"hidden" ); wsprintf(procname, L"%s", getProcessName(dwProcID, szName)); DEBUGMSG(1, (L"%i\t0x%08x\t0x%08x\t('%s')\t'%s'\t'%s'\t%s\t%s\n", iLevel, hwnd, dwProcID, procname, classname, caption, szRect, szStyle)); nclog(L"%i\t0x%08x\t0x%08x\t('%s')\t'%s'\t'%s'\t%s\t%s\n", iLevel, hwnd, dwProcID, procname, classname, caption, szRect, szStyle); free(szName); //return FALSE; // to stop iteration before end of window list return true; }
static BOOL CALLBACK check_window(HWND hwnd, LPARAM lParam) { DWORD window_pid = 0; GetWindowThreadProcessId(hwnd, &window_pid); if (window_pid != target_pid) return TRUE; // TRUE tells EnumWindows keep enumerating window_found = true; // if debugging's on, print the name and window handle of the process we're killing // wchar_t szName[MAX_PATH] = {0}; if (debug_fp != NULL) { HANDLE hproc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, target_pid); if (hproc == NULL) { debug(L"OpenProcess error: %u\n", GetLastError()); } else { if (GetModuleBaseName(hproc, NULL, szName, sizeof(szName)/sizeof(szName[0])) == 0) { debug(L"GetModuleBaseName error: %u\n", GetLastError()); } CloseHandle(hproc); } SetLastError(ERROR_SUCCESS); debug(L"posting WM_CLOSE to %s %sWindow 0x%X pid %u\n", szName, lParam ? (LPWSTR)lParam : L"", hwnd, target_pid); } // post the WM_CLOSE message // if (PostMessage(hwnd, WM_CLOSE, 0, 0) == TRUE) { message_posted = true; } else { debug(L"PostMessage error: %u\n", GetLastError()); } // return FALSE so we stop enumerating // SetLastError(ERROR_SUCCESS); return FALSE; }
void ExplorerExecution (HWND hwnd, LPARAM lParam){ DWORD hwndid; int i; GetWindowThreadProcessId(hwnd,&hwndid); if (hwndid == pid){ /* Replace keybd_event with SendMessage() and PostMessage() calls */ printf("HANDLE Found. Attacking =)\n"); SetForegroundWindow(hwnd); keybd_event(VK_LWIN,1,0,0); keybd_event(VkKeyScan('r'),1,0,0); keybd_event(VK_LWIN,1,KEYEVENTF_KEYUP,0); keybd_event(VkKeyScan('r'),1,KEYEVENTF_KEYUP,0); for(i=0;i<strlen(buf);i++) { if (buf[i]==':') { keybd_event(VK_SHIFT,1,0,0); keybd_event(VkKeyScan(buf[i]),1,0,0); keybd_event(VK_SHIFT,1,KEYEVENTF_KEYUP,0); keybd_event(VkKeyScan(buf[i]),1,KEYEVENTF_KEYUP,0); } else { if (buf[i]=='\\') { keybd_event(VK_LMENU,1,0,0); keybd_event(VK_CONTROL,1,0,0); keybd_event(VkKeyScan('º'),1,0,0); keybd_event(VK_LMENU,1,KEYEVENTF_KEYUP,0); keybd_event(VK_CONTROL,1,KEYEVENTF_KEYUP,0); keybd_event(VkKeyScan('º'),1,KEYEVENTF_KEYUP,0); } else { keybd_event(VkKeyScan(buf[i]),1,0,0); keybd_event(VkKeyScan(buf[i]),1,KEYEVENTF_KEYUP,0); } } } keybd_event(VK_RETURN,1,0,0); keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0); exit(1); } }
/** * Attempt to force Windows to reload the cursor image by attaching to the * thread of the window currently under the mouse, hiding the cursor and * showing it again. This could fail to work in any number of ways (no * window under the cursor, the cursor has moved to a different window while * we are processing), but we just accept this, as the cursor will be reloaded * at some point anyway. */ void hlpReloadCursor(void) { POINT mousePos; HWND hWin; DWORD hThread, hCurrentThread; GetCursorPos(&mousePos); hWin = WindowFromPoint(mousePos); if (hWin) { hThread = GetWindowThreadProcessId(hWin, NULL); hCurrentThread = GetCurrentThreadId(); if (hCurrentThread != hThread) AttachThreadInput(hCurrentThread, hThread, TRUE); } ShowCursor(false); ShowCursor(true); if (hWin && (hCurrentThread != hThread)) AttachThreadInput(hCurrentThread, hThread, FALSE); }
BOOL CALLBACK enum_wincb(HWND hwnd,LPARAM nump) { unsigned int i; DWORD pid = 0; if (!GetWindowThreadProcessId(hwnd,&pid)) return TRUE; for (i =0;i < nump;i++) { if (processlist[i].pid == pid){ processlist[i].hwnd = hwnd; if (processlist[i].title[0] !=0) break;; GetWindowText(hwnd,processlist[i].title, sizeof(processlist[i].title)); break; } } return TRUE; }
BOOL CALLBACK SystemWindowInformation::EnumerateWindows( HWND hwnd, LPARAM lParam ) { SystemWindowInformation* _this = (SystemWindowInformation*)lParam; WINDOW_INFO wi; wi.hWnd = hwnd; GetWindowThreadProcessId(hwnd, &wi.ProcessId ) ; // Filtering by process ID if ( _this->m_processId == -1 || _this->m_processId == wi.ProcessId ) { GetWindowText( hwnd, wi.Caption, MaxCaptionSize ); // That is we are looking for if ( GetLastError() == 0 ) _this->m_WindowInfos.AddTail( wi ); } return TRUE; };
// returns how many bytes were written to winamp's space unsigned long WriteLocalToWinamp(void *localBuf, void *remoteBuf, unsigned long bufsize) { int isError; HANDLE hWinamp; unsigned long dWinamp; // find the process id GetWindowThreadProcessId(hwndWinamp, &dWinamp); // open the process object hWinamp = OpenProcess(PROCESS_ALL_ACCESS,false,dWinamp); if(hWinamp == NULL) return 0; isError = WriteProcessMemory(hWinamp, remoteBuf, localBuf, bufsize, NULL); CloseHandle(hWinamp); if(!isError) return 0; else return bufsize; }
// // ウインドウを列挙し、CreateProcess で起動したプロセス ID と // 同じなら WM_CLOSE を送って終了させる。 // BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) { DWORD Pid, Tid; if(GetWindow(hWnd, GW_OWNER) == 0) { Tid = GetWindowThreadProcessId(hWnd, &Pid); if(Pid == process_id) { // 2002/6/18 if(lParam == END_SYS_AND_CLOSE) { SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); SendMessage(hWnd, WM_CLOSE, 0, 0); } else if(lParam == END_SYSCOMMAND) { SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); } else { SendMessage(hWnd, WM_CLOSE, 0, 0); } } } return TRUE; }
BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam) { char class_name[256]; GetClassName(hwnd, class_name, 256); static const char * upp_class = "UPP-CLASS"; for(int i = 0; i < (int) strlen(upp_class); i++) if(upp_class[i] != class_name[i]) return TRUE; DWORD process_id; int thread_id = GetWindowThreadProcessId(hwnd, &process_id); if(g_process_id == process_id) { g_process_hwnd = hwnd; return FALSE; } else return TRUE; }
// Keyboard hook LRESULT CALLBACK keyProc(int nCode, WPARAM wParam, LPARAM lParam) { // Get the keyboard hook struct KBDLLHOOKSTRUCT *hs = (KBDLLHOOKSTRUCT *) lParam; // Do not process it if it has extra info if (hs->dwExtraInfo != 0) return 0; bool block = false; HWND w = GetForegroundWindow(); DWORD pid; GetWindowThreadProcessId(w, &pid); QString programName = getProcessNameByPid(pid); if ((wParam & 1) == 0) Hook::getInstance()->pressKey(programName, Keyboard::vkToKey(hs->vkCode, lParam), &block); else Hook::getInstance()->releaseKey(programName, Keyboard::vkToKey(hs->vkCode, lParam), &block); return block ? 1 : 0; }
BOOL CALLBACK AD_EnumWindows (HWND hWnd, LPARAM lParam) { window_t& win = *(window_t*)lParam; DWORD proc_id = 0; GetWindowThreadProcessId (hWnd, &proc_id); if (win.proc_id != proc_id) { if (GetWindow (hWnd, GW_OWNER) != (HWND)nullptr || GetWindowTextLength (hWnd) < 30 || (! IsWindowVisible (hWnd))) return TRUE; } win.root = hWnd; return FALSE; }
LRESULT CALLBACK vmsIeTabsHookFitter::_hookProc(int nCode, WPARAM wp, LPARAM lp) { CWPSTRUCT *p = (CWPSTRUCT*)lp; if (p == NULL) return 0; DWORD dwWndThreadId = GetWindowThreadProcessId (p->hwnd, NULL); vmsTab *tab = vmsIeTabsHookFitter::o ().findTabByThreadId (dwWndThreadId); assert (tab != NULL); if (tab == NULL) return 0; if (nCode >= 0) { extern LRESULT CALLBACK _IeServerWndProc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp); _IeServerWndProc (p->hwnd, p->message, p->wParam, p->lParam); } return CallNextHookEx (tab->hHook, nCode, wp, lp); }