BOOL CALLBACK FindPrevInstanceProc(HWND hWnd, LPSTR lpszParam) { char szT[260]; HANDLE hInstance; // Filter out invisible and disabled windows // if (!IsWindowEnabled(hWnd) || !IsWindowVisible(hWnd)) return TRUE; hInstance = GetWindowWord(hWnd, GWW_HINSTANCE); GetModuleFileName(hInstance, szT, sizeof (szT)-1); // Make sure that the hWnd belongs to the current VDM process // // GetWindowTask returns the wowexec htask16 if the window belongs // to a different process - thus we filter out windows in // 'separate VDM' processes. // - nanduri if (lstrcmpi(szT, lpszParam) == 0 && GetWindowTask(hWnd) != GetWindowTask(ghwndMain)) { *(LPHANDLE)lpszParam = hWnd; return FALSE; } else { return TRUE; } }
static BOOL IsTaskWnd( HWND wnd ) { if( wnd == NULL ) return( FALSE ); if( !IsWindow( wnd ) ) return( FALSE ); if( GetWindowTask( wnd ) != DebugeeTask ) return( FALSE ); return( TRUE ); }
// -------------------------------------------------------------------------- // // PatchDdi() // // Patches the DDI for the caller // // -------------------------------------------------------------------------- HPATCH WINAPI PatchDdi(HWND hwnd, HGLOBAL hHeap, UINT uType) { HPATCH hpatch; // // Allocate a structure. // hpatch = (HPATCH)LocalAlloc(LPTR, sizeof(PATCH)); if (!hpatch) return(NULL); // // Save info away // hpatch->hwndPost = hwnd; hpatch->hheapPost = hHeap; hpatch->idThread = (DWORD)GetWindowTask(hwnd); // // Set the ddi hook // hpatch->hddi = SetDDIHook(NULL, hInstance, MAKELONG(hpatch, 0), uType, DdiHookProc); // // Installation failed, clean up. // if (!hpatch->hddi) { LocalFree((HANDLE)hpatch); hpatch = NULL; } return(hpatch); }
BOOL RestoreFocusToChild ( HWND parent, HWND avoid_this_one ) { FoundChild = 0 ; EnumTaskWindows ( GetWindowTask ( parent ), EnumProc, ( LPARAM ) avoid_this_one ) ; if ( FoundChild ) { SetActiveWindow ( FoundChild ) ; return ( TRUE ) ; } else return ( FALSE ) ; }
/* * IsMyWindow - check if a specific window belongs to our task */ BOOL IsMyWindow( HWND hwnd ) { if( hwnd == NULL ) { return( FALSE ); } if( GetWindowTask( hwnd ) == MyTask ) { if( hwnd == GetDesktopWindow() ) { return( FALSE ); } return( TRUE ); } return( FALSE ); } /* IsMyWindow */
BOOL WINAPI PostMessage(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { HTASK hTask; BOOL rc; APISTR((LF_APICALL, "PostMessage(HWND=%x,UINT=%x:%s,WPARAM=%x,LPARAM=%x)\n", hWnd,wMsg,GetTwinMsgCode(hWnd,wMsg),wParam,lParam)); if (hWnd != 0xffff) hTask = GetWindowTask(hWnd); else hTask = GetCurrentTask(); rc = AddAppMsgQueue(hTask,-1,hWnd,wMsg,wParam,lParam); APISTR((LF_APIRET,"PostMessage: returns BOOL %d\n",rc)); return rc; }
void TWIN_FlushWindowMessages(HWND hWnd) { LPQUEUEMSG lpQueueMsg, lpQueuePtr, lpQueueNext; HANDLE hTask; LPQUEUE lpQueue; hTask = GetWindowTask(hWnd); lpQueue = QueueGetPtr(hTask); if (!lpQueue) return; for(lpQueueMsg = lpQueue->lpQueueNext; lpQueueMsg; lpQueueMsg = lpQueueNext) { lpQueueNext = (LPQUEUEMSG)(lpQueueMsg->lpNextMsg); if (lpQueueMsg->Message.hwnd == hWnd) { /* is it the first one in the queue */ if (lpQueueMsg == lpQueue->lpQueueNext) lpQueue->lpQueueNext = lpQueueMsg->lpNextMsg; else { /* find the message before this one */ for (lpQueuePtr = lpQueue->lpQueueNext; lpQueuePtr->lpNextMsg != lpQueueMsg; lpQueuePtr = lpQueuePtr->lpNextMsg); /* set the next message of our previous to our next msg */ lpQueuePtr->lpNextMsg = lpQueueMsg->lpNextMsg; } /* add this message to the free list */ lpQueueMsg->lpNextMsg = lpQueue->lpQueueFree; lpQueue->lpQueueFree = lpQueueMsg; } } }
BOOL QueueGetMsg(LPQUEUE lpQueue, LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wFlags) { #define POOLSIZE 16 #define POOLMASK 0x000f LPQUEUEMSG lpQueueMsg, lpQueuePtr, lpQueueNext; MSG msg; int nmsgs; int rc; static WMCONVERT ConvPool[POOLSIZE]; static int nPoolIndex = 0; extern BOOL IsMouseOrKeyboardMsg(UINT); UINT cFlags; if(lpQueue == 0) { lpQueue = SystemQueue; } /* search for a message meeting our filters... */ for(lpQueueMsg = lpQueue->lpQueueNext,nmsgs=0,rc=0; lpQueueMsg; lpQueueMsg = lpQueueNext) { cFlags = wFlags; lpQueueNext = (LPQUEUEMSG)(lpQueueMsg->lpNextMsg); msg = lpQueueMsg->Message; if(msg.hwnd && !IsWindow(msg.hwnd)) { // we have an event for a non-existent window // don't even try to pass it on, instead flush // it from the queue, and get another... cFlags |= PM_REMOVE; } else { if ((lpQueue == SystemQueue) && (IsMouseOrKeyboardMsg(msg.message) == WM_MOUSEFIRST)) if (!TWIN_ForwardButtonEvent(&msg)) continue; if (wMsgFilterMin) { if (msg.message < wMsgFilterMin) continue; } if (wMsgFilterMax) { if (msg.message > wMsgFilterMax) continue; } if (hWnd == HWND_BROADCAST) { if (msg.hwnd) continue; } else if (hWnd) { if (msg.hwnd && msg.hwnd != hWnd) { if (!IsChild(hWnd, msg.hwnd)) continue; } } } if(msg.hwnd && !IsWindow(msg.hwnd)) rc++; else { if (msg.hwnd && GetWindowTask(msg.hwnd) != GetCurrentTask()) { ReadyTask(GetWindowTask(msg.hwnd)); continue; } if (msg.hwnd && HaveDisabledAncestor(msg.hwnd) && lpQueue == SystemQueue) { if ((rc == 0) && (msg.message != WM_MOUSEMOVE) && (msg.message != WM_NCMOUSEMOVE)) MessageBeep(0); rc++; } else { rc = 0; memcpy((LPSTR)lpMsg,(LPSTR)&(msg), sizeof(MSG)); if (lpMsg->message == WM_CONVERT) { memcpy((LPSTR)&ConvPool[nPoolIndex], (LPSTR)&(lpQueueMsg->wmc), sizeof(WMCONVERT)); lpMsg->lParam = (LPARAM)&ConvPool[nPoolIndex]; lpMsg->wParam |= HSWMC_ALLOC; nPoolIndex = (nPoolIndex+1) & POOLMASK; } } } /* are we removing it? */ if (cFlags & PM_REMOVE) { /* is it the first one in the queue */ if (lpQueueMsg == lpQueue->lpQueueNext) lpQueue->lpQueueNext = lpQueueMsg->lpNextMsg; else { /* find the message before this one */ for(lpQueuePtr = lpQueue->lpQueueNext; lpQueuePtr->lpNextMsg != lpQueueMsg; lpQueuePtr = lpQueuePtr->lpNextMsg); /* set the next message of our previous to our next msg */ lpQueuePtr->lpNextMsg = lpQueueMsg->lpNextMsg; } /* add this message to the free list */ lpQueueMsg->lpNextMsg = lpQueue->lpQueueFree; lpQueue->lpQueueFree = lpQueueMsg; } if(rc == 0) return(TRUE); } return FALSE; }
LRESULT WINAPI SendMessage(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { #ifdef STRICT WNDPROC lpfnWndProc; #else FARPROC lpfnWndProc; #endif DWORD rc; BOOL cInSendMessage; MSG msg; HWND32 hWnd32; #ifdef DEBUG memset((LPSTR)&msg,'\0',sizeof(MSG)); #endif if(hWnd == HWND_BROADCAST) { msg.message = wMsg; msg.wParam = wParam; msg.lParam = lParam; /*send to all top level windows */ return EnumWindows((WNDENUMPROC)MultiSendMsg,(LONG)&msg); } /* * Is this a valid window? */ if (!(hWnd32 = CHECKHWND32(hWnd))) return 0; /* * Does the window have a valid task? */ if (GetWindowTask(hWnd) == 0 || !TWIN_IsLiveTask(GetWindowTask(hWnd))) { RELEASEWININFO(hWnd32); return 0; } /* * Is this window dead? */ if (hWnd32->dwWinFlags & WFDEAD) { RELEASEWININFO(hWnd32); return 0; } /* * Window is a good destination. Intertask send? */ if (hWnd != 0 && GetWindowTask(hWnd) != GetCurrentTask()) { ITSMINFO smse; /* save current InSendMessage Flag */ cInSendMessage = bInSendMessage; /* we are now in sendmessage */ bInSendMessage = TRUE; smse.hSendingTask = GetCurrentTask(); smse.hReceivingTask = GetWindowTask(hWnd); smse.msg.hwnd = hWnd; smse.msg.message = wMsg; smse.msg.wParam = wParam; smse.msg.lParam = lParam; smse.bSendReceived = FALSE; smse.bSendCompleted = FALSE; smse.lpPrev = lpSendMessageStack; lpSendMessageStack = &smse; DirectedYield(smse.hReceivingTask); while (!smse.bSendCompleted) { TWIN_ReceiveMessage(TRUE); } lpSendMessageStack = smse.lpPrev; /* back to what it was before... */ bInSendMessage = cInSendMessage; RELEASEWININFO(hWnd32); return smse.lResult; } if ((lpfnWndProc = #ifdef STRICT (WNDPROC) #else (FARPROC) #endif GetWindowLong(hWnd, GWL_WNDPROC)) == NULL) { ERRSTR((LF_WARNING,"SendMessage: Null wndproc!\n")); RELEASEWININFO(hWnd32); return(0L); } /* save current InSendMessage Flag */ cInSendMessage = bInSendMessage; /* we are now in sendmessage */ bInSendMessage = TRUE; if (lpHookList[WH_CALLWNDPROC+1]) { ATOM atmClassName; HOOKINFO hki; if ((atmClassName = GetClassWord(hWnd,GCW_ATOM)) != atmGlobalLookup[LOOKUP_FRAME]) { hki.hWnd = hWnd; hki.msg = wMsg; hki.wParam = wParam; hki.lParam = lParam; msg.hwnd = hWnd; msg.message = wMsg; msg.wParam = wParam; msg.lParam = lParam; lpHookList[WH_CALLWNDPROC+1]->lpfnHookProc(0,0,(LPARAM)&hki); } } rc = TWIN_CallWindowProc(lpfnWndProc,0,hWnd, wMsg, wParam, lParam); RELEASEWININFO(hWnd32); /* back to what it was before... */ bInSendMessage = cInSendMessage; return rc; }
BOOL TWIN_DriverMessage(LPMSG lpMsg, HWND hWnd, UINT uMin, UINT uMax,UINT uFlg,BOOL bNoWait) { DWORD dwerv; HANDLE hTask; LPQUEUE lpQueue; if (hWnd && !IsWindow(hWnd)) hWnd = 0; if (hWnd) hTask = GetWindowTask(hWnd); else hTask = GetCurrentTask(); lpQueue = QueueGetPtr(hTask); /******************************************/ /* what is this? it is not called... */ /*hFocusTask = GetWindowTask(GetFocus()); */ /******************************************/ lpMsg->hwnd = 0; labLoop: while(1) { while (lpSendMessageStack && lpSendMessageStack->hReceivingTask == GetCurrentTask() && !lpSendMessageStack->bSendReceived) { TWIN_ReceiveMessage(FALSE); } /* try for a message from application queue */ if (QueueGetMsg(lpQueue, lpMsg, hWnd, uMin, uMax, uFlg)) { break; } /* try for a message from system queue */ if (QueueGetMsg(0,lpMsg,hWnd,uMin,uMax,uFlg)) { break; } if (uMin <= WM_PAINT && (!uMax || uMax >= WM_PAINT)) { /* finally, check if the window needs a paint message */ if(lpQueue->wQueueFlags & QFPAINT) { labTryNext: if((lpMsg->hwnd = InternalUpdateWindows())) { if (TestWF(lpMsg->hwnd, WFNCDIRTY)) { if (NonEmptyNCRect(lpMsg->hwnd)) { lpMsg->message = WM_NCPAINT; lpMsg->wParam = 0; lpMsg->lParam = 0L; break; } else { ClearWF(lpMsg->hwnd, WFNCDIRTY); } } if (TestWF(lpMsg->hwnd, WFDIRTY)) { if (IsIconic(lpMsg->hwnd) && GetClassIcon(lpMsg->hwnd)) { lpMsg->message = WM_PAINTICON; lpMsg->wParam = 1; } else { lpMsg->message = WM_PAINT; lpMsg->wParam = 0; } lpMsg->lParam = 0L; break; } else goto labTryNext; } lpQueue->wQueueFlags &= ~QFPAINT; } } if ((uMin <= WM_TIMER && (!uMax || uMax >= WM_TIMER)) || (uMin <= WM_SYSTIMER && (!uMax || uMax >= WM_SYSTIMER))) { if(lpQueue->wQueueFlags & QFTIMER) { if (TWIN_GetTimerMsg(hWnd,hTask,lpMsg,uFlg)) { break; } } } /* none of the above, so see if system is ready. */ if (!TWIN_InDriverWait) { TWIN_InDriverWait = TRUE; dwerv = DriverWaitEvent(TRUE); TWIN_InDriverWait = FALSE; if (!dwerv && !bNoWait) { /* * The code here used to call ReadyTask(GetCurrentTask()) * before calling InternalYield(), but that results in * a solid-run condition if more than one task is * defined, because it results in the other task looking * like it's ready to run, when all tasks should be waiting * on a driver event. So we yield if necessary, but do * not set ourselves as ready-to-run if we do. We will * be run again when we first get a message in our queue. */ #if defined(MAC_TASKING_PATCH) ReadyTask(GetCurrentTask()); #endif if (!InternalYield()) { TWIN_InDriverWait = TRUE; (void)DriverWaitEvent(FALSE); TWIN_InDriverWait = FALSE; } } else if (!(uFlg & PM_NOYIELD)) Yield(); } else if (!(uFlg & PM_NOYIELD)) InternalYield(); if(bNoWait) return FALSE; } if (CallGetMessageHooks(lpMsg,uFlg & PM_REMOVE)) goto labLoop; return TRUE; }
/* * spyInit - initialization */ static BOOL spyInit( HANDLE currinst, HANDLE previnst, int cmdshow ) { WNDCLASS wc; HANDLE memhdl; WORD i; i=i; memhdl = memhdl; /* shut up the compiler for non-NT version */ JDialogInit(); Instance = currinst; ResInstance = currinst; if( !InitGblStrings() ) { return( FALSE ); } SpyMenu = LoadMenu( ResInstance, "SPYMENU" ); #ifdef __WATCOMC__ _STACKLOW = 0; #endif MemStart(); HandleMessageInst = MakeProcInstance( (FARPROC) HandleMessage, Instance ); HintWndInit( Instance, NULL, 0 ); /* * set up window class */ if( !previnst ) { wc.style = 0L; wc.lpfnWndProc = SpyWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = sizeof( LONG_PTR ); wc.hInstance = Instance; wc.hIcon = LoadIcon( ResInstance, "APPLICON" ); wc.hCursor = LoadCursor( (HANDLE)NULL, IDC_ARROW); #ifdef __NT__ wc.hbrBackground = NULL; #else wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); #endif wc.lpszMenuName = NULL; wc.lpszClassName = SPY_CLASS_NAME; if( !RegisterClass( &wc ) ) { return( FALSE ); } #ifdef USE_SNAP_WINDOW if( !RegisterSnapClass( Instance ) ) { return( FALSE ); } #endif } #ifndef NOUSE3D CvrCtl3DInit( Instance ); CvrCtl3dRegister( Instance ); CvrCtl3dAutoSubclass( Instance ); #endif /* * now make the main window */ LoadSpyConfig( NULL ); SpyMainWindow = CreateWindow( SPY_CLASS_NAME, /* Window class name */ SpyName, /* Window caption */ WS_OVERLAPPEDWINDOW, /* Window style */ SpyMainWndInfo.xpos, /* Initial x position */ SpyMainWndInfo.ypos, /* Initial y position */ SpyMainWndInfo.xsize, /* Initial x size */ SpyMainWndInfo.ysize, /* Initial y size */ (HWND)NULL, /* Parent window handle */ (HMENU)SpyMenu, /* Window menu handle */ Instance, /* Program instance handle */ NULL ); /* Create parameters */ if( SpyMainWindow == NULL ) { return( FALSE ); } MyTask = GetWindowTask( SpyMainWindow ); ShowWindow( SpyMainWindow, cmdshow ); UpdateWindow( SpyMainWindow ); InitMessages(); return( TRUE ); } /* spyInit */