From fe273d3531b6e22589b58aea5b45508c810ef08f Mon Sep 17 00:00:00 2001 From: Shriraj Sawant Date: Fri, 7 Jul 2017 14:53:11 +0000 Subject: [PATCH] [QCKLNCH] -Removed CWindowImpl -Added CWindow -Used OnWinEvent() instead of subclassing -Handled WM_COMMAND and WM_NOTIFY as needed -Now along with buttons chevron menu is also working CR-122 (https://code.reactos.org/cru/CR-122#details) PS: Thank you everyone for spending your time and giving a thorough review. :) svn path=/branches/GSoC_2017/shellext/; revision=75297 --- reactos/dll/shellext/qcklnch/CISFBand.cpp | 168 ++++++++++------------ reactos/dll/shellext/qcklnch/CISFBand.h | 14 +- reactos/dll/shellext/qcklnch/resource.h | 12 +- 3 files changed, 86 insertions(+), 108 deletions(-) diff --git a/reactos/dll/shellext/qcklnch/CISFBand.cpp b/reactos/dll/shellext/qcklnch/CISFBand.cpp index 227b2fce29f..fde02300a6f 100644 --- a/reactos/dll/shellext/qcklnch/CISFBand.cpp +++ b/reactos/dll/shellext/qcklnch/CISFBand.cpp @@ -7,7 +7,6 @@ */ #include "precomp.h" -#include #include #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) @@ -26,7 +25,7 @@ BOOL WINAPI _ILIsDesktop(LPCITEMIDLIST pidl) // *** CISFBand *** CISFBand::CISFBand() : - m_BandID(0), + m_BandID(0), m_pidl(NULL), m_textFlag(true), m_iconFlag(true) @@ -34,84 +33,10 @@ CISFBand::CISFBand() : } CISFBand::~CISFBand() -{ +{ } -// *** CWindowImpl *** -// Subclassing - -LRESULT CISFBand::OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) -{ - TBBUTTON tb; - POINT pt; - DWORD pos = GetMessagePos(); - pt.x = GET_X_LPARAM(pos); - pt.y = GET_Y_LPARAM(pos); - ScreenToClient(&pt); - - int index = SendMessage(m_hWnd, TB_HITTEST, 0, (LPARAM)&pt); - bool chk = SendMessage(m_hWnd, TB_GETBUTTON, abs(index), (LPARAM)&tb); - if(chk) - SHInvokeDefaultCommand(m_hWnd, m_pISF, (LPITEMIDLIST)tb.dwData); - - return 0; -} - -LRESULT CISFBand::OnRButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) -{ - HRESULT hr; - CComPtr picm; - HMENU fmenu = CreatePopupMenu(); - TBBUTTON tb; - POINT pt; - DWORD pos = GetMessagePos(); - pt.x = GET_X_LPARAM(pos); - pt.y = GET_Y_LPARAM(pos); - ScreenToClient(&pt); - - int index = SendMessage(m_hWnd, TB_HITTEST, 0, (LPARAM)&pt); - bool chk = SendMessage(m_hWnd, TB_GETBUTTON, abs(index), (LPARAM)&tb); - LPITEMIDLIST pidl = (LPITEMIDLIST)tb.dwData; - - if (chk) - { - ClientToScreen(&pt); - hr = m_pISF->GetUIObjectOf(m_hWnd, 1, &pidl, IID_NULL_PPV_ARG(IContextMenu, &picm)); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - hr = picm->QueryContextMenu(fmenu, 0, 1, 0x7FFF, CMF_DEFAULTONLY); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - int id = TrackPopupMenuEx(fmenu, TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RETURNCMD, pt.x, pt.y, m_hWnd, 0); - if (id > 0) - { - CMINVOKECOMMANDINFOEX info = { 0 }; - info.cbSize = sizeof(info); - info.fMask = CMIC_MASK_UNICODE | CMIC_MASK_PTINVOKE; - if (GetKeyState(VK_CONTROL) < 0) - { - info.fMask |= CMIC_MASK_CONTROL_DOWN; - } - if (GetKeyState(VK_SHIFT) < 0) - { - info.fMask |= CMIC_MASK_SHIFT_DOWN; - } - info.hwnd = m_hWnd; - info.lpVerb = MAKEINTRESOURCEA(id - 1); - info.lpVerbW = MAKEINTRESOURCEW(id - 0x7FFF); - info.nShow = SW_SHOWNORMAL; - info.ptInvoke = pt; - picm->InvokeCommand((LPCMINVOKECOMMANDINFO)&info); - } - } - - DestroyMenu(fmenu); - return 0; -} - -// ToolbarTest +// Toolbar HRESULT CISFBand::CreateSimpleToolbar(HWND hWndParent) { // Declare and initialize local constants. @@ -159,9 +84,9 @@ HRESULT CISFBand::CreateSimpleToolbar(HWND hWndParent) StrRetToBuf(&stret, pidl, sz, _countof(sz)); TBBUTTON tb = { MAKELONG(index, 0), i, TBSTATE_ENABLED, buttonStyles,{ 0 }, (DWORD_PTR)pidl, (INT_PTR)sz }; - SendMessage(m_hWnd, TB_INSERTBUTTONW, 0, (LPARAM)&tb); - //CoTaskMemFree(pidl); - } + SendMessage(m_hWnd, TB_INSERTBUTTONW, i, (LPARAM)&tb); + //CoTaskMemFree(pidl); + } // Resize the toolbar, and then show it. SendMessage(m_hWnd, TB_AUTOSIZE, 0, 0); @@ -189,11 +114,7 @@ HRESULT CISFBand::CreateSimpleToolbar(HWND hWndParent) hr = CreateSimpleToolbar(hwndParent); if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - hr = SubclassWindow(m_hWnd); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; + return hr; return S_OK; } @@ -386,20 +307,83 @@ HRESULT CISFBand::CreateSimpleToolbar(HWND hWndParent) } STDMETHODIMP CISFBand::OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult) - { - /* switch (uMsg) + { + switch (uMsg) { case WM_COMMAND: { - MessageBox(L"Button Clicked", L"Test", MB_OKCANCEL | MB_ICONINFORMATION); + TBBUTTON tb; + bool chk = SendMessage(m_hWnd, TB_GETBUTTON, LOWORD(wParam), (LPARAM)&tb); + if (chk) + SHInvokeDefaultCommand(m_hWnd, m_pISF, (LPITEMIDLIST)tb.dwData); + + *theResult = TRUE; + break; + } + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + case NM_RCLICK: + { + HRESULT hr; + POINT pt = ((LPNMMOUSE)lParam)->pt; + CComPtr picm; + HMENU fmenu = CreatePopupMenu(); + TBBUTTON tb; + + bool chk = SendMessage(m_hWnd, TB_GETBUTTON, ((LPNMMOUSE)lParam)->dwItemSpec, (LPARAM)&tb); + LPITEMIDLIST pidl = (LPITEMIDLIST)tb.dwData; + + if (chk) + { + ClientToScreen(&pt); + hr = m_pISF->GetUIObjectOf(m_hWnd, 1, &pidl, IID_NULL_PPV_ARG(IContextMenu, &picm)); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + hr = picm->QueryContextMenu(fmenu, 0, 1, 0x7FFF, CMF_DEFAULTONLY); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + int id = TrackPopupMenuEx(fmenu, TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RETURNCMD, pt.x, pt.y, m_hWnd, 0); + if (id > 0) + { + CMINVOKECOMMANDINFOEX info = { 0 }; + info.cbSize = sizeof(info); + info.fMask = CMIC_MASK_UNICODE | CMIC_MASK_PTINVOKE; + if (GetKeyState(VK_CONTROL) < 0) + { + info.fMask |= CMIC_MASK_CONTROL_DOWN; + } + if (GetKeyState(VK_SHIFT) < 0) + { + info.fMask |= CMIC_MASK_SHIFT_DOWN; + } + info.hwnd = m_hWnd; + info.lpVerb = MAKEINTRESOURCEA(id - 1); + info.lpVerbW = MAKEINTRESOURCEW(id - 0x7FFF); + info.nShow = SW_SHOWNORMAL; + info.ptInvoke = pt; + picm->InvokeCommand((LPCMINVOKECOMMANDINFO)&info); + } + } + DestroyMenu(fmenu); + + *theResult = TRUE; + break; + } + default: + *theResult = FALSE; + } break; } + default: + *theResult = FALSE; } - return DefSubclassProc(hWnd, uMsg, wParam, lParam);*/ - UNIMPLEMENTED; - return E_NOTIMPL; + return S_OK; } STDMETHODIMP CISFBand::IsWindowOwner(HWND hWnd) diff --git a/reactos/dll/shellext/qcklnch/CISFBand.h b/reactos/dll/shellext/qcklnch/CISFBand.h index 004edaed210..4fe8a668d5d 100644 --- a/reactos/dll/shellext/qcklnch/CISFBand.h +++ b/reactos/dll/shellext/qcklnch/CISFBand.h @@ -9,7 +9,7 @@ // COM class for cisfband class CISFBand : - public CWindowImpl, + public CWindow, public CComCoClass, public CComObjectRootEx, public IObjectWithSite, @@ -24,9 +24,9 @@ class CISFBand : DWORD m_BandID; CComPtr m_Site; - // Toolbar + // Toolbar CComPtr m_pISF; - PCIDLIST_ABSOLUTE m_pidl; + PCIDLIST_ABSOLUTE m_pidl; // Menu BOOL m_textFlag; @@ -39,8 +39,6 @@ public: // Personal Methods HRESULT CreateSimpleToolbar(HWND hWndParent); - LRESULT OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnRButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); // IObjectWithSite @@ -182,11 +180,7 @@ public: UINT uFlags ); -//***************************************************************************************************** - BEGIN_MSG_MAP(CISFBand) - MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp) - MESSAGE_HANDLER(WM_RBUTTONUP, OnRButtonUp) - END_MSG_MAP() +//***************************************************************************************************** DECLARE_NOT_AGGREGATABLE(CISFBand) DECLARE_PROTECT_FINAL_CONSTRUCT() diff --git a/reactos/dll/shellext/qcklnch/resource.h b/reactos/dll/shellext/qcklnch/resource.h index 1d3c7860756..ca882a8663d 100644 --- a/reactos/dll/shellext/qcklnch/resource.h +++ b/reactos/dll/shellext/qcklnch/resource.h @@ -2,10 +2,10 @@ #define IDR_QCKLNCH 1001 -#define IDM_POPUPMENU 2000 -#define IDM_LARGE_ICONS 1 -#define IDM_SMALL_ICONS 2 -#define IDM_SHOW_TEXT 3 -#define IDM_VIEW_MENU 4 +#define IDM_POPUPMENU 2001 +#define IDM_LARGE_ICONS 101 +#define IDM_SMALL_ICONS 102 +#define IDM_SHOW_TEXT 103 +#define IDM_VIEW_MENU 104 -#define IDS_BROWSEINFO_TITLE 100 +#define IDS_BROWSEINFO_TITLE 201