void CBackgroundUpdater::IgnoreItemsAndGoToSleep() { InterlockedExchange(&m_lIgnoreItemsAndGoToSleep,TRUE); ISDLGTHREADOK BuDebugMessage("BU: IgnoreItemsAndGoToSleep, executing modal loop"); PostQuitMessage(0); GetTrayIconWnd()->GetLocateDlgThread()->ModalLoop(); while (!m_lIsWaiting) { Sleep(20); PostQuitMessage(0); GetTrayIconWnd()->GetLocateDlgThread()->ModalLoop(); } BuDebugMessage("BU: modal loop out"); if (m_lIgnoreItemsAndGoToSleep) { EnterCriticalSection(&m_csUpdateList); m_aUpdateList.RemoveAll(); LeaveCriticalSection(&m_csUpdateList); } BuDebugMessage("BU: IgnoreItemsAndGoToSleep END"); }
void CSubAction::DoMenuCommand() { CLocateDlg* pLocateDlg=GetLocateDlg(); if (pLocateDlg==NULL) return; if (GetCurrentThreadId()==GetTrayIconWnd()->GetLocateDlgThread()->GetThreadId()) pLocateDlg->OnCommand(LOWORD(m_nMenuCommand),0,NULL); else pLocateDlg->SendMessage(WM_COMMAND,MAKEWPARAM(LOWORD(m_nMenuCommand),0),0); }
void CShortcut::SendEventBackToControl() { #ifndef KEYHOOK_EXPORTS CWinThread* pThread=GetTrayIconWnd()->GetLocateDlgThread(); if (pThread!=NULL) { const MSG* pMsg=pThread->GetCurrentMessage(); ASSERT(pMsg!=NULL); TranslateMessage(pMsg); if (IsUnicodeSystem()) DispatchMessageW(pMsg); else DispatchMessageA(pMsg); } #endif }
void CSubAction::DoMisc() { if (m_nMisc==ExecuteCommandMisc) { if (m_szCommand!=NULL) CLocateDlg::ExecuteCommand(m_szCommand); return; } else if (m_nMisc==InsertAsterisks) { CLocateDlg* pLocateDlg=GetLocateDlg(); if (pLocateDlg==NULL) return; CStringW Text; pLocateDlg->m_NameDlg.m_Name.GetText(Text); DWORD dwSelStart=pLocateDlg->m_NameDlg.m_Name.GetEditSel(); WORD wSelEnd=HIWORD(dwSelStart); dwSelStart&=0xFFFF; // If asterisks are already at the beginning and the end, replace spaces if (Text[0]==L'*' && Text.LastChar()==L'*') Text.ReplaceChars(L' ',L'*'); else { if (Text[0]!=L'*') { Text.InsChar(0,L'*'); // Update selection if (dwSelStart==wSelEnd) { dwSelStart++; wSelEnd++; } else { if (dwSelStart>0) dwSelStart++; wSelEnd++; } } if (Text.LastChar()!=L'*') { // Update selection first if (wSelEnd==Text.GetLength()) { if (dwSelStart==wSelEnd) dwSelStart++; wSelEnd++; } Text.Append(L'*'); } } pLocateDlg->m_NameDlg.m_Name.SetText(Text); pLocateDlg->m_NameDlg.m_Name.SetEditSel(dwSelStart,wSelEnd); pLocateDlg->OnFieldChange(CLocateDlg::isNameChanged); return; } // Send/Post Message BOOL bFreeWParam=FALSE,bFreeLParam=FALSE; HWND hWnd=NULL; WPARAM wParam=NULL,lParam=NULL; if (m_pSendMessage->szWindow[0]=='0') { if (m_pSendMessage->szWindow[1]=='x' || m_pSendMessage->szWindow[1]=='X') { // Hex value LPWSTR szTemp; hWnd=(HWND)wcstoul(m_pSendMessage->szWindow+2,&szTemp,16); } } else if (strcasecmp(m_pSendMessage->szWindow,L"HWND_BROADCAST")==0) hWnd=HWND_BROADCAST; else if (GetLocateDlg()!=NULL && strcasecmp(m_pSendMessage->szWindow,L"LOCATEDLG")==0) hWnd=*GetLocateDlg(); else if (strcasecmp(m_pSendMessage->szWindow,L"LOCATEST")==0) hWnd=*GetTrayIconWnd(); else if (wcsncmp(m_pSendMessage->szWindow,L"Find",4)==0) { int nIndex=(int)FirstCharIndex(m_pSendMessage->szWindow,L'('); if (nIndex!=-1) { LPCWSTR pText=m_pSendMessage->szWindow+nIndex+1; LPWSTR pClassAndWindow[3]={NULL,NULL,NULL}; nIndex=(int)FirstCharIndex(pText,L','); if (nIndex==-1) { nIndex=(int)FirstCharIndex(pText,L')'); if (nIndex==-1) pClassAndWindow[0]=alloccopy(pText); else pClassAndWindow[0]=alloccopy(pText,nIndex); } else { pClassAndWindow[0]=alloccopy(pText,nIndex); pText+=nIndex+1; nIndex=(int)FirstCharIndex(pText,L')'); pClassAndWindow[1]=alloccopy(pText,nIndex); } EnumWindows(WindowEnumProc,LPARAM(pClassAndWindow)); // Third cell is handle to window hWnd=(HWND)pClassAndWindow[2]; delete[] pClassAndWindow[0]; if (pClassAndWindow[1]) delete[] pClassAndWindow[1]; } } // Parse wParam if (m_pSendMessage->szWParam!=NULL) { if (m_pSendMessage->szWParam[0]=='0') { if (m_pSendMessage->szWParam[1]=='x' || m_pSendMessage->szWParam[1]=='X') { // Hex value LPWSTR szTemp; wParam=(WPARAM)wcstoul(m_pSendMessage->szWParam+2,&szTemp,16); } else if (m_pSendMessage->szWParam[1]!='\0') { DWORD dwLength; wParam=(WPARAM)dataparser(m_pSendMessage->szWParam,istrlen(m_pSendMessage->szWParam),gmalloc,&dwLength); *((BYTE*)wParam+dwLength)=0; bFreeWParam=TRUE; } } else if ((wParam=_wtoi(m_pSendMessage->szWParam))==0) { DWORD dwLength; wParam=(WPARAM)dataparser(m_pSendMessage->szWParam,istrlen(m_pSendMessage->szWParam),gmalloc,&dwLength); *((BYTE*)wParam+dwLength)=0; bFreeWParam=TRUE; } } // Parse lParam if (m_pSendMessage->szLParam!=NULL) { if (m_pSendMessage->szLParam[0]=='0') { if (m_pSendMessage->szLParam[1]=='x' || m_pSendMessage->szLParam[1]=='X') { // Hex value LPWSTR szTemp; lParam=(WPARAM)wcstoul(m_pSendMessage->szLParam+2,&szTemp,16); } else if (m_pSendMessage->szLParam[1]!='\0') { DWORD dwLength; lParam=(WPARAM)dataparser(m_pSendMessage->szLParam,istrlen(m_pSendMessage->szLParam),gmalloc,&dwLength); *((BYTE*)lParam+dwLength)=0; bFreeLParam=TRUE; } } else if ((lParam=_wtoi(m_pSendMessage->szLParam))==0) { DWORD dwLength; lParam=(WPARAM)dataparser(m_pSendMessage->szLParam,istrlen(m_pSendMessage->szLParam),gmalloc,&dwLength); *((BYTE*)lParam+dwLength)=0; bFreeLParam=TRUE; } } if (hWnd!=NULL) { if (m_nMisc==PostMessage) ::PostMessage(hWnd,m_pSendMessage->nMessage,wParam,lParam); else ::SendMessage(hWnd,m_pSendMessage->nMessage,wParam,lParam); } if (bFreeWParam) GlobalFree((HANDLE)wParam); if (bFreeLParam) GlobalFree((HANDLE)lParam); }
void CSubAction::DoHelp() { CTargetWnd* pWnd=GetLocateDlg(); if (pWnd==NULL) pWnd=GetTrayIconWnd(); switch(m_nHelp) { case HelpShowHelp: { HELPINFO h; h.cbSize=sizeof(HELPINFO); h.iContextType=HELPINFO_WINDOW; h.hItemHandle=GetFocus(); if (pWnd==GetLocateDlg()) { // If comboboxes are selected, the edit in size of combo // may have focus. HWND hParent=GetParent((HWND)h.hItemHandle); while (hParent!=NULL && hParent!=*pWnd && hParent!=((CLocateDlg*)pWnd)->m_NameDlg && hParent!=((CLocateDlg*)pWnd)->m_SizeDateDlg && hParent!=((CLocateDlg*)pWnd)->m_AdvancedDlg) { h.hItemHandle=hParent; hParent=GetParent(hParent); } } h.iCtrlId=GetDlgCtrlID((HWND)h.hItemHandle); h.dwContextId=0; GetCursorPos(&h.MousePos); pWnd->OnHelp(&h); break; } case HelpCloseHelp: pWnd->HtmlHelp(HH_CLOSE_ALL,0); break; case HelpShowTopics: pWnd->HtmlHelp(HH_DISPLAY_TOPIC,0); break; case HelpIndex: pWnd->HtmlHelp(HH_DISPLAY_INDEX,0); break; case HelpTOC: pWnd->HtmlHelp(HH_DISPLAY_TOC,0); break; case HelpSearch: { HH_FTS_QUERY q; ZeroMemory(&q,sizeof(HH_FTS_QUERY)); q.cbStruct=sizeof(HH_FTS_QUERY); pWnd->HtmlHelp(HH_DISPLAY_SEARCH,(DWORD_PTR)&q); break; } }; }
void CSubAction::DoShowHideDialog() { CLocateDlg* pLocateDlg=GetLocateDlg(); switch(m_nDialogCommand) { case ShowDialog: GetTrayIconWnd()->OnLocate(); break; case MinimizeDialog: if (pLocateDlg!=NULL) pLocateDlg->ShowWindow(CWnd::swMinimize); break; case CloseDialog: if (pLocateDlg!=NULL) pLocateDlg->PostMessage(WM_CLOSE); break; case ShowOrHideDialog: if (pLocateDlg!=NULL) { WINDOWPLACEMENT wp; wp.length=sizeof(WINDOWPLACEMENT); pLocateDlg->GetWindowPlacement(&wp); if (wp.showCmd!=SW_SHOWMINIMIZED &&wp.showCmd!=SW_HIDE) pLocateDlg->ShowWindow(CWnd::swMinimize); else GetTrayIconWnd()->OnLocate(); } break; case OpenOrCloseDialog: if (pLocateDlg!=NULL) { WINDOWPLACEMENT wp; wp.length=sizeof(WINDOWPLACEMENT); pLocateDlg->GetWindowPlacement(&wp); if (wp.showCmd!=SW_SHOWMINIMIZED && wp.showCmd!=SW_HIDE) pLocateDlg->PostMessage(WM_CLOSE); else GetTrayIconWnd()->OnLocate(); } else GetTrayIconWnd()->OnLocate(); break; case RestoreDialog: if (pLocateDlg!=NULL) pLocateDlg->ShowWindow(CWnd::swRestore); break; case MaximizeDialog: if (pLocateDlg!=NULL) pLocateDlg->ShowWindow(CWnd::swMaximize); break; case MaximizeOrRestoreDialog: if (pLocateDlg!=NULL) { WINDOWPLACEMENT wp; wp.length=sizeof(WINDOWPLACEMENT); pLocateDlg->GetWindowPlacement(&wp); if (wp.showCmd!=SW_SHOWMAXIMIZED) pLocateDlg->ShowWindow(CWnd::swMaximize); else pLocateDlg->ShowWindow(CWnd::swRestore); } break; case ShowOpenOrHideDialog: if (pLocateDlg==NULL) GetTrayIconWnd()->OnLocate(); else if (pLocateDlg!=NULL) { WINDOWPLACEMENT wp; wp.length=sizeof(WINDOWPLACEMENT); pLocateDlg->GetWindowPlacement(&wp); if (wp.showCmd!=SW_SHOWMINIMIZED &&wp.showCmd!=SW_HIDE) pLocateDlg->ShowWindow(CWnd::swMinimize); else GetTrayIconWnd()->OnLocate(); } break; case ShowDialogAndGetDirFromExplorer: { LPWSTR pPath=GetPathFromExplorer(); GetTrayIconWnd()->OnLocate(); if (pPath!=NULL) { CLocateDlg* pLocateDlg=GetLocateDlg(); if (pLocateDlg!=NULL) pLocateDlg->SetPath(pPath); delete[] pPath; } break; } break; case StopLocatingOrCloseWindow: if (pLocateDlg!=NULL) { if (pLocateDlg->IsLocating()) pLocateDlg->OnStop(); else pLocateDlg->PostMessage(WM_CLOSE); } break; } }
BOOL CCheckFileNotificationsThread::Stop() { // Stopping background notifier FnDebugMessage("FN: stopping"); // First check whether thread is already stopped if (m_hThread==NULL) { FnDebugMessage("FN: already stopped"); return FALSE; } // Creating a copy of thread handle and using HANDLE hThread; DuplicateHandle(GetCurrentProcess(),m_hThread,GetCurrentProcess(), &hThread,0,FALSE,DUPLICATE_SAME_ACCESS); DebugOpenThread(hThread); ASSERT(m_lState==sInitializing || m_lState==sWaiting || m_lState==sProcessing || m_lState==sStopping); // First, try some friendly ways to terminate thread switch (m_lState) { case sInitializing: // Still initializing, say that processing can be stopped FnDebugMessage("FN: thread still initializing"); InterlockedExchange(&m_lFlags,m_lFlags|fwStopWhenPossible); // First wait that initialization is ended if (WaitForSingleObject(m_hStopEvent,500)!=WAIT_OBJECT_0) break; // Wait that ending processes are handled WaitForSingleObject(m_hThread,1000); break; case sWaiting: FnDebugMessage("FN: thread waiting"); // Waiting events, so give it SetEvent(m_hStopEvent); // Wait that ending processes are handled WaitForSingleObject(m_hThread,1000); break; case sProcessing: FnDebugMessage("FN: thread is processing"); InterlockedExchange(&m_lFlags,m_lFlags|fwStopWhenPossible); // Wait that ending processes are handled if (GetCurrentThreadId()==GetTrayIconWnd()->GetLocateDlgThread()->GetThreadId()) { // This Stop() is called from CLocateDlg, it is possible // that RunninProcNew sens messages to this window. // Taking care of that for (int i=0;i<40;i++) { PostQuitMessage(0); GetTrayIconWnd()->GetLocateDlgThread()->ModalLoop(); if (WaitForSingleObject(hThread,50)!=WAIT_TIMEOUT) break; } } else WaitForSingleObject(hThread,2000); break; }; if (GetLocateDlg()->m_pFileNotificationsThread!=NULL) { // So that didn't go very well, use harder ways InterlockedExchange(&m_lState,sTerminated); DWORD status=0; BOOL bRet=::GetExitCodeThread(hThread,&status); BOOL bTerminated=FALSE; if (bRet && status==STILL_ACTIVE) { if (::TerminateThread(hThread,1,TRUE)) bTerminated=TRUE; } if (bTerminated) delete this; } // Closing dublicated handle CloseHandle(hThread); DebugCloseThread(hThread); return TRUE; }