xref: /reactos/sdk/include/reactos/dll/desk/deskcplx.h (revision 994e2f28)
1 #ifndef __DESKCPLX__H
2 #define __DESKCPLX__H
3 
4 #define DESK_EXT_CALLBACK CALLBACK
5 
6 #define DESK_EXT_EXTINTERFACE TEXT("Desk.cpl extension interface")
7 #define DESK_EXT_PRUNINGMODE TEXT("Pruning Mode")
8 #define DESK_EXT_DISPLAYDEVICE TEXT("Display Device")
9 #define DESK_EXT_DISPLAYNAME TEXT("Display Name")
10 #define DESK_EXT_DISPLAYID TEXT("Display ID")
11 #define DESK_EXT_DISPLAYKEY TEXT("Display Key")
12 #define DESK_EXT_DISPLAYSTATEFLAGS TEXT("Display State Flags")
13 #define DESK_EXT_MONITORNAME TEXT("Monitor Name")
14 #define DESK_EXT_MONITORDEVICE TEXT("Monitor Device")
15 
16 typedef PDEVMODEW (DESK_EXT_CALLBACK *PDESK_EXT_ENUMALLMODES)(PVOID Context, DWORD Index);
17 typedef PDEVMODEW (DESK_EXT_CALLBACK *PDESK_EXT_GETCURRENTMODE)(PVOID Context);
18 typedef BOOL (DESK_EXT_CALLBACK *PDESK_EXT_SETCURRENTMODE)(PVOID Context, DEVMODEW *pDevMode);
19 typedef VOID (DESK_EXT_CALLBACK *PDESK_EXT_GETPRUNINGMODE)(PVOID Context, PBOOL pbModesPruned, PBOOL pbKeyIsReadOnly, PBOOL pbPruningOn);
20 typedef VOID (DESK_EXT_CALLBACK *PDESK_EXT_SETPRUNINGMODE)(PVOID Context, BOOL PruningOn);
21 
22 typedef struct _DESK_EXT_INTERFACE
23 {
24     /* NOTE: This structure is binary compatible to XP. The windows shell
25              extensions rely on this structure to be properly filled! */
26     DWORD cbSize;
27 
28     PVOID Context; /* This value is passed on to the callback routines */
29 
30     /* Callback routines called by the shell extensions */
31     PDESK_EXT_ENUMALLMODES EnumAllModes;
32     PDESK_EXT_SETCURRENTMODE SetCurrentMode;
33     PDESK_EXT_GETCURRENTMODE GetCurrentMode;
34     PDESK_EXT_SETPRUNINGMODE SetPruningMode;
35     PDESK_EXT_GETPRUNINGMODE GetPruningMode;
36 
37     /* HardwareInformation.* values provided in the device registry key */
38     WCHAR MemorySize[128];
39     WCHAR ChipType[128];
40     WCHAR DacType[128];
41     WCHAR AdapterString[128];
42     WCHAR BiosString[128];
43 } DESK_EXT_INTERFACE, *PDESK_EXT_INTERFACE;
44 
45 LONG WINAPI DisplaySaveSettings(PVOID pContext, HWND hwndPropSheet);
46 
47 static __inline PDESK_EXT_INTERFACE
QueryDeskCplExtInterface(IDataObject * pdo)48 QueryDeskCplExtInterface(IDataObject *pdo)
49 {
50     PDESK_EXT_INTERFACE pRecvBuffer, pExtIface = NULL;
51     FORMATETC fetc;
52     STGMEDIUM medium;
53 
54     fetc.cfFormat = (CLIPFORMAT)RegisterClipboardFormat(DESK_EXT_EXTINTERFACE);
55     fetc.ptd = NULL;
56     fetc.dwAspect = DVASPECT_CONTENT;
57     fetc.lindex = -1;
58     fetc.tymed = TYMED_HGLOBAL;
59 
60     if (SUCCEEDED(IDataObject_GetData(pdo, &fetc, &medium)) && medium.hGlobal != NULL)
61     {
62         /* We always receive the string in unicode! */
63         pRecvBuffer = (PDESK_EXT_INTERFACE)GlobalLock(medium.hGlobal);
64 
65         if (pRecvBuffer->cbSize == sizeof(*pRecvBuffer))
66         {
67             pExtIface = LocalAlloc(LMEM_FIXED, sizeof(*pExtIface));
68             if (pExtIface != NULL)
69             {
70                 CopyMemory(pExtIface,
71                            pRecvBuffer,
72                            sizeof(*pRecvBuffer));
73             }
74         }
75 
76         GlobalUnlock(medium.hGlobal);
77         ReleaseStgMedium(&medium);
78     }
79 
80     return pExtIface;
81 }
82 
83 static __inline LPTSTR
QueryDeskCplString(IDataObject * pdo,UINT cfFormat)84 QueryDeskCplString(IDataObject *pdo, UINT cfFormat)
85 {
86     FORMATETC fetc;
87     STGMEDIUM medium;
88     SIZE_T BufLen;
89     LPWSTR lpRecvBuffer;
90     LPTSTR lpStr = NULL;
91 
92     fetc.cfFormat = (CLIPFORMAT)cfFormat;
93     fetc.ptd = NULL;
94     fetc.dwAspect = DVASPECT_CONTENT;
95     fetc.lindex = -1;
96     fetc.tymed = TYMED_HGLOBAL;
97 
98     if (SUCCEEDED(IDataObject_GetData(pdo, &fetc, &medium)) && medium.hGlobal != NULL)
99     {
100         /* We always receive the string in unicode! */
101         lpRecvBuffer = (LPWSTR)GlobalLock(medium.hGlobal);
102 
103         BufLen = wcslen(lpRecvBuffer) + 1;
104         lpStr = LocalAlloc(LMEM_FIXED, BufLen * sizeof(TCHAR));
105         if (lpStr != NULL)
106         {
107 #ifdef UNICODE
108             wcscpy(lpStr, lpRecvBuffer);
109 #else
110             WideCharToMultiByte(CP_ACP, 0, lpRecvBuffer, -1, lpStr, BufLen, NULL, NULL);
111 #endif
112         }
113 
114         GlobalUnlock(medium.hGlobal);
115         ReleaseStgMedium(&medium);
116     }
117 
118     return lpStr;
119 }
120 
121 static __inline LONG
DeskCplExtDisplaySaveSettings(PDESK_EXT_INTERFACE DeskExtInterface,HWND hwndDlg)122 DeskCplExtDisplaySaveSettings(PDESK_EXT_INTERFACE DeskExtInterface,
123                               HWND hwndDlg)
124 {
125     typedef LONG (WINAPI *PDISPLAYSAVESETTINGS)(PVOID, HWND);
126     HMODULE hModDeskCpl;
127     PDISPLAYSAVESETTINGS pDisplaySaveSettings;
128     LONG lRet = DISP_CHANGE_BADPARAM;
129 
130     /* We could use GetModuleHandle() instead, but then this routine
131        wouldn't work if some other application hosts the shell extension */
132     hModDeskCpl = LoadLibrary(TEXT("desk.cpl"));
133     if (hModDeskCpl != NULL)
134     {
135         pDisplaySaveSettings = (PDISPLAYSAVESETTINGS)GetProcAddress(hModDeskCpl,
136                                                                     "DisplaySaveSettings");
137         if (pDisplaySaveSettings != NULL)
138         {
139             lRet = pDisplaySaveSettings(DeskExtInterface->Context,
140                                         hwndDlg);
141         }
142 
143         FreeLibrary(hModDeskCpl);
144     }
145 
146     return lRet;
147 }
148 
149 #endif /* __DESKCPLX__H */
150