Skip to content

Commit

Permalink
Merge pull request #2 from rounk-ctrl/main
Browse files Browse the repository at this point in the history
Add file picker for target executable
  • Loading branch information
m417z authored Apr 14, 2024
2 parents 10b0764 + b94d397 commit b14005b
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 6 deletions.
61 changes: 61 additions & 0 deletions MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,64 @@ 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;
}
8 changes: 8 additions & 0 deletions MainDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CMainDlg : public CDialogImpl<CMainDlg>,
DLGRESIZE_CONTROL(IDC_SYMBOL_SERVER, DLSZ_SIZE_X)
DLGRESIZE_CONTROL(IDC_STATIC_TARGET_EXECUTABLE, DLSZ_SIZE_X)
DLGRESIZE_CONTROL(IDC_TARGET_EXECUTABLE, DLSZ_SIZE_X)
DLGRESIZE_CONTROL(IDC_PICKFILE, DLSZ_MOVE_X)
DLGRESIZE_CONTROL(IDC_STATIC_RESULTS, DLSZ_SIZE_X)
DLGRESIZE_CONTROL(IDC_RESULTS, DLSZ_SIZE_X | DLSZ_SIZE_Y)
DLGRESIZE_CONTROL(IDOK, DLSZ_MOVE_Y)
Expand All @@ -42,6 +43,7 @@ class CMainDlg : public CDialogImpl<CMainDlg>,
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;
Expand All @@ -61,4 +63,10 @@ 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*/);
};
4 changes: 4 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="wtl" version="10.0.10320" targetFramework="native" />
</packages>
4 changes: 3 additions & 1 deletion resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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 @@ -18,14 +19,15 @@
#define IDC_STATIC_RESULTS 1011
#define IDC_RESULTS 1012
#define IDC_RESULTS_PLACEHOLDER 1013
#define IDC_PICKFILE 1014

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 202
#define _APS_NEXT_COMMAND_VALUE 32776
#define _APS_NEXT_CONTROL_VALUE 1014
#define _APS_NEXT_CONTROL_VALUE 1015
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
3 changes: 2 additions & 1 deletion windhawk-symbol-helper.rc
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +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,263,12,ES_AUTOHSCROLL
EDITTEXT IDC_TARGET_EXECUTABLE,7,98,210,12,ES_AUTOHSCROLL
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
18 changes: 14 additions & 4 deletions windhawk-symbol-helper.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>C:\WTL10\Include;$(ProjectDir)libraries;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)libraries;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)libraries;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>C:\WTL10\Include;$(ProjectDir)libraries;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)libraries;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)libraries;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>C:\WTL10\Include;$(ProjectDir)libraries;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)libraries;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)libraries;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>C:\WTL10\Include;$(ProjectDir)libraries;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)libraries;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)libraries;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down Expand Up @@ -243,7 +243,17 @@
<ItemGroup>
<Image Include="res\windhawk-symbol-helper.ico" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="packages\wtl.10.0.10320\build\native\wtl.targets" Condition="Exists('packages\wtl.10.0.10320\build\native\wtl.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\wtl.10.0.10320\build\native\wtl.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\wtl.10.0.10320\build\native\wtl.targets'))" />
</Target>
</Project>
3 changes: 3 additions & 0 deletions windhawk-symbol-helper.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

0 comments on commit b14005b

Please sign in to comment.