Skip to content

Commit

Permalink
File picker adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
m417z committed Apr 15, 2024
1 parent b14005b commit 6522c28
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 78 deletions.
118 changes: 57 additions & 61 deletions MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFileDialog> 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<IShellItem> psiResult;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr)) {
CComHeapPtr<WCHAR> 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 "
Expand Down Expand Up @@ -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<IFileDialog> 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<IShellItem> 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;
}
9 changes: 2 additions & 7 deletions MainDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ class CMainDlg : public CDialogImpl<CMainDlg>,
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;

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);
Expand All @@ -63,10 +64,4 @@ class CMainDlg : public CDialogImpl<CMainDlg>,

std::optional<std::jthread> m_enumSymbolsThread;
CString m_enumSymbolsResult;

public:
LRESULT OnBnClickedPickfile(WORD /*wNotifyCode*/,
WORD /*wID*/,
HWND /*hWndCtl*/,
BOOL& /*bHandled*/);
};
15 changes: 7 additions & 8 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
//
Expand Down
4 changes: 2 additions & 2 deletions windhawk-symbol-helper.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 6522c28

Please sign in to comment.