Reputation: 1
I have created a hidden C++ console application in Code::Blocks. So, taskbar icon of application is not visible during execution.
I want to hide the taskbar icon of a GetOpenFileNameW()
dialog.
Here is the code I have written to open that dialog:
#include "iostream"
#include "string_operations.h"
using namespace std;
///--- variables ---///
//-- HMODULE --//
HMODULE hmComDlg32;
//-- HWND --//
HWND hwndApplication;
//-- OPENFILENAMEW --//
OPENFILENAMEW ofn;
//-- size_t --//
size_t szSizeOfSelectedFilePaths;
//-- string --//
string strSelectedFilePath;
//-- vector<string> --//
vector<string> v_strSelectedFilePaths;
//-- wchar_t* --//
wchar_t* p_wcSelectedFilePaths;
int main()
{
ZeroMemory(&ofn, sizeof(ofn));
hwndApplication = GetConsoleWindow();
p_wcSelectedFilePaths = new wchar_t[MAX_PATH];
memset(p_wcSelectedFilePaths, 0, MAX_PATH * sizeof(wchar_t));
ofn = {0};
ofn.Flags = OFN_ALLOWMULTISELECT | OFN_DONTADDTORECENT | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
ofn.hwndOwner = hwndApplication;
ofn.lpstrFile = p_wcSelectedFilePaths;
ofn.lpstrFilter = L"JSON Files (*.json)\0*.json\0PAS Files (*.pas)\0*.pas\0";
ofn.lpstrTitle = L"Choose files.";
ofn.lStructSize = sizeof(ofn);
ofn.nMaxFile = MAX_PATH;
hmComDlg32 = LoadLibraryW(L"ComDlg32.dll");
if(hmComDlg32)
{
typedef WINBOOL (WINAPI *tdGetOpenFileNameW)(LPOPENFILENAMEW);
tdGetOpenFileNameW fnGetOpenFileNameW = (tdGetOpenFileNameW)GetProcAddress(hmComDlg32, "GetOpenFileNameW");
if(fnGetOpenFileNameW)
{
if(fnGetOpenFileNameW(&ofn))
{
while(*p_wcSelectedFilePaths)
{
szSizeOfSelectedFilePaths = wcslen(p_wcSelectedFilePaths);
strSelectedFilePath = WideStringToUtf8String(wstring(p_wcSelectedFilePaths));
v_strSelectedFilePaths.push_back(strSelectedFilePath);
p_wcSelectedFilePaths += szSizeOfSelectedFilePaths + 1;
}
}
}
FreeLibrary(hmComDlg32);
}
delete [] p_wcSelectedFilePaths;
return 0;
}
But, the dialog displays an icon in the Taskbar:
How can I hide that icon?
Upvotes: -1
Views: 99
Reputation: 598174
You need to use the OPENFILENAMEW::hwndOwner
field to specify an owner for the dialog window. The owner can be a hidden window that does not have a Taskbar button.
Upvotes: 0