Skip to content

Commit

Permalink
[STOBJECT]
Browse files Browse the repository at this point in the history
Implement the power schemes popup menu.

svn path=/trunk/; revision=74228
  • Loading branch information
EricKohl committed Mar 25, 2017
1 parent 2a258f8 commit 587b5a7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions reactos/dll/shellext/stobject/CMakeLists.txt
Expand Up @@ -33,6 +33,7 @@ add_importlibs(stobject
winmm winmm
ole32 ole32
oleaut32 oleaut32
powrprof
shlwapi shlwapi
shell32 shell32
comctl32 comctl32
Expand Down
73 changes: 72 additions & 1 deletion reactos/dll/shellext/stobject/power.cpp
Expand Up @@ -8,6 +8,7 @@
*/ */


#include "precomp.h" #include "precomp.h"
#include "powrprof.h"


#include <mmsystem.h> #include <mmsystem.h>
#include <mmddk.h> #include <mmddk.h>
Expand All @@ -17,6 +18,13 @@


WINE_DEFAULT_DEBUG_CHANNEL(stobject); WINE_DEFAULT_DEBUG_CHANNEL(stobject);


typedef struct _PWRSCHEMECONTEXT
{
HMENU hPopup;
UINT uiFirst;
UINT uiLast;
} PWRSCHEMECONTEXT, *PPWRSCHEMECONTEXT;

//static HICON g_hIconBattery = NULL; //static HICON g_hIconBattery = NULL;
static HICON g_hIconAC = NULL; static HICON g_hIconAC = NULL;


Expand Down Expand Up @@ -120,6 +128,68 @@ static void _ShowContextMenu(CSysTray * pSysTray)
} }
} }


static
BOOLEAN
CALLBACK
PowerSchemesEnumProc(
UINT uiIndex,
DWORD dwName,
LPWSTR sName,
DWORD dwDesc,
LPWSTR sDesc,
PPOWER_POLICY pp,
LPARAM lParam)
{
PPWRSCHEMECONTEXT PowerSchemeContext = (PPWRSCHEMECONTEXT)lParam;

if (AppendMenuW(PowerSchemeContext->hPopup, MF_STRING, uiIndex + 1, sName))
{
if (PowerSchemeContext->uiFirst == 0)
PowerSchemeContext->uiFirst = uiIndex + 1;

PowerSchemeContext->uiLast = uiIndex + 1;
}

return TRUE;
}

static
VOID
ShowPowerSchemesPopupMenu(
CSysTray *pSysTray)
{
PWRSCHEMECONTEXT PowerSchemeContext = {NULL, 0, 0};
UINT uiActiveScheme;
DWORD id, msgPos;

PowerSchemeContext.hPopup = CreatePopupMenu();
EnumPwrSchemes(PowerSchemesEnumProc, (LPARAM)&PowerSchemeContext);

if (GetActivePwrScheme(&uiActiveScheme))
{
CheckMenuRadioItem(PowerSchemeContext.hPopup,
PowerSchemeContext.uiFirst,
PowerSchemeContext.uiLast,
uiActiveScheme + 1,
MF_BYCOMMAND);
}

msgPos = GetMessagePos();

SetForegroundWindow(pSysTray->GetHWnd());
id = TrackPopupMenuEx(PowerSchemeContext.hPopup,
TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN,
GET_X_LPARAM(msgPos),
GET_Y_LPARAM(msgPos),
pSysTray->GetHWnd(),
NULL);

DestroyMenu(PowerSchemeContext.hPopup);

if (id != 0)
SetActivePwrScheme(id - 1, NULL, NULL);
}

HRESULT STDMETHODCALLTYPE Power_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult) HRESULT STDMETHODCALLTYPE Power_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult)
{ {
TRACE("Power_Message uMsg=%d, wParam=%x, lParam=%x\n", uMsg, wParam, lParam); TRACE("Power_Message uMsg=%d, wParam=%x, lParam=%x\n", uMsg, wParam, lParam);
Expand Down Expand Up @@ -155,7 +225,7 @@ HRESULT STDMETHODCALLTYPE Power_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPA
break; break;


case WM_LBUTTONUP: case WM_LBUTTONUP:
TRACE("TODO: display power options!\n"); ShowPowerSchemesPopupMenu(pSysTray);
break; break;


case WM_LBUTTONDBLCLK: case WM_LBUTTONDBLCLK:
Expand All @@ -167,6 +237,7 @@ HRESULT STDMETHODCALLTYPE Power_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPA


case WM_RBUTTONUP: case WM_RBUTTONUP:
_ShowContextMenu(pSysTray); _ShowContextMenu(pSysTray);
break;


case WM_RBUTTONDBLCLK: case WM_RBUTTONDBLCLK:
break; break;
Expand Down

0 comments on commit 587b5a7

Please sign in to comment.