mshtml: Added IHTMLWindow2::get_screen implementation.
[wine] / dlls / shell32 / dde.c
1 /*
2  * Shell DDE Handling
3  *
4  * Copyright 2004 Robert Shearman
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "ddeml.h"
26 #include "shellapi.h"
27
28 #include "wine/debug.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(shell);
31
32 /* String handles */
33 static HSZ hszProgmanTopic;
34 static HSZ hszProgmanService;
35 static HSZ hszAsterisk;
36 static HSZ hszShell;
37 static HSZ hszAppProperties;
38 static HSZ hszFolders;
39 /* DDE Instance ID */
40 static DWORD dwDDEInst;
41
42
43 static inline BOOL Dde_OnConnect(HSZ hszTopic, HSZ hszService)
44 {
45     if ((hszTopic == hszProgmanTopic) && (hszService == hszProgmanService))
46         return TRUE;
47     if ((hszTopic == hszProgmanTopic) && (hszService == hszAppProperties))
48         return TRUE;
49     if ((hszTopic == hszShell) && (hszService == hszFolders))
50         return TRUE;
51     if ((hszTopic == hszShell) && (hszService == hszAppProperties))
52         return TRUE;
53     return FALSE;
54 }
55
56 static inline void Dde_OnConnectConfirm(HCONV hconv, HSZ hszTopic, HSZ hszService)
57 {
58     FIXME("stub\n");
59 }
60
61 static inline BOOL Dde_OnWildConnect(HSZ hszTopic, HSZ hszService)
62 {
63     FIXME("stub\n");
64     return FALSE;
65 }
66
67 static inline HDDEDATA Dde_OnRequest(UINT uFmt, HCONV hconv, HSZ hszTopic,
68                                      HSZ hszItem)
69 {
70     FIXME("stub\n");
71     return NULL;
72 }
73
74 static inline DWORD Dde_OnExecute(HCONV hconv, HSZ hszTopic, HDDEDATA hdata)
75 {
76     BYTE * pszCommand;
77
78     pszCommand = DdeAccessData(hdata, NULL);
79     if (!pszCommand)
80         return DDE_FNOTPROCESSED;
81
82     FIXME("stub: %s\n", pszCommand);
83
84     DdeUnaccessData(hdata);
85
86     return DDE_FNOTPROCESSED;
87 }
88
89 static inline void Dde_OnDisconnect(HCONV hconv)
90 {
91     FIXME("stub\n");
92 }
93
94 static HDDEDATA CALLBACK DdeCallback(      
95     UINT uType,
96     UINT uFmt,
97     HCONV hconv,
98     HSZ hsz1,
99     HSZ hsz2,
100     HDDEDATA hdata,
101     ULONG_PTR dwData1,
102     ULONG_PTR dwData2)
103 {
104     switch (uType)
105     {
106     case XTYP_CONNECT:
107         return (HDDEDATA)(DWORD_PTR)Dde_OnConnect(hsz1, hsz2);
108     case XTYP_CONNECT_CONFIRM:
109         Dde_OnConnectConfirm(hconv, hsz1, hsz2);
110         return NULL;
111     case XTYP_WILDCONNECT:
112         return (HDDEDATA)(DWORD_PTR)Dde_OnWildConnect(hsz1, hsz2);
113     case XTYP_REQUEST:
114         return Dde_OnRequest(uFmt, hconv, hsz1, hsz2);
115     case XTYP_EXECUTE:
116         return (HDDEDATA)(DWORD_PTR)Dde_OnExecute(hconv, hsz1, hdata);
117     case XTYP_DISCONNECT:
118         Dde_OnDisconnect(hconv);
119         return NULL;
120     default:
121         return NULL;
122     }
123 }
124
125 /*************************************************************************
126  * ShellDDEInit (SHELL32.@)
127  *
128  * Registers the Shell DDE services with the system so that applications
129  * can use them.
130  *
131  * PARAMS
132  *  bInit [I] TRUE to initialize the services, FALSE to uninitalize.
133  *
134  * RETURNS
135  *  Nothing.
136  */
137 void WINAPI ShellDDEInit(BOOL bInit)
138 {
139     TRACE("bInit = %s\n", bInit ? "TRUE" : "FALSE");
140
141     if (bInit)
142     {
143         static const WCHAR wszProgman[] = {'P','r','o','g','m','a','n',0};
144         static const WCHAR wszAsterisk[] = {'*',0};
145         static const WCHAR wszShell[] = {'S','h','e','l','l',0};
146         static const WCHAR wszAppProperties[] =
147             {'A','p','p','P','r','o','p','e','r','t','i','e','s',0};
148         static const WCHAR wszFolders[] = {'F','o','l','d','e','r','s',0};
149
150         DdeInitializeW(&dwDDEInst, DdeCallback, CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
151
152         hszProgmanTopic = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE);
153         hszProgmanService = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE);
154         hszAsterisk = DdeCreateStringHandleW(dwDDEInst, wszAsterisk, CP_WINUNICODE);
155         hszShell = DdeCreateStringHandleW(dwDDEInst, wszShell, CP_WINUNICODE);
156         hszAppProperties = DdeCreateStringHandleW(dwDDEInst, wszAppProperties, CP_WINUNICODE);
157         hszFolders = DdeCreateStringHandleW(dwDDEInst, wszFolders, CP_WINUNICODE);
158
159         DdeNameService(dwDDEInst, hszFolders, 0, DNS_REGISTER);
160         DdeNameService(dwDDEInst, hszProgmanService, 0, DNS_REGISTER);
161         DdeNameService(dwDDEInst, hszShell, 0, DNS_REGISTER);
162     }
163     else
164     {
165         /* unregister all services */
166         DdeNameService(dwDDEInst, 0, 0, DNS_UNREGISTER);
167
168         DdeFreeStringHandle(dwDDEInst, hszFolders);
169         DdeFreeStringHandle(dwDDEInst, hszAppProperties);
170         DdeFreeStringHandle(dwDDEInst, hszShell);
171         DdeFreeStringHandle(dwDDEInst, hszAsterisk);
172         DdeFreeStringHandle(dwDDEInst, hszProgmanService);
173         DdeFreeStringHandle(dwDDEInst, hszProgmanTopic);
174
175         DdeUninitialize(dwDDEInst);
176     }
177 }