Skip to content

Commit

Permalink
Add modeless support. Also resize list view columns when resizing the…
Browse files Browse the repository at this point in the history
… dialog.
  • Loading branch information
chrdavis committed Nov 4, 2019
1 parent 76cca4e commit 9b88051
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
56 changes: 53 additions & 3 deletions SmartRenameUI/SmartRenameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ HRESULT CSmartRenameUI::s_CreateInstance(_In_ ISmartRenameManager* psrm, _In_opt
// ISmartRenameUI
IFACEMETHODIMP CSmartRenameUI::Show(_In_opt_ HWND hwndParent)
{
return _DoModal(hwndParent);
return _DoModeless(hwndParent);
}

IFACEMETHODIMP CSmartRenameUI::Close()
Expand Down Expand Up @@ -354,12 +354,24 @@ void CSmartRenameUI::_OnCloseDlg()
{
// Persist the current settings
_WriteSettings();
EndDialog(m_hwnd, 1);
if (m_modeless)
{
DestroyWindow(m_hwnd);
}
else
{
EndDialog(m_hwnd, 1);
}
}

void CSmartRenameUI::_OnDestroyDlg()
{
_Cleanup();

if (m_modeless)
{
PostQuitMessage(0);
}
}

void CSmartRenameUI::_OnRename()
Expand All @@ -384,6 +396,7 @@ void CSmartRenameUI::_OnAbout()

HRESULT CSmartRenameUI::_DoModal(__in_opt HWND hwnd)
{
m_modeless = false;
HRESULT hr = S_OK;
INT_PTR ret = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_MAIN), hwnd, s_DlgProc, (LPARAM)this);
if (ret < 0)
Expand All @@ -393,6 +406,33 @@ HRESULT CSmartRenameUI::_DoModal(__in_opt HWND hwnd)
return hr;
}

HRESULT CSmartRenameUI::_DoModeless(__in_opt HWND hwnd)
{
m_modeless = true;
HRESULT hr = S_OK;
if (NULL != CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MAIN), hwnd, s_DlgProc, (LPARAM)this))
{
ShowWindow(m_hwnd, SW_SHOWNORMAL);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if (!IsDialogMessage(m_hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

DestroyWindow(m_hwnd);
m_hwnd = NULL;
}
else
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
return hr;
}

INT_PTR CSmartRenameUI::_DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
INT_PTR bRet = TRUE; // default for all handled cases in switch below
Expand Down Expand Up @@ -618,6 +658,8 @@ void CSmartRenameUI::_OnSize(_In_ WPARAM wParam)
{
_MoveControl(g_repositionMap[u].id, g_repositionMap[u].flags, xDelta, yDelta);
}

m_listview.OnSize();
}
}

Expand Down Expand Up @@ -784,7 +826,7 @@ void CSmartRenameListView::Init(_In_ HWND hwndLV)
SetWindowLongPtr(m_hwndLV, GWL_STYLE, dwLVStyle);

// Set the extended view styles
ListView_SetExtendedListViewStyle(m_hwndLV, LVS_EX_CHECKBOXES | LVS_EX_DOUBLEBUFFER);
ListView_SetExtendedListViewStyle(m_hwndLV, LVS_EX_CHECKBOXES | LVS_EX_DOUBLEBUFFER | LVS_EX_AUTOSIZECOLUMNS);

// Get the system image lists. Our list view is setup to not destroy
// these since the image list belongs to the entire explorer process
Expand Down Expand Up @@ -966,6 +1008,14 @@ void CSmartRenameListView::GetDisplayInfo(_In_ ISmartRenameManager* psrm, _Inout
}
}

void CSmartRenameListView::OnSize()
{
RECT rc = { 0 };
GetClientRect(m_hwndLV, &rc);
ListView_SetColumnWidth(m_hwndLV, 0, RECT_WIDTH(rc) / 2);
ListView_SetColumnWidth(m_hwndLV, 1, RECT_WIDTH(rc) / 2);
}

void CSmartRenameListView::RedrawItems(_In_ int first, _In_ int last)
{
ListView_RedrawItems(m_hwndLV, first, last);
Expand Down
3 changes: 3 additions & 0 deletions SmartRenameUI/SmartRenameUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CSmartRenameListView
void OnKeyDown(_In_ ISmartRenameManager* psrm, _In_ LV_KEYDOWN* lvKeyDown);
void OnClickList(_In_ ISmartRenameManager* psrm, NM_LISTVIEW* pnmListView);
void GetDisplayInfo(_In_ ISmartRenameManager* psrm, _Inout_ LV_DISPINFO* plvdi);
void OnSize();
HWND GetHWND() { return m_hwndLV; }

private:
Expand Down Expand Up @@ -76,6 +77,7 @@ class CSmartRenameUI :
}

HRESULT _DoModal(__in_opt HWND hwnd);
HRESULT _DoModeless(__in_opt HWND hwnd);

static INT_PTR CALLBACK s_DlgProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
Expand Down Expand Up @@ -120,6 +122,7 @@ class CSmartRenameUI :
bool m_initialized = false;
bool m_enableDragDrop = false;
bool m_disableCountUpdate = false;
bool m_modeless = true;
HWND m_hwnd = nullptr;
HWND m_hwndLV = nullptr;
HICON m_iconMain = nullptr;
Expand Down

0 comments on commit 9b88051

Please sign in to comment.