Skip to content

Commit

Permalink
Merge pull request microsoft#655 from chrdavis/master
Browse files Browse the repository at this point in the history
Switch to modeless experience and resize list view columns on dialog size
  • Loading branch information
chrdavis authored Nov 4, 2019
2 parents ea3cb02 + 389590e commit 1d3acbe
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
57 changes: 54 additions & 3 deletions src/modules/powerrename/ui/PowerRenameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ HRESULT CPowerRenameUI::s_CreateInstance(_In_ IPowerRenameManager* psrm, _In_opt
// IPowerRenameUI
IFACEMETHODIMP CPowerRenameUI::Show(_In_opt_ HWND hwndParent)
{
return _DoModal(hwndParent);
return _DoModeless(hwndParent);
}

IFACEMETHODIMP CPowerRenameUI::Close()
Expand Down Expand Up @@ -354,12 +354,25 @@ void CPowerRenameUI::_OnCloseDlg()
{
// Persist the current settings
_WriteSettings();
EndDialog(m_hwnd, 1);

if (m_modeless)
{
DestroyWindow(m_hwnd);
}
else
{
EndDialog(m_hwnd, 1);
}
}

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

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

void CPowerRenameUI::_OnRename()
Expand All @@ -384,6 +397,7 @@ void CPowerRenameUI::_OnAbout()

HRESULT CPowerRenameUI::_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 +407,33 @@ HRESULT CPowerRenameUI::_DoModal(__in_opt HWND hwnd)
return hr;
}

HRESULT CPowerRenameUI::_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 CPowerRenameUI::_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 +659,8 @@ void CPowerRenameUI::_OnSize(_In_ WPARAM wParam)
{
_MoveControl(g_repositionMap[u].id, g_repositionMap[u].flags, xDelta, yDelta);
}

m_listview.OnSize();
}
}

Expand Down Expand Up @@ -784,7 +827,7 @@ void CPowerRenameListView::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 +1009,14 @@ void CPowerRenameListView::GetDisplayInfo(_In_ IPowerRenameManager* psrm, _Inout
}
}

void CPowerRenameListView::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 CPowerRenameListView::RedrawItems(_In_ int first, _In_ int last)
{
ListView_RedrawItems(m_hwndLV, first, last);
Expand Down
3 changes: 3 additions & 0 deletions src/modules/powerrename/ui/PowerRenameUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CPowerRenameListView
void OnKeyDown(_In_ IPowerRenameManager* psrm, _In_ LV_KEYDOWN* lvKeyDown);
void OnClickList(_In_ IPowerRenameManager* psrm, NM_LISTVIEW* pnmListView);
void GetDisplayInfo(_In_ IPowerRenameManager* psrm, _Inout_ LV_DISPINFO* plvdi);
void OnSize();
HWND GetHWND() { return m_hwndLV; }

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

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 CPowerRenameUI :
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 1d3acbe

Please sign in to comment.