diff --git a/MainDlg.cpp b/MainDlg.cpp index c4ab782..e6a36f2 100644 --- a/MainDlg.cpp +++ b/MainDlg.cpp @@ -194,6 +194,63 @@ void CMainDlg::OnDropFiles(HDROP hDropInfo) { DragFinish(hDropInfo); } +void CMainDlg::OnPickFile(UINT uNotifyCode, int nID, CWindow wndCtl) { + // https://learn.microsoft.com/en-us/windows/win32/shell/common-file-dialog#basic-usage + + CComPtr pfd; + HRESULT hr = pfd.CoCreateInstance(CLSID_FileOpenDialog, nullptr, + CLSCTX_INPROC_SERVER); + if (FAILED(hr)) { + return; + } + + // Get options. + DWORD dwFlags; + hr = pfd->GetOptions(&dwFlags); + if (FAILED(hr)) { + return; + } + + // Get shell items only for file system items. + hr = pfd->SetOptions(dwFlags | FOS_FORCEFILESYSTEM); + if (FAILED(hr)) { + return; + } + + // Set the file types. + const COMDLG_FILTERSPEC fileTypes[] = { + {L"Executable files (*.dll;*.exe)", L"*.dll;*.exe"}, + {L"All files (*.*)", L"*.*"}, + }; + + hr = pfd->SetFileTypes(ARRAYSIZE(fileTypes), fileTypes); + if (FAILED(hr)) { + return; + } + + hr = pfd->SetTitle(L"Browse"); + if (FAILED(hr)) { + return; + } + + // Show the dialog. + hr = pfd->Show(m_hWnd); + if (FAILED(hr)) { + return; + } + + CComPtr psiResult; + hr = pfd->GetResult(&psiResult); + if (SUCCEEDED(hr)) { + CComHeapPtr pszFilePath; + hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); + if (SUCCEEDED(hr)) { + // Set the file name on the textbox. + SetDlgItemText(IDC_TARGET_EXECUTABLE, pszFilePath); + } + } +} + void CMainDlg::OnAppAbout(UINT uNotifyCode, int nID, CWindow wndCtl) { PCWSTR content = L"A tool to get symbols from executables the same way Windhawk mods do " @@ -390,64 +447,3 @@ LRESULT CMainDlg::OnEnumSymbolsDone(UINT uMsg, WPARAM wParam, LPARAM lParam) { return 0; } -const COMDLG_FILTERSPEC file_types[] = { - {L"Supported Files (*.dll;*.exe)", L"*.dll;*.exe"}, - {L"All Files (*.*)", L"*.*"}, -}; - -LRESULT CMainDlg::OnBnClickedPickfile(WORD /*wNotifyCode*/, - WORD /*wID*/, - HWND /*hWndCtl*/, - BOOL& /*bHandled*/) { - // https://learn.microsoft.com/en-us/windows/win32/shell/common-file-dialog#basic-usage - - CComPtr pfd; - HRESULT hr = pfd.CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER); - - if (FAILED(hr)) - return E_FAIL; - - // get options - DWORD dwFlags; - hr = pfd->GetOptions(&dwFlags); - if (FAILED(hr)) - return E_FAIL; - - // get shell items only for file system items. - hr = pfd->SetOptions(dwFlags | FOS_FORCEFILESYSTEM); - if (FAILED(hr)) - return E_FAIL; - - // set the file types - hr = pfd->SetFileTypes(ARRAYSIZE(file_types), file_types); - if (FAILED(hr)) - return E_FAIL; - - // the first element from the array - hr = pfd->SetFileTypeIndex(1); - if (FAILED(hr)) - return E_FAIL; - - pfd->SetTitle(L"Browse"); - if (FAILED(hr)) - return E_FAIL; - - // Show the dialog - hr = pfd->Show(this->m_hWnd); - if (FAILED(hr)) - return E_FAIL; - - CComPtr psiResult; - hr = pfd->GetResult(&psiResult); - if (SUCCEEDED(hr)) { - PWSTR pszFilePath = NULL; - hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); - if (SUCCEEDED(hr)) { - // set the file name on the textbox - CEdit(GetDlgItem(IDC_TARGET_EXECUTABLE)).SetWindowText(pszFilePath); - - CoTaskMemFree(pszFilePath); - } - } - return 0; -} \ No newline at end of file diff --git a/MainDlg.h b/MainDlg.h index f96596f..75a6e2b 100644 --- a/MainDlg.h +++ b/MainDlg.h @@ -37,13 +37,13 @@ class CMainDlg : public CDialogImpl, MSG_WM_INITDIALOG(OnInitDialog) MSG_WM_DESTROY(OnDestroy) MSG_WM_DROPFILES(OnDropFiles) + COMMAND_ID_HANDLER_EX(IDC_PICKFILE, OnPickFile) COMMAND_ID_HANDLER_EX(ID_APP_ABOUT, OnAppAbout) COMMAND_ID_HANDLER_EX(IDOK, OnOK) COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel) MESSAGE_HANDLER_EX(UWM_PROGRESS, OnProgress) MESSAGE_HANDLER_EX(UWM_ENUM_SYMBOLS_DONE, OnEnumSymbolsDone) CHAIN_COMMANDS_MEMBER(m_resultsEdit) - COMMAND_HANDLER(IDC_PICKFILE, BN_CLICKED, OnBnClickedPickfile) END_MSG_MAP() BOOL PreTranslateMessage(MSG* pMsg) override; @@ -51,6 +51,7 @@ class CMainDlg : public CDialogImpl, BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam); void OnDestroy(); void OnDropFiles(HDROP hDropInfo); + void OnPickFile(UINT uNotifyCode, int nID, CWindow wndCtl); void OnAppAbout(UINT uNotifyCode, int nID, CWindow wndCtl); void OnOK(UINT uNotifyCode, int nID, CWindow wndCtl); void OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl); @@ -63,10 +64,4 @@ class CMainDlg : public CDialogImpl, std::optional m_enumSymbolsThread; CString m_enumSymbolsResult; - - public: - LRESULT OnBnClickedPickfile(WORD /*wNotifyCode*/, - WORD /*wID*/, - HWND /*hWndCtl*/, - BOOL& /*bHandled*/); }; diff --git a/resource.h b/resource.h index a028a90..3e64488 100644 --- a/resource.h +++ b/resource.h @@ -2,7 +2,6 @@ // Microsoft Visual C++ generated include file. // Used by windhawk-symbol-helper.rc // -#define IDCANCEL2 3 #define IDR_MAINFRAME 128 #define IDD_MAINDLG 129 #define IDC_STATIC_ENGINE_DIR 1000 @@ -13,13 +12,13 @@ #define IDC_SYMBOL_SERVER 1005 #define IDC_STATIC_TARGET_EXECUTABLE 1006 #define IDC_TARGET_EXECUTABLE 1007 -#define IDC_UNDECORATED 1008 -#define IDC_DECORATED 1009 -#define IDC_LOG 1010 -#define IDC_STATIC_RESULTS 1011 -#define IDC_RESULTS 1012 -#define IDC_RESULTS_PLACEHOLDER 1013 -#define IDC_PICKFILE 1014 +#define IDC_PICKFILE 1008 +#define IDC_UNDECORATED 1009 +#define IDC_DECORATED 1010 +#define IDC_LOG 1011 +#define IDC_STATIC_RESULTS 1012 +#define IDC_RESULTS 1013 +#define IDC_RESULTS_PLACEHOLDER 1014 // Next default values for new objects // diff --git a/windhawk-symbol-helper.rc b/windhawk-symbol-helper.rc index e7308fa..9d2bc02 100644 --- a/windhawk-symbol-helper.rc +++ b/windhawk-symbol-helper.rc @@ -75,13 +75,13 @@ BEGIN LTEXT "Symbol ser&ver:",IDC_STATIC_SYMBOL_SERVER,7,61,263,8 EDITTEXT IDC_SYMBOL_SERVER,7,71,263,12,ES_AUTOHSCROLL LTEXT "Target e&xecutable:",IDC_STATIC_TARGET_EXECUTABLE,7,88,263,8 - EDITTEXT IDC_TARGET_EXECUTABLE,7,98,210,12,ES_AUTOHSCROLL + EDITTEXT IDC_TARGET_EXECUTABLE,7,98,208,12,ES_AUTOHSCROLL + PUSHBUTTON "&Browse...",IDC_PICKFILE,218,97,50,14 CONTROL "&Undecorated",IDC_UNDECORATED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,115,55,10 CONTROL "&Decorated",IDC_DECORATED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,65,115,47,10 CONTROL "&Log",IDC_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,116,115,27,10 LTEXT "&Results:",IDC_STATIC_RESULTS,7,130,263,8 LTEXT "Static",IDC_RESULTS_PLACEHOLDER,7,140,263,129,NOT WS_VISIBLE - PUSHBUTTON "&Browse...",IDC_PICKFILE,218,98,50,14 END