Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

405 lines
12 KiB

  1. #include "precomp.h"
  2. static void testURLHelper(LPCTSTR pcszUrl);
  3. static void setProxyDlgHelper(HWND hDlg, LPCTSTR pcszProxy, DWORD dwIdName, DWORD dwIdPort,
  4. BOOL fDef80);
  5. static void getProxyDlgHelper(HWND hDlg, LPTSTR pszProxy, DWORD dwIdName, DWORD dwIdPort);
  6. static void showBitmapHelper(HWND hControl, LPCTSTR pcszFileName, int nBitmapId, PHANDLE pBitmap);
  7. static BOOL copyAnimBmpHelper(HWND hDlg, LPTSTR pszBmp, LPCTSTR pcszWorkDir,
  8. LPCTSTR pcszNameStr, LPCTSTR pcszPathStr, LPCTSTR pcszInsFile);
  9. static BOOL copyLogoBmpHelper(HWND hDlg, LPTSTR pszBmp, LPCTSTR pcszLogoStr,
  10. LPCTSTR pcszWorkDir, LPCTSTR pcszInsFile);
  11. static BOOL copyWallPaperHelper(HWND hDlg, LPCTSTR pcszWallPaper, UINT nBitmapId,
  12. LPCTSTR pcszWorkDir, LPCTSTR pcszInsFile, BOOL fCopy);
  13. void WINAPI TestURLA(LPCSTR pcszUrl)
  14. {
  15. USES_CONVERSION;
  16. testURLHelper(A2CT(pcszUrl));
  17. }
  18. void WINAPI TestURLW(LPCWSTR pcwszUrl)
  19. {
  20. USES_CONVERSION;
  21. testURLHelper(W2CT(pcwszUrl));
  22. }
  23. void WINAPI SetProxyDlgA(HWND hDlg, LPCSTR pcszProxy, DWORD dwIdName, DWORD dwIdPort, BOOL fDef80)
  24. {
  25. USES_CONVERSION;
  26. setProxyDlgHelper(hDlg, A2CT(pcszProxy), dwIdName, dwIdPort, fDef80);
  27. }
  28. void WINAPI SetProxyDlgW(HWND hDlg, LPCWSTR pcwszProxy, DWORD dwIdName, DWORD dwIdPort, BOOL fDef80)
  29. {
  30. USES_CONVERSION;
  31. setProxyDlgHelper(hDlg, W2CT(pcwszProxy), dwIdName, dwIdPort, fDef80);
  32. }
  33. void WINAPI GetProxyDlgA(HWND hDlg, LPSTR pszProxy, DWORD dwIdName, DWORD dwIdPort)
  34. {
  35. TCHAR szProxyBuf[MAX_PATH];
  36. USES_CONVERSION;
  37. getProxyDlgHelper(hDlg, szProxyBuf, dwIdName, dwIdPort);
  38. T2Abux(szProxyBuf, pszProxy);
  39. }
  40. void WINAPI GetProxyDlgW(HWND hDlg, LPWSTR pwszProxy, DWORD dwIdName, DWORD dwIdPort)
  41. {
  42. TCHAR szProxyBuf[MAX_PATH];
  43. USES_CONVERSION;
  44. getProxyDlgHelper(hDlg, szProxyBuf, dwIdName, dwIdPort);
  45. T2Wbux(szProxyBuf, pwszProxy);
  46. }
  47. HPALETTE WINAPI BuildPalette(HDC hdc)
  48. {
  49. DWORD adw[257];
  50. int i,n;
  51. n = GetDIBColorTable(hdc, 0, 256, (LPRGBQUAD)&adw[1]);
  52. for(i = 1; i < n; i++)
  53. {
  54. adw[i] = RGB(GetBValue(adw[i]),GetGValue(adw[i]),GetRValue(adw[i]));
  55. }
  56. adw[0] = MAKELONG(0x300, n);
  57. return CreatePalette((LPLOGPALETTE)&adw[0]);
  58. }
  59. void WINAPI ShowBitmapA(HWND hControl, LPCSTR pcszFileName, int nBitmapId, PHANDLE pBitmap)
  60. {
  61. USES_CONVERSION;
  62. showBitmapHelper(hControl, A2CT(pcszFileName), nBitmapId, pBitmap);
  63. }
  64. void WINAPI ShowBitmapW(HWND hControl, LPCWSTR pcwszFileName, int nBitmapId, PHANDLE pBitmap)
  65. {
  66. USES_CONVERSION;
  67. showBitmapHelper(hControl, W2CT(pcwszFileName), nBitmapId, pBitmap);
  68. }
  69. BOOL WINAPI CopyAnimBmpA(HWND hDlg, LPSTR pszBmp, LPCSTR pcszWorkDir, LPCSTR pcszNameStr,
  70. LPCSTR pcszPathStr, LPCSTR pcszInsFile)
  71. {
  72. TCHAR szBmpBuf[MAX_PATH];
  73. BOOL fRet;
  74. USES_CONVERSION;
  75. A2Tbux(pszBmp, szBmpBuf);
  76. fRet = copyAnimBmpHelper(hDlg, szBmpBuf, A2CT(pcszWorkDir), A2CT(pcszNameStr),
  77. A2CT(pcszPathStr), A2CT(pcszInsFile));
  78. T2Abux(szBmpBuf, pszBmp);
  79. return fRet;
  80. }
  81. BOOL WINAPI CopyAnimBmpW(HWND hDlg, LPWSTR pwszBmp, LPCWSTR pcwszWorkDir, LPCWSTR pcwszNameStr,
  82. LPCWSTR pcwszPathStr, LPCWSTR pcwszInsFile)
  83. {
  84. TCHAR szBmpBuf[MAX_PATH];
  85. BOOL fRet;
  86. USES_CONVERSION;
  87. W2Tbux(pwszBmp, szBmpBuf);
  88. fRet = copyAnimBmpHelper(hDlg, szBmpBuf, W2CT(pcwszWorkDir), W2CT(pcwszNameStr),
  89. W2CT(pcwszPathStr), W2CT(pcwszInsFile));
  90. T2Wbux(szBmpBuf, pwszBmp);
  91. return fRet;
  92. }
  93. BOOL WINAPI CopyLogoBmpA(HWND hDlg, LPSTR pszBmp, LPCSTR pcszLogoStr,
  94. LPCSTR pcszWorkDir, LPCSTR pcszInsFile)
  95. {
  96. TCHAR szBmpBuf[MAX_PATH];
  97. BOOL fRet;
  98. USES_CONVERSION;
  99. A2Tbux(pszBmp, szBmpBuf);
  100. fRet = copyLogoBmpHelper(hDlg, szBmpBuf, A2CT(pcszLogoStr), A2CT(pcszWorkDir),
  101. A2CT(pcszInsFile));
  102. T2Abux(szBmpBuf, pszBmp);
  103. return fRet;
  104. }
  105. BOOL WINAPI CopyLogoBmpW(HWND hDlg, LPWSTR pwszBmp, LPCWSTR pcwszLogoStr,
  106. LPCWSTR pcwszWorkDir, LPCWSTR pcwszInsFile)
  107. {
  108. TCHAR szBmpBuf[MAX_PATH];
  109. BOOL fRet;
  110. USES_CONVERSION;
  111. W2Tbux(pwszBmp, szBmpBuf);
  112. fRet = copyLogoBmpHelper(hDlg, szBmpBuf, W2CT(pcwszLogoStr), W2CT(pcwszWorkDir),
  113. W2CT(pcwszInsFile));
  114. T2Wbux(szBmpBuf, pwszBmp);
  115. return fRet;
  116. }
  117. BOOL WINAPI CopyWallPaperA(HWND hDlg, LPCSTR pcszWallPaper, UINT nBitmapId,
  118. LPCSTR pcszWorkDir, LPCSTR pcszInsFile, BOOL fCopy)
  119. {
  120. USES_CONVERSION;
  121. return copyWallPaperHelper(hDlg, A2CT(pcszWallPaper), nBitmapId, A2CT(pcszWorkDir),
  122. A2CT(pcszInsFile), fCopy);
  123. }
  124. BOOL WINAPI CopyWallPaperW(HWND hDlg, LPCWSTR pcwszWallPaper, UINT nBitmapId,
  125. LPCWSTR pcwszWorkDir, LPCWSTR pcwszInsFile, BOOL fCopy)
  126. {
  127. USES_CONVERSION;
  128. return copyWallPaperHelper(hDlg, W2CT(pcwszWallPaper), nBitmapId, W2CT(pcwszWorkDir),
  129. W2CT(pcwszInsFile), fCopy);
  130. }
  131. static void testURLHelper(LPCTSTR pcszUrl)
  132. {
  133. TCHAR szCommand[MAX_PATH];
  134. DWORD cbSize;
  135. SHELLEXECUTEINFO shInfo;
  136. if(ISNULL(pcszUrl))
  137. return;
  138. // launch iexplore
  139. *szCommand = TEXT('\0');
  140. cbSize = sizeof(szCommand);
  141. SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE"),
  142. TEXT(""), NULL, (LPVOID) szCommand, &cbSize);
  143. ZeroMemory(&shInfo, sizeof(shInfo));
  144. shInfo.cbSize = sizeof(shInfo);
  145. shInfo.lpVerb = TEXT("open");
  146. if (*szCommand)
  147. {
  148. shInfo.lpFile = szCommand;
  149. shInfo.lpParameters = pcszUrl;
  150. }
  151. else
  152. shInfo.lpFile = pcszUrl; // this will launch the program that's registered for "http"
  153. shInfo.nShow = SW_SHOWNORMAL;
  154. ShellExecuteEx(&shInfo);
  155. }
  156. static void setProxyDlgHelper(HWND hDlg, LPCTSTR pcszProxy, DWORD dwIdName, DWORD dwIdPort,
  157. BOOL fDef80)
  158. {
  159. TCHAR szProxName[MAX_PATH];
  160. LPTSTR pProxPort;
  161. StrCpy(szProxName, pcszProxy);
  162. pProxPort = StrRChr(szProxName, NULL, TEXT(':'));
  163. if(pProxPort && isdigit(*(pProxPort + 1)))
  164. {
  165. *pProxPort = TEXT('\0');
  166. pProxPort++;
  167. }
  168. else if(fDef80) pProxPort = TEXT("80");
  169. else pProxPort = TEXT("");
  170. SetDlgItemText(hDlg, dwIdName, szProxName);
  171. SetDlgItemText(hDlg, dwIdPort, pProxPort);
  172. }
  173. static void getProxyDlgHelper(HWND hDlg, LPTSTR pszProxy, DWORD dwIdName, DWORD dwIdPort)
  174. {
  175. TCHAR szProxPort[16];
  176. LPTSTR pProxPort;
  177. BOOL fPortinprox = FALSE;
  178. GetDlgItemText(hDlg, dwIdName, pszProxy, MAX_PATH - 10);
  179. // this number needs to say in synch with the em_limittext's in the dlgproc's in
  180. // wizard and snapin
  181. GetDlgItemText(hDlg, dwIdPort, szProxPort, 6);
  182. pProxPort = StrRChr(pszProxy, NULL, TEXT(':'));
  183. if (pProxPort && isdigit(*(pProxPort + 1))) fPortinprox = TRUE;
  184. if (!fPortinprox && StrLen(szProxPort) && StrLen(pszProxy))
  185. {
  186. StrCat(pszProxy, TEXT(":"));
  187. StrCat(pszProxy, szProxPort);
  188. }
  189. }
  190. static void showBitmapHelper(HWND hControl, LPCTSTR pcszFileName, int nBitmapId, PHANDLE pBitmap)
  191. {
  192. BITMAP bmImage;
  193. HANDLE hImage = NULL;
  194. static HPALETTE hPalette = 0;
  195. HDC hDCMain;
  196. HDC hDCBitmap;
  197. RECT rect;
  198. if(hControl == NULL)
  199. {
  200. if(hPalette)
  201. {
  202. DeleteObject(hPalette);
  203. hPalette = 0;
  204. }
  205. return;
  206. }
  207. if(PathFileExists(pcszFileName) || nBitmapId)
  208. {
  209. if(nBitmapId)
  210. {
  211. hImage = LoadImage(g_hInst, MAKEINTRESOURCE(nBitmapId), IMAGE_BITMAP, 0, 0,
  212. LR_CREATEDIBSECTION);
  213. }
  214. else
  215. {
  216. hImage = LoadImage(NULL, pcszFileName, IMAGE_BITMAP, 0, 0,
  217. LR_LOADFROMFILE | LR_CREATEDIBSECTION);
  218. }
  219. if(hImage)
  220. {
  221. if(*pBitmap)
  222. {
  223. DeleteObject(*pBitmap);
  224. *pBitmap = NULL;
  225. }
  226. *pBitmap = hImage;
  227. }
  228. }
  229. else
  230. hImage = *pBitmap;
  231. if(hImage)
  232. {
  233. GetObject(hImage, sizeof(bmImage), &bmImage);
  234. hDCMain = GetDC(hControl);
  235. hDCBitmap = CreateCompatibleDC(hDCMain);
  236. SelectObject(hDCBitmap, hImage);
  237. if(hPalette == 0)
  238. hPalette = BuildPalette(hDCBitmap);
  239. SelectPalette(hDCMain, hPalette, FALSE);
  240. RealizePalette(hDCMain);
  241. GetClientRect(hControl, &rect);
  242. BitBlt(hDCMain, 0, 0, rect.right, rect.bottom, hDCBitmap, 0, 0, SRCCOPY);
  243. DeleteDC(hDCBitmap);
  244. ReleaseDC(hControl, hDCMain);
  245. }
  246. }
  247. static BOOL copyAnimBmpHelper(HWND hDlg, LPTSTR pszBmp, LPCTSTR pcszWorkDir,
  248. LPCTSTR pcszNameStr, LPCTSTR pcszPathStr, LPCTSTR pcszInsFile)
  249. {
  250. TCHAR szTemp[MAX_PATH];
  251. BOOL fBrandBmps = (IsDlgButtonChecked(hDlg, IDC_ANIMBITMAP) == BST_CHECKED);
  252. // delete the old file in the working dir
  253. if (fBrandBmps &&
  254. InsGetString(IS_ANIMATION, pcszNameStr, szTemp, countof(szTemp), pcszInsFile) &&
  255. ISNONNULL(szTemp))
  256. DeleteFileInDir(PathFindFileName(szTemp), pcszWorkDir);
  257. if (fBrandBmps && ISNONNULL(pszBmp))
  258. CopyFileToDir(pszBmp, pcszWorkDir);
  259. InsWriteString(IS_ANIMATION, pcszNameStr, PathFindFileName(pszBmp), pcszInsFile,
  260. fBrandBmps, NULL, INSIO_TRISTATE | INSIO_PATH);
  261. InsWriteString(IS_ANIMATION, pcszPathStr, pszBmp, pcszInsFile,
  262. fBrandBmps, NULL, INSIO_TRISTATE | INSIO_PATH);
  263. return TRUE;
  264. }
  265. static BOOL copyLogoBmpHelper(HWND hDlg, LPTSTR pszBmp, LPCTSTR pcszLogoStr,
  266. LPCTSTR pcszWorkDir, LPCTSTR pcszInsFile)
  267. {
  268. TCHAR szTemp[MAX_PATH];
  269. BOOL fBrandBmps = (IsDlgButtonChecked(hDlg, IDC_BITMAPCHECK) == BST_CHECKED);
  270. // delete the old bitmap in the working dir
  271. if (fBrandBmps &&
  272. InsGetString(pcszLogoStr, TEXT("Name"), szTemp, countof(szTemp), pcszInsFile) &&
  273. ISNONNULL(szTemp))
  274. DeleteFileInDir(PathFindFileName(szTemp), pcszWorkDir);
  275. if (fBrandBmps && ISNONNULL(pszBmp))
  276. CopyFileToDir(pszBmp, pcszWorkDir);
  277. InsWriteString(pcszLogoStr, TEXT("Name"), PathFindFileName(pszBmp), pcszInsFile,
  278. fBrandBmps, NULL, INSIO_TRISTATE | INSIO_PATH);
  279. InsWriteString(pcszLogoStr, TEXT("Path"), pszBmp, pcszInsFile,
  280. fBrandBmps, NULL, INSIO_TRISTATE | INSIO_PATH);
  281. return TRUE;
  282. }
  283. static BOOL copyWallPaperHelper(HWND hDlg, LPCTSTR pcszWallPaper, UINT nBitmapId,
  284. LPCTSTR pcszWorkDir, LPCTSTR pcszInsFile, BOOL fCopy)
  285. {
  286. TCHAR szDest[MAX_PATH];
  287. USES_CONVERSION;
  288. //clear the old data from the section
  289. WritePrivateProfileString(CUSTWALLPPR, NULL, NULL, pcszInsFile);
  290. if(fCopy)
  291. {
  292. if (!CheckField(hDlg, nBitmapId, FC_FILE | FC_EXISTS))
  293. return FALSE;
  294. WritePrivateProfileString( DESKTOP_OBJ_SECT, WLPPRPATH, pcszWallPaper, pcszInsFile );
  295. //delete old files from the working dir
  296. PathRemovePath(pcszWorkDir);
  297. CreateDirectory(pcszWorkDir, NULL);
  298. //copy new files to the working dir
  299. if(ISNONNULL(pcszWallPaper))
  300. {
  301. WritePrivateProfileString( DESKTOP_OBJ_SECT, OPTION, TEXT("1"), pcszInsFile );
  302. CopyFileToDir(pcszWallPaper, pcszWorkDir);
  303. WritePrivateProfileString( CUSTWALLPPR, NUMFILES, TEXT("1"), pcszInsFile);
  304. WritePrivateProfileString( CUSTWALLPPR, TEXT("file0"), PathFindFileName(pcszWallPaper), pcszInsFile);
  305. if(StrCmp(PathFindExtension(pcszWallPaper), TEXT(".htm")) == 0)
  306. CopyHtmlImgs(pcszWallPaper, pcszWorkDir, CUSTWALLPPR, pcszInsFile);
  307. }
  308. else
  309. WritePrivateProfileString( DESKTOP_OBJ_SECT, OPTION, TEXT("0"), pcszInsFile );
  310. }
  311. else //delete
  312. {
  313. //delete old files from the desktop dir ( if the files were saved )
  314. PathCombine(szDest, pcszWorkDir, PathFindFileName(pcszWallPaper));
  315. if(PathFileExists(szDest))
  316. {
  317. if(StrCmp(PathFindExtension(szDest), TEXT(".htm")) == 0)
  318. DeleteHtmlImgs(pcszWallPaper, pcszWorkDir, NULL, NULL);
  319. DeleteFile(szDest);
  320. }
  321. }
  322. return TRUE;
  323. }