ReactOS 0.4.16-dev-1176-g64fda67
appbar.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Shell32
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: SHAppBarMessage implementation
5 * COPYRIGHT: Copyright 2008 Vincent Povirk for CodeWeavers
6 * Copyright 2025 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7 */
8
9#include <windef.h>
10#include <winbase.h>
11#include <winuser.h>
12#include <shellapi.h>
13#include <shlobj.h>
14#include <shlwapi.h>
15#include <undocshell.h>
16
17#include <wine/debug.h>
18#include <wine/unicode.h>
19
21
22static HANDLE
24 _In_ const VOID *pvSrc,
26 _In_ DWORD dwProcessId)
27{
28 HANDLE hMem = SHAllocShared(NULL, dwSize, dwProcessId);
29 if (!hMem)
30 return 0;
31
32 PVOID pvDest = SHLockShared(hMem, dwProcessId);
33 if (!pvDest)
34 {
35 SHFreeShared(hMem, dwProcessId);
36 return 0;
37 }
38
39 CopyMemory(pvDest, pvSrc, dwSize);
40 SHUnlockShared(pvDest);
41 return hMem;
42}
43
44static BOOL
46 _In_ HANDLE hOutput,
47 _Out_ PVOID pvDest,
48 _In_ SIZE_T cbDest,
49 _In_ DWORD dwProcessId)
50{
51 PVOID pvSrc = SHLockShared(hOutput, dwProcessId);
52 if (pvSrc)
53 {
54 CopyMemory(pvDest, pvSrc, cbDest);
55 SHUnlockShared(pvSrc);
56 }
57
58 SHFreeShared(hOutput, dwProcessId);
59 return pvSrc != NULL;
60}
61
62/*************************************************************************
63 * SHAppBarMessage [SHELL32.@]
64 */
68 _In_ DWORD dwMessage,
70{
71 TRACE("dwMessage=%d, pData={cb=%d, hwnd=%p}\n", dwMessage, pData->cbSize, pData->hWnd);
72
73 HWND hTrayWnd = FindWindowW(L"Shell_TrayWnd", NULL);
74 if (!hTrayWnd || pData->cbSize > sizeof(*pData))
75 {
76 WARN("%p, %d\n", hTrayWnd, pData->cbSize);
77 return FALSE;
78 }
79
81 cmd.abd.cbSize = sizeof(cmd.abd);
82 cmd.abd.hWnd32 = HandleToUlong(pData->hWnd); // Truncated on x64, as on Windows!
83 cmd.abd.uCallbackMessage = pData->uCallbackMessage;
84 cmd.abd.uEdge = pData->uEdge;
85 cmd.abd.rc = pData->rc;
86 cmd.abd.lParam64 = pData->lParam;
87 cmd.dwMessage = dwMessage;
88 cmd.hOutput = (APPBAR_OUTPUT)NULL;
89 cmd.dwProcessId = GetCurrentProcessId();
90
91 /* Make output data if necessary */
92 switch (dwMessage)
93 {
94 case ABM_QUERYPOS:
95 case ABM_SETPOS:
97 cmd.hOutput = (APPBAR_OUTPUT)AppBar_CopyIn(&cmd.abd, sizeof(cmd.abd), cmd.dwProcessId);
98 if (!cmd.hOutput)
99 {
100 ERR("AppBar_CopyIn: %d\n", dwMessage);
101 return FALSE;
102 }
103 break;
104 default:
105 break;
106 }
107
108 /* Send WM_COPYDATA message */
109 COPYDATASTRUCT copyData = { TABDMC_APPBAR, sizeof(cmd), &cmd };
110 UINT_PTR ret = SendMessageW(hTrayWnd, WM_COPYDATA, (WPARAM)pData->hWnd, (LPARAM)&copyData);
111
112 /* Copy back output data */
113 if (cmd.hOutput)
114 {
115 if (!AppBar_CopyOut((HANDLE)cmd.hOutput, &cmd.abd, sizeof(cmd.abd), cmd.dwProcessId))
116 {
117 ERR("AppBar_CopyOut: %d\n", dwMessage);
118 return FALSE;
119 }
120 pData->hWnd = UlongToHandle(cmd.abd.hWnd32);
121 pData->uCallbackMessage = cmd.abd.uCallbackMessage;
122 pData->uEdge = cmd.abd.uEdge;
123 pData->rc = cmd.abd.rc;
124 pData->lParam = (LPARAM)cmd.abd.lParam64;
125 }
126
127 return ret;
128}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define UlongToHandle(ul)
Definition: basetsd.h:97
#define HandleToUlong(h)
Definition: basetsd.h:79
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
static HANDLE AppBar_CopyIn(_In_ const VOID *pvSrc, _In_ SIZE_T dwSize, _In_ DWORD dwProcessId)
Definition: appbar.c:23
UINT_PTR WINAPI SHAppBarMessage(_In_ DWORD dwMessage, _Inout_ PAPPBARDATA pData)
Definition: appbar.c:67
static BOOL AppBar_CopyOut(_In_ HANDLE hOutput, _Out_ PVOID pvDest, _In_ SIZE_T cbDest, _In_ DWORD dwProcessId)
Definition: appbar.c:45
HANDLE WINAPI SHAllocShared(LPCVOID lpvData, DWORD dwSize, DWORD dwProcId)
Definition: ordinal.c:169
PVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
Definition: ordinal.c:259
BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
Definition: ordinal.c:315
BOOL WINAPI SHUnlockShared(LPVOID lpView)
Definition: ordinal.c:295
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define L(x)
Definition: ntvdm.h:50
#define ABM_GETTASKBARPOS
Definition: shellapi.h:67
#define ABM_SETPOS
Definition: shellapi.h:65
#define ABM_QUERYPOS
Definition: shellapi.h:64
#define TRACE(s)
Definition: solgame.cpp:4
Definition: ftp_var.h:139
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
ULONG_PTR SIZE_T
Definition: typedefs.h:80
HANDLE APPBAR_OUTPUT
Definition: undocshell.h:1228
#define TABDMC_APPBAR
Definition: undocshell.h:935
int ret
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
#define CopyMemory
Definition: winbase.h:1742
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define WM_COPYDATA
Definition: winuser.h:1683
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)