//比较两个文件名是否是同一个文件 int compareTwoFileName(const char* szFileName1, const char* szFileName2) { char szTempFileName1[MAX_PATH] = {0}; char szTempFileName2[MAX_PATH] = {0}; _snprintf(szTempFileName1, MAX_PATH, "%s", szFileName1); _snprintf(szTempFileName2, MAX_PATH, "%s", szFileName2); PathRemoveBlanks(szTempFileName1); PathRemoveBlanks(szTempFileName2); PathRemoveBackslash(szTempFileName1); PathRemoveBackslash(szTempFileName2); int nRet = _stricmp(szTempFileName1, szTempFileName2); if(nRet == 0) return 0; char szShortFileName1[MAX_PATH] = {0}; char szShortFileName2[MAX_PATH] = {0}; if(GetShortPathName(szTempFileName1, szShortFileName1, MAX_PATH)) { strcpy(szTempFileName1, szShortFileName1); } if(GetShortPathName(szTempFileName2, szShortFileName2, MAX_PATH)) { strcpy(szTempFileName2, szShortFileName2); } return _stricmp(szTempFileName1, szTempFileName2); }
void MRUSelChange(HWND hDlg) { int nItem; HWND hCB; PSTARTINFO pStartInfo; LRESULT lresult; TCHAR szCmd[MAX_PATH]; hCB = GetDlgItem(hDlg, IDD_COMMAND); nItem = (int)SendMessage(hCB, CB_GETCURSEL, 0, 0L); if (nItem < 0) { return; } lresult = SendMessage(hCB, CB_GETITEMDATA, nItem, 0L); if ((lresult == 0) || (lresult == CB_ERR)) { return; } pStartInfo = (PSTARTINFO)lresult; #ifdef SHOWSTATES SendDlgItemMessage(hDlg, IDD_STATE, CB_SETCURSEL, pStartInfo->nState, 0L); #endif lresult = SendMessage(hCB, CB_GETLBTEXT, nItem, (LPARAM)szCmd); PathRemoveBlanks(szCmd); EnableOKButton(hDlg, szCmd); }
BOOL CheckWildcardMatch(const TCHAR *szWildcard, const TCHAR *szString, BOOL bCaseSensitive) { /* Handles multiple wildcard patterns. If the wildcard pattern contains ':', split the pattern into multiple subpatterns. For example "*.h: *.cpp" would match against "*.h" and "*.cpp" */ BOOL bMultiplePattern = FALSE; for(int i = 0; i < lstrlen(szWildcard); i++) { if(szWildcard[i] == ':') { bMultiplePattern = TRUE; break; } } if(!bMultiplePattern) { return CheckWildcardMatchInternal(szWildcard, szString, bCaseSensitive); } else { TCHAR szWildcardPattern[512]; TCHAR *szSinglePattern = NULL; TCHAR *szSearchPattern = NULL; TCHAR *szRemainingPattern = NULL; StringCchCopy(szWildcardPattern, SIZEOF_ARRAY(szWildcardPattern), szWildcard); szSinglePattern = cstrtok_s(szWildcardPattern, _T(":"), &szRemainingPattern); PathRemoveBlanks(szSinglePattern); while(szSinglePattern != NULL) { if(CheckWildcardMatchInternal(szSinglePattern, szString, bCaseSensitive)) { return TRUE; } szSearchPattern = szRemainingPattern; szSinglePattern = cstrtok_s(szSearchPattern, _T(":"), &szRemainingPattern); PathRemoveBlanks(szSinglePattern); } } return FALSE; }
//--------------------------------------------------------------------------- void EnableOKButton(HWND hDlg, LPTSTR pszText) { TCHAR szText[MAX_PATH]; BOOL bNonEmpty; if (!pszText) { GetDlgItemText(hDlg, IDD_COMMAND, szText, ARRAYSIZE(szText)); PathRemoveBlanks(szText); // REVIEW, should we not remove from the end of bNonEmpty = lstrlen(szText); // BUGBUG (DavePl) Not a bug, but this isn't BOOL } else bNonEmpty = lstrlen(pszText); EnableWindow(GetDlgItem(hDlg, IDOK), bNonEmpty); if (bNonEmpty) { SendMessage(hDlg, DM_SETDEFID, IDOK, 0L); } }
void CSearchDialog::StartSearching() { ShowWindow(GetDlgItem(m_hDlg, IDC_LINK_STATUS), SW_HIDE); ShowWindow(GetDlgItem(m_hDlg, IDC_STATIC_STATUS), SW_SHOW); m_AwaitingSearchItems.clear(); m_SearchItemsMapInternal.clear(); ListView_DeleteAllItems(GetDlgItem(m_hDlg, IDC_LISTVIEW_SEARCHRESULTS)); TCHAR szBaseDirectory[MAX_PATH]; TCHAR szSearchPattern[MAX_PATH]; /* Get the directory and name, and remove leading and trailing whitespace. */ /* TODO: Verify fields. */ GetDlgItemText(m_hDlg, IDC_COMBO_DIRECTORY, szBaseDirectory, SIZEOF_ARRAY(szBaseDirectory)); PathRemoveBlanks(szBaseDirectory); GetDlgItemText(m_hDlg, IDC_COMBO_NAME, szSearchPattern, SIZEOF_ARRAY(szSearchPattern)); PathRemoveBlanks(szSearchPattern); BOOL bSearchSubFolders = IsDlgButtonChecked(m_hDlg, IDC_CHECK_SEARCHSUBFOLDERS) == BST_CHECKED; BOOL bUseRegularExpressions = IsDlgButtonChecked(m_hDlg, IDC_CHECK_USEREGULAREXPRESSIONS) == BST_CHECKED; BOOL bCaseInsensitive = IsDlgButtonChecked(m_hDlg, IDC_CHECK_CASEINSENSITIVE) == BST_CHECKED; /* Turn search patterns of the form '???' into '*???*', and use this modified string to search. */ if(!bUseRegularExpressions && lstrlen(szSearchPattern) > 0) { if(szSearchPattern[0] != '*' && szSearchPattern[lstrlen(szSearchPattern) - 1] != '*') { TCHAR szTemp[MAX_PATH]; StringCchPrintf(szTemp, SIZEOF_ARRAY(szTemp), _T("*%s*"), szSearchPattern); StringCchCopy(szSearchPattern, SIZEOF_ARRAY(szSearchPattern), szTemp); } } DWORD dwAttributes = 0; if(IsDlgButtonChecked(m_hDlg, IDC_CHECK_ARCHIVE) == BST_CHECKED) dwAttributes |= FILE_ATTRIBUTE_ARCHIVE; if(IsDlgButtonChecked(m_hDlg, IDC_CHECK_HIDDEN) == BST_CHECKED) dwAttributes |= FILE_ATTRIBUTE_HIDDEN; if(IsDlgButtonChecked(m_hDlg, IDC_CHECK_READONLY) == BST_CHECKED) dwAttributes |= FILE_ATTRIBUTE_READONLY; if(IsDlgButtonChecked(m_hDlg, IDC_CHECK_SYSTEM) == BST_CHECKED) dwAttributes |= FILE_ATTRIBUTE_SYSTEM; m_pSearch = new CSearch(m_hDlg, szBaseDirectory, szSearchPattern, dwAttributes, bUseRegularExpressions, bCaseInsensitive, bSearchSubFolders); m_pSearch->AddRef(); /* Save the search directory and search pattern (only if they are not the same as the most recent entry). */ BOOL bSaveEntry = FALSE; if(m_sdps->m_pSearchDirectories->empty() || lstrcmp(szBaseDirectory, m_sdps->m_pSearchDirectories->begin()->c_str()) != 0) { bSaveEntry = TRUE; } if(bSaveEntry) { SaveEntry(IDC_COMBO_DIRECTORY, *m_sdps->m_pSearchDirectories); } bSaveEntry = FALSE; if(m_sdps->m_pSearchPatterns->empty() || lstrcmp(szSearchPattern, m_sdps->m_pSearchPatterns->begin()->c_str()) != 0) { bSaveEntry = TRUE; } if(bSaveEntry) { SaveEntry(IDC_COMBO_NAME, *m_sdps->m_pSearchPatterns); } GetDlgItemText(m_hDlg, IDSEARCH, m_szSearchButton, SIZEOF_ARRAY(m_szSearchButton)); TCHAR szTemp[64]; LoadString(GetInstance(), IDS_STOP, szTemp, SIZEOF_ARRAY(szTemp)); SetDlgItemText(m_hDlg, IDSEARCH, szTemp); m_bSearching = TRUE; /* Create a background thread, and search using it... */ HANDLE hThread = CreateThread(NULL, 0, NSearchDialog::SearchThread, reinterpret_cast<LPVOID>(m_pSearch), 0, NULL); CloseHandle(hThread); }
void CSearchDialog::OnSearch() { if(!m_bSearching) { ShowWindow(GetDlgItem(m_hDlg,IDC_LINK_STATUS),SW_HIDE); ShowWindow(GetDlgItem(m_hDlg,IDC_STATIC_STATUS),SW_SHOW); m_AwaitingSearchItems.clear(); m_SearchItemsMapInternal.clear(); ListView_DeleteAllItems(GetDlgItem(m_hDlg,IDC_LISTVIEW_SEARCHRESULTS)); TCHAR szBaseDirectory[MAX_PATH]; TCHAR szSearchPattern[MAX_PATH]; /* Get the directory and name, and remove leading and trailing whitespace. */ GetDlgItemText(m_hDlg,IDC_COMBO_DIRECTORY,szBaseDirectory, SIZEOF_ARRAY(szBaseDirectory)); PathRemoveBlanks(szBaseDirectory); GetDlgItemText(m_hDlg,IDC_COMBO_NAME,szSearchPattern, SIZEOF_ARRAY(szSearchPattern)); PathRemoveBlanks(szSearchPattern); BOOL bSearchSubFolders = IsDlgButtonChecked(m_hDlg,IDC_CHECK_SEARCHSUBFOLDERS) == BST_CHECKED; BOOL bUseRegularExpressions = IsDlgButtonChecked(m_hDlg,IDC_CHECK_USEREGULAREXPRESSIONS) == BST_CHECKED; BOOL bCaseInsensitive = IsDlgButtonChecked(m_hDlg,IDC_CHECK_CASEINSENSITIVE) == BST_CHECKED; /* Turn search patterns of the form '???' into '*???*', and use this modified string to search. */ if(!bUseRegularExpressions && lstrlen(szSearchPattern) > 0) { if(szSearchPattern[0] != '*' && szSearchPattern[lstrlen(szSearchPattern) - 1] != '*') { TCHAR szTemp[MAX_PATH]; StringCchPrintf(szTemp,SIZEOF_ARRAY(szTemp),_T("*%s*"), szSearchPattern); StringCchCopy(szSearchPattern,SIZEOF_ARRAY(szSearchPattern), szTemp); } } DWORD dwAttributes = 0; if(IsDlgButtonChecked(m_hDlg,IDC_CHECK_ARCHIVE) == BST_CHECKED) dwAttributes |= FILE_ATTRIBUTE_ARCHIVE; if(IsDlgButtonChecked(m_hDlg,IDC_CHECK_HIDDEN) == BST_CHECKED) dwAttributes |= FILE_ATTRIBUTE_HIDDEN; if(IsDlgButtonChecked(m_hDlg,IDC_CHECK_READONLY) == BST_CHECKED) dwAttributes |= FILE_ATTRIBUTE_READONLY; if(IsDlgButtonChecked(m_hDlg,IDC_CHECK_SYSTEM) == BST_CHECKED) dwAttributes |= FILE_ATTRIBUTE_SYSTEM; m_pSearch = new CSearch(m_hDlg,szBaseDirectory,szSearchPattern, dwAttributes,bUseRegularExpressions,bCaseInsensitive,bSearchSubFolders); m_pSearch->AddRef(); /* Save the search directory and search pattern (only if they are not the same as the most recent entry). */ BOOL bSaveEntry = FALSE; if(m_sdps->m_SearchDirectories.empty() || lstrcmp(szBaseDirectory, m_sdps->m_SearchDirectories.begin()->c_str()) != 0) { bSaveEntry = TRUE; } if(bSaveEntry) { /* TODO: Switch to circular buffer. */ m_sdps->m_SearchDirectories.push_front(szBaseDirectory); HWND hComboBox = GetDlgItem(m_hDlg,IDC_COMBO_DIRECTORY); SendMessage(hComboBox,CB_INSERTSTRING,0,reinterpret_cast<LPARAM>(szBaseDirectory)); ComboBox_SetCurSel(hComboBox,0); } bSaveEntry = FALSE; if(m_sdps->m_pSearchPatterns->empty() || lstrcmp(szSearchPattern,m_sdps->m_pSearchPatterns->begin()->c_str()) != 0) { bSaveEntry = TRUE; } if(bSaveEntry) { TCHAR szSearchPatternOriginal[MAX_PATH]; GetDlgItemText(m_hDlg,IDC_COMBO_NAME,szSearchPatternOriginal, SIZEOF_ARRAY(szSearchPatternOriginal)); std::wstring strSearchPatternOriginal(szSearchPatternOriginal); auto itr = std::find_if(m_sdps->m_pSearchPatterns->begin(),m_sdps->m_pSearchPatterns->end(), [strSearchPatternOriginal](const std::wstring Pattern){return Pattern.compare(strSearchPatternOriginal) == 0;}); HWND hComboBox = GetDlgItem(m_hDlg,IDC_COMBO_NAME); ComboBox_SetCurSel(hComboBox,-1); /* Remove the current element from both the list and the combo box. It will be reinserted at the front of both below. */ if(itr != m_sdps->m_pSearchPatterns->end()) { auto index = std::distance(m_sdps->m_pSearchPatterns->begin(),itr); SendMessage(hComboBox,CB_DELETESTRING,index,0); m_sdps->m_pSearchPatterns->erase(itr); } m_sdps->m_pSearchPatterns->push_front(szSearchPatternOriginal); SendMessage(hComboBox,CB_INSERTSTRING,0,reinterpret_cast<LPARAM>(szSearchPatternOriginal)); ComboBox_SetCurSel(hComboBox,0); ComboBox_SetEditSel(hComboBox,-1,-1); if(ComboBox_GetCount(hComboBox) > m_sdps->m_pSearchPatterns->capacity()) { SendMessage(hComboBox,CB_DELETESTRING,ComboBox_GetCount(hComboBox) - 1,0); } } GetDlgItemText(m_hDlg,IDSEARCH,m_szSearchButton,SIZEOF_ARRAY(m_szSearchButton)); TCHAR szTemp[64]; LoadString(GetInstance(),IDS_STOP,szTemp,SIZEOF_ARRAY(szTemp)); SetDlgItemText(m_hDlg,IDSEARCH,szTemp); m_bSearching = TRUE; /* Create a background thread, and search using it... */ HANDLE hThread = CreateThread(NULL,0,NSearchDialog::SearchThread, reinterpret_cast<LPVOID>(m_pSearch),0,NULL); CloseHandle(hThread); } else { m_bStopSearching = TRUE; if(m_pSearch != NULL) { /* Note that m_pSearch does not need to be released here. Once the search object finishes, it will send a WM_APP_SEARCHFINISHED message. The handler for this message will then release m_pSearch. */ m_pSearch->StopSearching(); } } }
BOOL OKPushed(LPRUNDLG_DATA lprd) { HWND hwndOwner; TCHAR szText[MAX_PATH]; TCHAR szTitle[64]; DWORD dwFlags; int showcmd; BOOL fSuccess; int iRun; HWND hDlg = lprd->hDlg; #ifdef WINNT TCHAR szNotExp[ MAX_PATH ]; #endif if (lprd->fDone) return TRUE; // Get out of the "synchronized input queues" state if (lprd->dwThreadId) { AttachThreadInput(GetCurrentThreadId(), lprd->dwThreadId, FALSE); } /* Get the command line and dialog title. */ #ifdef WINNT GetDlgItemText(hDlg, IDD_COMMAND, szNotExp, ARRAYSIZE(szNotExp)); PathRemoveBlanks(szNotExp);// REVIEW, should we not remove from the end of // the cmd line? ExpandEnvironmentStrings( szNotExp, szText, ARRAYSIZE(szText)); szText[ ARRAYSIZE(szText)-1 ] = (TCHAR)0; #else GetDlgItemText(hDlg, IDD_COMMAND, szText, ARRAYSIZE(szText)); PathRemoveBlanks(szText); // REVIEW, should we not remove from the end of // the cmd line? #endif GetWindowText(hDlg, szTitle, ARRAYSIZE(szTitle)); // Hide this dialog (REVIEW, to avoid save bits window flash) SetWindowPos(hDlg, 0, 0, 0, 0, 0, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER); #ifdef SHOWSTATES showcmd = pnStates[(int)SendDlgItemMessage(hDlg, IDD_STATE, CB_GETCURSEL, 0, 0L)]; #else showcmd = SW_SHOWNORMAL; #endif // // HACK: We need to activate the owner window before we call // ShellexecCmdLine, so that our folder DDE code can find an // explorer window as the ForegroundWindow. // hwndOwner = GetWindow(hDlg, GW_OWNER); if (hwndOwner) { SetActiveWindow(hwndOwner); } else { hwndOwner = hDlg; } iRun = RunDlgNotifyParent(hDlg, hwndOwner, szText, lprd->lpszWorkingDir, showcmd); switch (iRun) { case RFR_NOTHANDLED: if (lprd->dwFlags & RFD_USEFULLPATHDIR) { dwFlags = SECL_USEFULLPATHDIR; } else { dwFlags = 0; } #ifdef WINNT if ((!(lprd->dwFlags & RFD_NOSEPMEMORY_BOX)) && (lprd->dwFlags & RFD_WOW_APP)) { if (IsDlgButtonChecked( hDlg, IDD_RUNINSEPARATE ) == 1 ) { dwFlags |= SECL_SEPARATE_VDM; } } #endif fSuccess = ShellExecCmdLine( hwndOwner, szText, lprd->lpszWorkingDir, showcmd, szTitle, dwFlags ); break; case RFR_SUCCESS: fSuccess = TRUE; break; case RFR_FAILURE: fSuccess = FALSE; break; } // Get back into "synchronized input queues" state if (lprd->dwThreadId) { AttachThreadInput(GetCurrentThreadId(), lprd->dwThreadId, TRUE); } if (fSuccess) { #ifdef WINNT wsprintf(szNotExp + lstrlen(szNotExp), TEXT("%c%d"), CHAR_FIELDSEP, showcmd); AddMRUString(g_hMRURunDlg, szNotExp); #else wsprintf(szText + lstrlen(szText), TEXT("%c%d"), CHAR_FIELDSEP, showcmd); AddMRUString(g_hMRURunDlg, szText); #endif /* Everything went OK */ return(TRUE); } // Something went wrong. Put the dialog back up. SetWindowPos(hDlg, 0, 0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER); SetFocus(GetDlgItem(hDlg, IDD_COMMAND)); return(FALSE); }
// // Do checking of the .exe type in the background so the UI doesn't // get hung up while we scan. This is particularly important with // the .exe is over the network or on a floppy. // void CheckRunInSeparateThread( LPVOID lpVoid ) { LONG lBinaryType; DWORD cch; LPTSTR lpszFilePart; TCHAR szFile[MAX_PATH+1]; TCHAR szFullFile[MAX_PATH+1]; TCHAR szExp[MAX_PATH+1]; HWND hDlg = (HWND)lpVoid; BOOL fCheck = TRUE, fEnable = FALSE; DebugMsg( DM_TRACE, TEXT("CheckRunInSeparateThread created and running") ); while( g_bCheckRunInSep ) { WaitForSingleObject( g_hCheckNow, INFINITE ); ResetEvent( g_hCheckNow ); if (g_bCheckRunInSep) { LPRUNDLG_DATA lprd; LPTSTR pszT; BOOL f16bit = FALSE; szFile[0] = TEXT('\0'); szFullFile[0] = TEXT('\0'); cch = 0; GetWindowText( GetDlgItem( hDlg, IDD_COMMAND ), szFile, MAX_PATH ); // Remove & throw away arguments PathRemoveBlanks(szFile); if (PathIsUNC(szFile) || IsRemoteDrive(DRIVEID(szFile))) { f16bit = TRUE; fCheck = FALSE; fEnable = TRUE; goto ChangeTheBox; } // if the unquoted sting exists as a file just use it if (!PathFileExists(szFile)) { pszT = PathGetArgs(szFile); if (*pszT) *(pszT - 1) = TEXT('\0'); PathUnquoteSpaces(szFile); } if (szFile[0]) { ExpandEnvironmentStrings( szFile, szExp, MAX_PATH ); szExp[ MAX_PATH ] = TEXT('\0'); if (PathIsUNC(szExp) || IsRemoteDrive(DRIVEID(szExp))) { f16bit = TRUE; fCheck = FALSE; fEnable = TRUE; goto ChangeTheBox; } cch = SearchPath( NULL, szExp, TEXT(".EXE"), MAX_PATH+1, szFullFile, &lpszFilePart ); } if ((cch != 0) && (cch <= MAX_PATH)) { if ( (GetBinaryType( szFullFile, &lBinaryType) && (lBinaryType==SCS_WOW_BINARY)) ) { f16bit = TRUE; fCheck = FALSE; fEnable = TRUE; } else { f16bit = FALSE; fCheck = TRUE; fEnable = FALSE; } } else { f16bit = FALSE; fCheck = TRUE; fEnable = FALSE; } ChangeTheBox: CheckDlgButton( hDlg, IDD_RUNINSEPARATE, fCheck ? 1 : 0 ); EnableWindow( GetDlgItem( hDlg, IDD_RUNINSEPARATE ), fEnable ); ENTERCRITICAL; lprd = (LPRUNDLG_DATA)GetWindowLong(hDlg, DWL_USER); if (lprd) { if (f16bit) lprd->dwFlags |= RFD_WOW_APP; else lprd->dwFlags &= (~RFD_WOW_APP); } LEAVECRITICAL; } } CloseHandle( g_hCheckNow ); g_hCheckNow = NULL; DebugMsg( DM_TRACE, TEXT("CheckRunInSeparateThread exiting now...") ); ExitThread( 0 ); }