1
0

Dde.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #include "Main.h"
  2. /*
  3. static HDDEDATA CALLBACK GroupDDECallback (UINT uiType, UINT uiFmt, HANDLE hConv,
  4. HSZ sz1, HSZ sz2, HDDEDATA hData, LONG lData1, LONG lData2) {
  5. return ((HDDEDATA) NULL);
  6. }
  7. static BOOL CreateGroup(HWND hwnd);
  8. static BOOL AddProgramItems (HWND hwnd, LPSTR szDummy);
  9. static CONVCONTEXT CCFilter = { sizeof (CONVCONTEXT), 0, 0, 0, 0L, 0L };
  10. static LONG lIdInst;
  11. static LONG lIdInst2;
  12. */
  13. //CreateShortCut(hwnd,"D:\\WINNT\\Profiles\\Administrator\\Application Data\\Microsoft\\Internet Explorer\\Quick Launch\\Winamp.lnk","C:\\winamp\\winamp.exe");
  14. //CreateShortCut(hwnd,"D:\\WINNT\\Profiles\\Administrator\\Desktop\\Winamp.lnk","C:\\winamp\\winamp.exe");
  15. #if 0
  16. void dde_adddesktop(HWND hwnd)
  17. {
  18. HKEY mp3Key;
  19. char name[MAX_PATH]="";
  20. if (RegOpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",&mp3Key) == ERROR_SUCCESS)
  21. {
  22. int s=sizeof(name);
  23. if (RegQueryValueEx(mp3Key,"Desktop",0,NULL,name,&s) == ERROR_SUCCESS)
  24. {
  25. }
  26. RegCloseKey(mp3Key);
  27. }
  28. if (lstrlen(name))
  29. {
  30. char exe[MAX_PATH];
  31. GetModuleFileName(NULL,exe,sizeof(exe));
  32. lstrcat(name,"\\WINAMP.LNK");
  33. CreateShortCut(hwnd,name,exe,NULL,0);
  34. }
  35. }
  36. void dde_addquicklaunch(HWND hwnd)
  37. {
  38. HKEY mp3Key;
  39. char name[MAX_PATH]="";
  40. if (RegOpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",&mp3Key) == ERROR_SUCCESS)
  41. {
  42. int s=sizeof(name);
  43. if (RegQueryValueEx(mp3Key,"AppData",0,NULL,name,&s) == ERROR_SUCCESS)
  44. {
  45. }
  46. RegCloseKey(mp3Key);
  47. }
  48. if (lstrlen(name))
  49. {
  50. char exe[MAX_PATH];
  51. GetModuleFileName(NULL,exe,sizeof(exe));
  52. lstrcat(name,"\\Microsoft\\Internet Explorer\\Quick Launch\\WINAMP.LNK");
  53. CreateShortCut(hwnd,name,exe,NULL,0);
  54. }
  55. }
  56. int dde_isquicklaunchavailable(void)
  57. {
  58. HKEY mp3Key;
  59. char name[MAX_PATH]="";
  60. if (RegOpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",&mp3Key) == ERROR_SUCCESS)
  61. {
  62. int s=sizeof(name);
  63. if (RegQueryValueEx(mp3Key,"AppData",0,NULL,name,&s) == ERROR_SUCCESS)
  64. {
  65. }
  66. RegCloseKey(mp3Key);
  67. }
  68. if (lstrlen(name))
  69. {
  70. HANDLE h;
  71. WIN32_FIND_DATA fd;
  72. lstrcat(name,"\\Microsoft\\Internet Explorer\\Quick Launch");
  73. h=FindFirstFile(name,&fd);
  74. if (h != INVALID_HANDLE_VALUE)
  75. {
  76. FindClose(h);
  77. if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) return 1;
  78. }
  79. }
  80. return 0;
  81. }
  82. #if 1
  83. int dde_addstart(HWND hwnd)
  84. {
  85. HKEY mp3Key;
  86. char startMenu[MAX_PATH]="";
  87. if (RegOpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",&mp3Key) == ERROR_SUCCESS)
  88. {
  89. int s=sizeof(startMenu)/sizeof(startMenu[0]);
  90. if (RegQueryValueEx(mp3Key, "Programs", 0, NULL, startMenu, &s) == ERROR_SUCCESS)
  91. {
  92. char exe[MAX_PATH], shortcut[MAX_PATH], target[MAX_PATH];
  93. GetModuleFileName(NULL,exe,sizeof(exe));
  94. // create Winamp folder
  95. PathAppend(startMenu, "Winamp");
  96. CreateDirectory(startMenu, NULL);
  97. // winamp.exe
  98. PathCombine(shortcut, startMenu, "Winamp.lnk");
  99. CreateShortCut(hwnd, shortcut, exe, NULL, 0);
  100. // we don't need the executable filename anymore, but we need its path
  101. PathRemoveFileSpec(exe);
  102. // whatsnew.txt
  103. PathCombine(target, exe, "whatsnew.txt");
  104. PathCombine(shortcut, startMenu, "What's new.lnk");
  105. CreateShortCut(hwnd, startMenu, target, NULL, 0);
  106. // uninstwa.exe
  107. PathCombine(shortcut, startMenu, "Uninstall Winamp.lnk");
  108. PathAppend(target, exe, "uninstwa.exe");
  109. CreateShortCut(hwnd, shortcut, target, NULL, 0);
  110. }
  111. RegCloseKey(mp3Key);
  112. }
  113. return 0;
  114. }
  115. #else
  116. int dde_addstart(HWND hwnd)
  117. {
  118. CreateGroup(hwnd);
  119. AddProgramItems (hwnd, NULL);
  120. return 0;
  121. }
  122. void dde_delstart(void)
  123. {
  124. HDDEDATA hData;
  125. LPSTR szText;
  126. LPSTR szCommand;
  127. HCONV hConv;
  128. HSZ szProgMan;
  129. LONG lResult;
  130. szText = VirtualAlloc (NULL, 64, MEM_COMMIT, PAGE_READWRITE);
  131. szCommand = VirtualAlloc (NULL, 128, MEM_COMMIT, PAGE_READWRITE);
  132. if (szText) {
  133. if (DdeInitialize(&lIdInst, (PFNCALLBACK) GroupDDECallback,
  134. (DWORD) APPCMD_CLIENTONLY, 0L)) {
  135. VirtualFree (szText, 128, MEM_DECOMMIT);
  136. return;
  137. }
  138. szProgMan = DdeCreateStringHandle (lIdInst, "PROGMAN", CP_WINANSI);
  139. if (szProgMan) {
  140. hConv = DdeConnect (lIdInst, szProgMan, szProgMan, &CCFilter);
  141. lstrcpy(szText,app_name);
  142. wsprintf (szCommand, "[DeleteGroup(%s)]", szText);
  143. hData = DdeCreateDataHandle (lIdInst, szCommand,
  144. lstrlen (szCommand) + 1, 0, (HSZ) NULL, CF_TEXT, 0L);
  145. if (!DdeClientTransaction ((LPBYTE) hData, 0xFFFFFFFF, hConv,
  146. (HSZ) NULL, 0, XTYP_EXECUTE, 10000, &lResult)) {
  147. lResult = DdeGetLastError (lIdInst);
  148. }
  149. DdeFreeStringHandle (lIdInst, szProgMan);
  150. DdeDisconnect (hConv);
  151. } else {
  152. lResult = DdeGetLastError (lIdInst);
  153. }
  154. VirtualFree (szText, 64, MEM_DECOMMIT);
  155. VirtualFree (szCommand, 64, MEM_DECOMMIT);
  156. DdeUninitialize (lIdInst);
  157. lIdInst = 0L;
  158. return;
  159. } else {
  160. }
  161. }
  162. static BOOL CreateGroup(HWND hwnd) {
  163. HDDEDATA hData;
  164. LPSTR szText;
  165. LPSTR szCommand;
  166. HCONV hConv;
  167. HSZ szProgMan;
  168. LONG lResult;
  169. szText = VirtualAlloc (NULL, 64, MEM_COMMIT, PAGE_READWRITE);
  170. szCommand = VirtualAlloc (NULL, 128, MEM_COMMIT, PAGE_READWRITE);
  171. if (szText) {
  172. if (DdeInitialize(&lIdInst, (PFNCALLBACK) GroupDDECallback,
  173. (DWORD) APPCMD_CLIENTONLY, 0L)) {
  174. // MessageBox (hwnd, "DDEML Initialization Failure", "Error", MB_OK);
  175. VirtualFree (szText, 128, MEM_DECOMMIT);
  176. return (FALSE);
  177. }
  178. szProgMan = DdeCreateStringHandle (lIdInst, "PROGMAN", CP_WINANSI);
  179. if (szProgMan) {
  180. hConv = DdeConnect (lIdInst, szProgMan, szProgMan, &CCFilter);
  181. lstrcpy(szText,app_name);
  182. wsprintf (szCommand, "[CreateGroup(%s)]", szText);
  183. hData = DdeCreateDataHandle (lIdInst, szCommand,
  184. lstrlen (szCommand) + 1, 0, (HSZ) NULL, CF_TEXT, 0L);
  185. if (!DdeClientTransaction ((LPBYTE) hData, 0xFFFFFFFF, hConv,
  186. (HSZ) NULL, 0, XTYP_EXECUTE, 10000, &lResult)) {
  187. lResult = DdeGetLastError (lIdInst);
  188. // MessageBox (hwnd, "DdeClientTransaction Failed", "Error",
  189. // MB_OK);
  190. }
  191. DdeFreeStringHandle (lIdInst, szProgMan);
  192. DdeDisconnect (hConv);
  193. } else {
  194. lResult = DdeGetLastError (lIdInst);
  195. }
  196. VirtualFree (szText, 64, MEM_DECOMMIT);
  197. VirtualFree (szCommand, 64, MEM_DECOMMIT);
  198. DdeUninitialize (lIdInst);
  199. lIdInst = 0L;
  200. return (TRUE);
  201. } else {
  202. // MessageBox (hwnd, "Memory Allocation failure", "Error", MB_OK);
  203. }
  204. return (FALSE);
  205. }
  206. static BOOL AddProgramItems (HWND hwnd, LPSTR szDummy) {
  207. HDDEDATA hData;
  208. HCONV hConv;
  209. HSZ szProgMan;
  210. int lSelCount;
  211. LONG lResult;
  212. LPLONG lpSelection;
  213. LPSTR szProgName;
  214. LPSTR szExePath;
  215. LPSTR szExecuteString;
  216. int iIndex;
  217. int iGroupCount;
  218. iGroupCount = 2;
  219. lSelCount = 3;
  220. lpSelection = VirtualAlloc (NULL, lSelCount * sizeof (int), MEM_COMMIT,PAGE_READWRITE);
  221. if (lpSelection) {
  222. if (DdeInitialize (&lIdInst2, (PFNCALLBACK) GroupDDECallback,
  223. (DWORD) APPCMD_CLIENTONLY, 0L)) {
  224. VirtualFree (lpSelection, lSelCount * sizeof (int), MEM_DECOMMIT);
  225. return (FALSE);
  226. }
  227. szProgMan = DdeCreateStringHandle (lIdInst2, "PROGMAN", CP_WINANSI);
  228. hConv = DdeConnect (lIdInst2, szProgMan, szProgMan, &CCFilter);
  229. DdeFreeStringHandle (lIdInst2, szProgMan);
  230. szProgName = VirtualAlloc (NULL, MAX_PATH * 2, MEM_COMMIT, PAGE_READWRITE);
  231. szExePath = szProgName + MAX_PATH;
  232. szExecuteString = VirtualAlloc (NULL, MAX_PATH * 4, MEM_COMMIT,
  233. PAGE_READWRITE);
  234. for (iIndex = 0; iIndex < lSelCount; iIndex++) {
  235. {
  236. static char *paths[4] = {
  237. "Winamp.exe",
  238. "WhatsNew.txt",
  239. "Winamp.exe"
  240. };
  241. static char *names[4] =
  242. {
  243. "Winamp",
  244. "What's New",
  245. "Uninstall Winamp",
  246. };
  247. lstrcpy(szProgName,names[iIndex]);
  248. {
  249. szExePath[0] = '\"';
  250. GetModuleFileName(NULL,szExePath+1,MAX_PATH);
  251. scanstr_back(szExePath,"\\",szExePath-1)[1]=0;
  252. lstrcat(szExePath,paths[iIndex]);
  253. lstrcat(szExePath,"\"");
  254. if (iIndex==2) lstrcat(szExePath," /UNINSTALL");
  255. }
  256. }
  257. // Create the command string to add the item.
  258. wsprintf (szExecuteString, "[AddItem(%s,%s)]", szExePath,
  259. (LPARAM) szProgName);
  260. // Create a DDEML Data handle for the command string.
  261. hData = DdeCreateDataHandle (lIdInst2, szExecuteString,
  262. lstrlen (szExecuteString) + 1, 0, (HSZ) NULL, CF_TEXT, 0L);
  263. // Send the command over to the program manager.
  264. if (!DdeClientTransaction ((LPBYTE) hData, 0xFFFFFFFF,
  265. hConv, (HSZ) NULL, 0, XTYP_EXECUTE, 1000, &lResult)) {
  266. lResult = DdeGetLastError (lIdInst2);
  267. }/*endIf*/
  268. }/*endFor*/
  269. // Release the memory allocated for path and name retrieval.
  270. VirtualFree (szProgName, MAX_PATH * 2, MEM_DECOMMIT);
  271. // Release the command line memory.
  272. VirtualFree (szExecuteString, MAX_PATH * 4, MEM_DECOMMIT);
  273. // Disoconnect the DDEML Conversation
  274. DdeDisconnect (hConv);
  275. // Release the memory allocate for the list selections.
  276. VirtualFree (lpSelection, lSelCount * sizeof (int), MEM_DECOMMIT);
  277. }/*endIf*/
  278. // Clear the selection in the lists.
  279. // Uninitialize the local conversation.
  280. DdeUninitialize (lIdInst2);
  281. lIdInst2 = 0L;
  282. return (TRUE);
  283. }/* end AddProgramItems */
  284. #endif
  285. #endif