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.

691 lines
24 KiB

  1. #include "pch.h"
  2. #include "resource.h"
  3. #include "main.h"
  4. #include <stdio.h>
  5. //-------------------------------------------------------------------------//
  6. // 'General' page impl
  7. //-------------------------------------------------------------------------//
  8. // CreateIntance, DlgProc
  9. HWND CALLBACK GeneralPage_CreateInstance( HWND hwndParent );
  10. INT_PTR CALLBACK GeneralPage_DlgProc( HWND hwndPage, UINT, WPARAM , LPARAM );
  11. // Message Handlers
  12. LRESULT CALLBACK GeneralPage_OnThemeSelected( HWND hwndPage, UINT, WPARAM, HWND, BOOL&);
  13. LRESULT CALLBACK GeneralPage_OnColorSelected( HWND hwndPage, UINT, WPARAM, HWND, BOOL&);
  14. LRESULT CALLBACK GeneralPage_OnEdit( HWND hwndPage, UINT, WPARAM, HWND, BOOL&);
  15. LRESULT CALLBACK GeneralPage_OnInitDialog(HWND hwndPage, UINT, WPARAM, LPARAM, BOOL&);
  16. LRESULT CALLBACK GeneralPage_OnDestroy( HWND hwndPage, UINT, WPARAM, LPARAM, BOOL&);
  17. // Misc
  18. BOOL CALLBACK GeneralPage_AddProccessNamesCB( HWND hwnd, LPARAM lParam );
  19. void GeneralPage_AddProcessNamesToCombos( HWND hwndPage );
  20. // Utility Methods
  21. void GeneralPage_RefreshThemeName( HWND hwndPage );
  22. BOOL GeneralPage_EnumProc( enum THEMECALLBACK tcbType, LPCWSTR pszName, LPCWSTR pszDisplayName,
  23. LPCWSTR pszToolTip, int iIndex, LPARAM lParam );
  24. void GeneralPage_AddProcessNamesToCombos( HWND hwndPage );
  25. void GeneralPage_EnableDlgButtons( HWND hwndPage );
  26. void GeneralPage_RebuildThemes(HWND hwndPage, LPCWSTR pszCurrentTheme);
  27. HWND g_hwndGeneralPage = NULL;
  28. //-------------------------------------------------------------------------//
  29. void ExpandDirIntoFullThemeFileName(LPCWSTR pszSubDir, LPWSTR pszFileName)
  30. {
  31. //---- turn this into a real theme file name ----
  32. WCHAR szRelativeDir[_MAX_PATH+1];
  33. StringCchPrintfW(szRelativeDir, ARRAYSIZE(szRelativeDir),
  34. L"%s\\%s.msstyles", pszSubDir, pszSubDir);
  35. WCHAR *pszBaseName;
  36. GetFullPathName(szRelativeDir, MAX_PATH, pszFileName, &pszBaseName);
  37. }
  38. //-------------------------------------------------------------------------//
  39. INT_PTR CALLBACK GeneralPage_DlgProc( HWND hwndPage, UINT uMsg, WPARAM wParam, LPARAM lParam )
  40. {
  41. BOOL bHandled = TRUE;
  42. LRESULT lRet = 0L;
  43. switch( uMsg )
  44. {
  45. case WM_INITDIALOG:
  46. lRet = GeneralPage_OnInitDialog( hwndPage, uMsg, wParam, lParam, bHandled );
  47. break;
  48. case WM_COMMAND:
  49. {
  50. HWND hwndCtl = (HWND)lParam;
  51. UINT uCode = HIWORD(wParam);
  52. switch( LOWORD(wParam) )
  53. {
  54. case IDC_TESTBUTTON:
  55. lRet = GeneralPage_OnTestButton( hwndPage, uMsg, wParam, hwndCtl, bHandled );
  56. break;
  57. case IDC_CLEARBUTTON:
  58. lRet = GeneralPage_OnClearButton( hwndPage, uMsg, wParam, hwndCtl, bHandled );
  59. break;
  60. case IDC_DIRNAME:
  61. lRet = GeneralPage_OnThemeSelected( hwndPage, uMsg, wParam, hwndCtl, bHandled );
  62. break;
  63. case IDC_COLORCOMBO:
  64. lRet = GeneralPage_OnColorSelected( hwndPage, uMsg, wParam, hwndCtl, bHandled );
  65. break;
  66. case IDC_EDIT_THEME:
  67. lRet = GeneralPage_OnEdit( hwndPage, uMsg, wParam, hwndCtl, bHandled );
  68. break;
  69. case IDC_TARGET:
  70. case IDC_UNTARGET:
  71. if( CBN_DROPDOWN == uCode )
  72. {
  73. // Keep process names fresh.
  74. GeneralPage_AddProcessNamesToCombos( hwndPage );
  75. }
  76. break;
  77. }
  78. GeneralPage_EnableDlgButtons( hwndPage );
  79. break;
  80. }
  81. case WM_DESTROY:
  82. lRet = GeneralPage_OnDestroy( hwndPage, uMsg, wParam, lParam, bHandled );
  83. break;
  84. default:
  85. bHandled = FALSE;
  86. break;
  87. }
  88. return bHandled;
  89. }
  90. //-------------------------------------------------------------------------//
  91. HWND CALLBACK GeneralPage_CreateInstance( HWND hwndParent )
  92. {
  93. g_hwndGeneralPage = CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_PAGE_GENERAL),
  94. hwndParent, GeneralPage_DlgProc );
  95. return g_hwndGeneralPage;
  96. }
  97. //---------------------------------------------------------------------------
  98. BOOL ThemeEnumerator(enum THEMECALLBACK tcbType, LPCWSTR pszName,
  99. LPCWSTR pszDisplayName, LPCWSTR pszToolTip, int iIndex, LPARAM lParam)
  100. {
  101. HWND combo = (HWND)lParam;
  102. WCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szBase[_MAX_FNAME], szExt[_MAX_EXT];
  103. WCHAR szBaseName[MAX_PATH];
  104. _tsplitpath(pszName, szDrive, szDir, szBase, szExt);
  105. StringCchPrintfW(szBaseName, ARRAYSIZE(szBaseName), L".\\%s\\%s%s", szBase, szBase, szExt);
  106. int index = (int)SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)szBaseName);
  107. if (! index) // first one added
  108. {
  109. ::SetWindowText(combo, szBaseName);
  110. //---- simulate a selection change ----
  111. ::SendMessage(combo, CB_SETCURSEL, 0, 0);
  112. }
  113. return TRUE;
  114. }
  115. //---------------------------------------------------------------------------
  116. void GeneralPage_RebuildThemes(HWND hwndPage, LPCWSTR pszCurrentTheme)
  117. {
  118. HWND hwndCombo = GetDlgItem(hwndPage, IDC_DIRNAME);
  119. SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
  120. WCHAR szFullDir[_MAX_PATH+1];
  121. WCHAR *pszBaseName;
  122. DWORD val = GetFullPathName(L".", ARRAYSIZE(szFullDir), szFullDir, &pszBaseName);
  123. if (! val)
  124. {
  125. MessageBox(NULL, L"GetFullPathName() failure", L"Error", MB_OK);
  126. return;
  127. }
  128. //---- enum actual theme DLL's ----
  129. HRESULT hr = EnumThemes(szFullDir, ThemeEnumerator, (LPARAM)hwndCombo);
  130. ATLASSERT(SUCCEEDED(hr));
  131. //---- enum theme subdirs ----
  132. HANDLE hFile = NULL;
  133. BOOL bFile = TRUE;
  134. WIN32_FIND_DATA wfd;
  135. hr = S_FALSE; // assume interrupted until we complete
  136. bFile = TRUE;
  137. for( hFile = FindFirstFile( TEXT("*.*"), &wfd ); hFile != INVALID_HANDLE_VALUE && bFile;
  138. bFile = FindNextFile( hFile, &wfd ) )
  139. {
  140. WCHAR *p = wfd.cFileName;
  141. if(! ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ))
  142. continue;
  143. if ((lstrcmp(wfd.cFileName, TEXT("."))==0) || (lstrcmp(wfd.cFileName, TEXT(".."))==0))
  144. continue;
  145. if (_tcsicmp(p, _TEXT("obj"))==0) // dev directory
  146. continue;
  147. SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)wfd.cFileName);
  148. }
  149. //---- select the first theme ----
  150. int index = (int)SendMessage(hwndCombo, CB_FINDSTRINGEXACT, 0, (LPARAM)pszCurrentTheme);
  151. if (index < 0)
  152. index = 0;
  153. SendMessage(hwndCombo, CB_SETCURSEL, index, NULL);
  154. }
  155. //---------------------------------------------------------------------------
  156. LRESULT GeneralPage_OnInitDialog(HWND hwndPage, UINT, WPARAM wid, LPARAM, BOOL&)
  157. {
  158. GeneralPage_RefreshThemeName( hwndPage );
  159. #if 0 // testing SetWindowTheme()
  160. HWND hwndOK = GetDlgItem(hwndPage, IDC_TESTBUTTON);
  161. if (hwndOK)
  162. SetWindowTheme(hwndOK, L"themeok", NULL);
  163. HWND hwndCancel = GetDlgItem(hwndPage, IDC_CLEARBUTTON);
  164. if (hwndCancel)
  165. SetWindowTheme(hwndCancel, NULL, L"CancelButton");
  166. #endif
  167. GeneralPage_RebuildThemes(hwndPage, DEFAULT_THEME);
  168. //---- simulate a selection ----
  169. BOOL mybool;
  170. GeneralPage_OnThemeSelected(hwndPage, 0, 0, 0, mybool);
  171. GeneralPage_AddProcessNamesToCombos( hwndPage );
  172. CheckDlgButton( hwndPage, IDC_THEME_ALL, *g_options.szTargetApp == 0 );
  173. CheckDlgButton( hwndPage, IDC_THEME_PROCESS, *g_options.szTargetApp != 0 && !g_options.fExceptTarget);
  174. CheckDlgButton( hwndPage, IDC_THEME_EXEMPT, *g_options.szTargetApp != 0 && g_options.fExceptTarget );
  175. CheckDlgButton( hwndPage, IDC_THEME_PREVIEW, g_options.hwndPreviewTarget != 0 );
  176. CheckDlgButton( hwndPage, IDC_ENABLE_FRAME, g_options.fEnableFrame );
  177. CheckDlgButton( hwndPage, IDC_ENABLE_DLG, g_options.fEnableDialog );
  178. CheckDlgButton( hwndPage, IDC_USERSWITCH, g_options.fUserSwitch );
  179. GeneralPage_EnableDlgButtons( hwndPage );
  180. //---- set preview edit text to hwndPage ----
  181. WCHAR szBuff[_MAX_PATH+1];
  182. StringCchPrintfW(szBuff, ARRAYSIZE(szBuff), L"%x", hwndPage);
  183. SetDlgItemText(hwndPage, IDC_PREVIEW, szBuff);
  184. return 0;
  185. }
  186. //---------------------------------------------------------------------------
  187. void GeneralPage_EnableDlgButtons( HWND hwndPage )
  188. {
  189. EnableWindow( GetDlgItem( hwndPage, IDC_TARGET ), IsDlgButtonChecked( hwndPage, IDC_THEME_PROCESS )!=0 );
  190. EnableWindow( GetDlgItem( hwndPage, IDC_UNTARGET ), IsDlgButtonChecked( hwndPage, IDC_THEME_EXEMPT )!=0 );
  191. EnableWindow( GetDlgItem( hwndPage, IDC_PREVIEW ), IsDlgButtonChecked( hwndPage, IDC_THEME_PREVIEW )!=0 );
  192. }
  193. //---------------------------------------------------------------------------
  194. LRESULT GeneralPage_OnDumpTheme()
  195. {
  196. HTHEME hTheme = OpenThemeData(NULL, L"globals");
  197. if (hTheme)
  198. {
  199. HTHEMEFILE hThemeFile;
  200. if (SUCCEEDED(OpenThemeFileFromData(hTheme, &hThemeFile)))
  201. {
  202. HRESULT hr = DumpLoadedThemeToTextFile(hThemeFile, L"theme.dmp", TRUE, TRUE);
  203. if (FAILED(hr))
  204. MessageBox(NULL, L"DumpLoadedThemeToTextFile() Failed", L"Error", MB_OK);
  205. CloseThemeFile(hThemeFile);
  206. }
  207. CloseThemeData(hTheme);
  208. }
  209. return 0;
  210. }
  211. //---------------------------------------------------------------------------
  212. LRESULT GeneralPage_OnTestButton( HWND hwndPage, UINT, WPARAM, HWND, BOOL&)
  213. {
  214. //---- get theme szFileName ----
  215. WCHAR szThemeFileName[_MAX_PATH+1];
  216. GetDlgItemText(hwndPage, IDC_DIRNAME, szThemeFileName, ARRAYSIZE(szThemeFileName));
  217. //---- is it a dir? ----
  218. DWORD dwMask = GetFileAttributes(szThemeFileName);
  219. BOOL fDir = ((dwMask != 0xffffffff) && (dwMask & FILE_ATTRIBUTE_DIRECTORY));
  220. if (fDir) // do auto convert to a .msstyles file
  221. {
  222. //---- run "packthem" against the dir ----
  223. WCHAR szDirName[_MAX_PATH+1];
  224. StringCchCopyW(szDirName, ARRAYSIZE(szDirName), szThemeFileName);
  225. WCHAR szCmdLine[2*_MAX_PATH+1];
  226. StringCchPrintfW(szCmdLine, ARRAYSIZE(szCmdLine), L"/e %s", szDirName);
  227. HRESULT hr = SyncCmdLineRun(L"packthem.exe", szCmdLine);
  228. if (FAILED(hr))
  229. {
  230. LPWSTR szErrMsg;
  231. hr = AllocateTextFile(L"packthem.err", &szErrMsg, NULL);
  232. if (FAILED(hr))
  233. {
  234. MessageBox(NULL, L"Unknown Error", L"Error in packing Theme", MB_OK);
  235. return FALSE;
  236. }
  237. MessageBox(NULL, szErrMsg, L"Error in packing Theme", MB_OK);
  238. LocalFree(szErrMsg);
  239. return FALSE;
  240. }
  241. GeneralPage_RebuildThemes(hwndPage, szDirName);
  242. //---- convert into a DLL name ----
  243. ExpandDirIntoFullThemeFileName(szDirName, szThemeFileName);
  244. }
  245. WCHAR ColorParam[MAX_PATH+1];
  246. WCHAR SizeParam[MAX_PATH+1];
  247. *ColorParam = 0;
  248. *SizeParam = 0;
  249. //---- extract ColorParam ----
  250. HWND hwndCombo;
  251. hwndCombo = GetDlgItem(hwndPage, IDC_COLORCOMBO);
  252. int index;
  253. index = (int)SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  254. if (index > -1)
  255. SendMessage(hwndCombo, CB_GETLBTEXT, index, (LPARAM)ColorParam);
  256. //---- extract SizeParam ----
  257. hwndCombo = GetDlgItem(hwndPage, IDC_SIZECOMBO);
  258. index = (int)SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  259. if (index > -1)
  260. SendMessage(hwndCombo, CB_GETLBTEXT, index, (LPARAM)SizeParam);
  261. g_options.fExceptTarget = IsDlgButtonChecked( hwndPage, IDC_THEME_EXEMPT ) != 0;
  262. if( g_options.fExceptTarget )
  263. {
  264. GetDlgItemText( hwndPage, IDC_UNTARGET,
  265. g_options.szTargetApp,
  266. ARRAYSIZE(g_options.szTargetApp) );
  267. }
  268. else if( IsDlgButtonChecked( hwndPage, IDC_THEME_PROCESS ) != 0 )
  269. {
  270. GetDlgItemText( hwndPage, IDC_TARGET,
  271. g_options.szTargetApp,
  272. ARRAYSIZE(g_options.szTargetApp) );
  273. }
  274. else
  275. *g_options.szTargetApp = 0;
  276. //---- extract Preview info ----
  277. g_options.hwndPreviewTarget = GetPreviewHwnd(hwndPage);
  278. g_options.fEnableFrame = IsDlgButtonChecked( hwndPage, IDC_ENABLE_FRAME ) != 0;
  279. g_options.fEnableDialog = IsDlgButtonChecked( hwndPage, IDC_ENABLE_DLG ) != 0;
  280. g_options.fUserSwitch = IsDlgButtonChecked( hwndPage, IDC_USERSWITCH ) != 0;
  281. _ApplyTheme(szThemeFileName, ColorParam, SizeParam, NULL);
  282. GeneralPage_RefreshThemeName( hwndPage );
  283. return TRUE;
  284. }
  285. //---------------------------------------------------------------------------
  286. HWND GetPreviewHwnd(HWND hwndGeneralPage)
  287. {
  288. if (! hwndGeneralPage)
  289. return NULL;
  290. BOOL fPreview = IsDlgButtonChecked( hwndGeneralPage, IDC_THEME_PREVIEW ) != 0;
  291. if (! fPreview)
  292. return NULL;
  293. WCHAR szTempBuff[_MAX_PATH+1];
  294. GetDlgItemText(hwndGeneralPage, IDC_PREVIEW, szTempBuff, ARRAYSIZE(szTempBuff));
  295. LONG val;
  296. int cnt = swscanf(szTempBuff, L"%lx", &val);
  297. if (! cnt)
  298. val = 0;
  299. return (HWND)IntToPtr(val);
  300. }
  301. //---------------------------------------------------------------------------
  302. LRESULT GeneralPage_OnClearButton(HWND hwndPage, UINT, WPARAM, HWND, BOOL&)
  303. {
  304. #if 0 // testing SetWindowTheme()
  305. HWND hwndOK = GetDlgItem(hwndPage, IDC_TESTBUTTON);
  306. if (hwndOK)
  307. SetWindowTheme(hwndOK, NULL, NULL);
  308. HWND hwndCancel = GetDlgItem(hwndPage, IDC_CLEARBUTTON);
  309. if (hwndCancel)
  310. SetWindowTheme(hwndCancel, NULL, NULL);
  311. #endif
  312. _RestoreSystemSettings(hwndPage, TRUE);
  313. GeneralPage_RefreshThemeName( hwndPage );
  314. return 0;
  315. }
  316. //---------------------------------------------------------------------------
  317. LRESULT GeneralPage_OnThemeSelected( HWND hwndPage, UINT, WPARAM, HWND, BOOL&)
  318. {
  319. //---- get theme szFileName ----
  320. WCHAR szFileName[MAX_PATH+1];
  321. WCHAR szSubDir[MAX_PATH+1];
  322. HWND hwndCombo = GetDlgItem(hwndPage, IDC_DIRNAME);
  323. int index = (int)SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  324. if (index == -1)
  325. *szFileName = 0;
  326. else
  327. {
  328. ::SendMessage(hwndCombo, CB_GETLBTEXT, index, (LPARAM)szSubDir);
  329. //---- turn this into a real theme file name ----
  330. ExpandDirIntoFullThemeFileName(szSubDir, szFileName);
  331. }
  332. //---- enum the theme colors ----
  333. HWND hwnd = GetDlgItem(hwndPage, IDC_COLORCOMBO);
  334. ::SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  335. for (DWORD c=0; ; c++)
  336. {
  337. THEMENAMEINFO names;
  338. if (FAILED(EnumThemeColors(szFileName, NULL, c, &names)))
  339. break;
  340. ::SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)names.szName);
  341. }
  342. //---- remove choices if only 1 entry ----
  343. if (c < 2)
  344. {
  345. ::SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  346. ::EnableWindow(hwnd, FALSE);
  347. }
  348. else
  349. {
  350. ::EnableWindow(hwnd, TRUE);
  351. SendMessage(hwnd, CB_SETCURSEL, 0, 0);
  352. }
  353. BOOL fDummy;
  354. GeneralPage_OnColorSelected(hwndPage, 0, 0, 0, fDummy);
  355. WCHAR szBuff[MAX_PATH+1];
  356. HRESULT hr;
  357. //---- update DisplayName ----
  358. hr = GetThemeDocumentationProperty(szFileName, L"DisplayName", szBuff, ARRAYSIZE(szBuff));
  359. if (FAILED(hr))
  360. StringCchCopyW(szBuff, ARRAYSIZE(szBuff), L"<not available>");
  361. SetDlgItemText(hwndPage, IDC_DISPLAYNAME, szBuff);
  362. //---- update ToolTip ----
  363. hr = GetThemeDocumentationProperty(szFileName, L"Tooltip", szBuff, ARRAYSIZE(szBuff));
  364. if (FAILED(hr))
  365. StringCchCopyW(szBuff, ARRAYSIZE(szBuff), L"<not available>");
  366. SetDlgItemText(hwndPage, IDC_TOOLTIP, szBuff);
  367. //---- update Author ----
  368. hr = GetThemeDocumentationProperty(szFileName, L"author", szBuff, ARRAYSIZE(szBuff));
  369. if (FAILED(hr))
  370. StringCchCopyW(szBuff, ARRAYSIZE(szBuff), L"<not available>");
  371. SetDlgItemText(hwndPage, IDC_AUTHOR, szBuff);
  372. return 1;
  373. }
  374. //---------------------------------------------------------------------------
  375. LRESULT GeneralPage_OnColorSelected( HWND hwndPage, UINT, WPARAM, HWND, BOOL&)
  376. {
  377. //---- get theme szFileName ----
  378. WCHAR szFileName[MAX_PATH+1];
  379. HWND hwndCombo = GetDlgItem(hwndPage, IDC_DIRNAME);
  380. int index = (int)SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  381. if (index == -1)
  382. *szFileName = 0;
  383. else
  384. ::SendMessage(hwndCombo, CB_GETLBTEXT, index, (LPARAM)szFileName);
  385. //---- get the currently selected color ----
  386. WCHAR szColor[_MAX_PATH+1];
  387. HWND hwnd = GetDlgItem(hwndPage, IDC_COLORCOMBO);
  388. GetWindowText(hwnd, szColor, ARRAYSIZE(szColor));
  389. //---- get the current size name ----
  390. WCHAR szSizeName[MAX_PATH+1];
  391. HWND hwndSize = GetDlgItem(hwndPage, IDC_SIZECOMBO);
  392. GetWindowText(hwndSize, szSizeName, ARRAYSIZE(szSizeName));
  393. //---- enum the theme sizes for the specified color ----
  394. hwnd = GetDlgItem(hwndPage, IDC_SIZECOMBO);
  395. if (* szColor) // only set size if a color is set
  396. {
  397. ::SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  398. for (DWORD s=0; ; s++) // enumerate sizes
  399. {
  400. THEMENAMEINFO names;
  401. if (FAILED(EnumThemeSizes(szFileName, szColor, s, &names)))
  402. break;
  403. ::SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)names.szName);
  404. }
  405. //---- remove choices if only 1 entry ----
  406. if (s < 2)
  407. {
  408. ::SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  409. ::EnableWindow(hwnd, FALSE);
  410. }
  411. else
  412. {
  413. ::EnableWindow(hwnd, TRUE);
  414. //---- try to select previously set size ----
  415. int index = (int)SendMessage(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)szSizeName);
  416. if (index == -1)
  417. index = 0;
  418. SendMessage(hwnd, CB_SETCURSEL, index, 0);
  419. }
  420. }
  421. else
  422. {
  423. ::SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  424. ::EnableWindow(hwnd, FALSE);
  425. }
  426. return 1;
  427. }
  428. //---------------------------------------------------------------------------
  429. LRESULT GeneralPage_OnEdit( HWND hwndPage, UINT, WPARAM, HWND, BOOL&)
  430. {
  431. //---- get theme szFileName ----
  432. WCHAR szBuff[1024];
  433. WCHAR szFileName[MAX_PATH+1];
  434. HWND hwndCombo = GetDlgItem(hwndPage, IDC_DIRNAME);
  435. int index = (int)SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  436. if (index == -1)
  437. *szFileName = 0;
  438. else
  439. {
  440. ::SendMessage(hwndCombo, CB_GETLBTEXT, index, (LPARAM)szBuff);
  441. WCHAR *p = wcschr(szBuff, L'.');
  442. if (p)
  443. *p = 0; // remove file extension of DLL name
  444. WCHAR *pStart = wcsrchr(szBuff, L'\\');
  445. if (pStart)
  446. pStart++;
  447. else
  448. pStart = szBuff;
  449. //---- try for classdata file; fallback onto container file ----
  450. StringCchPrintfW(szFileName, ARRAYSIZE(szFileName), L"%s\\%s", pStart, USUAL_CLASSDATA_NAME);
  451. if (! FileExists(szFileName))
  452. StringCchPrintfW(szFileName, ARRAYSIZE(szFileName), L"%s\\%s", pStart, CONTAINER_NAME);
  453. }
  454. HANDLE hInst = CmdLineRun(L"notepad.exe", szFileName, FALSE);
  455. CloseHandle(hInst);
  456. return 1;
  457. }
  458. //---------------------------------------------------------------------------
  459. LRESULT GeneralPage_OnDestroy( HWND hwndPage, UINT, WPARAM wid, LPARAM, BOOL&)
  460. {
  461. return 0;
  462. }
  463. //---------------------------------------------------------------------------
  464. void GeneralPage_RefreshThemeName( HWND hwndPage )
  465. {
  466. WCHAR szName[MAX_PATH+1];
  467. WCHAR szColor[MAX_PATH+1];
  468. WCHAR szSize[MAX_PATH+1];
  469. WCHAR szTitle[1024];
  470. BOOL fThemeActive = IsThemeActive();
  471. if (fThemeActive)
  472. {
  473. HRESULT hr = GetCurrentThemeName(szName, ARRAYSIZE(szName),
  474. szColor, ARRAYSIZE(szColor), szSize, ARRAYSIZE(szSize));
  475. if (FAILED(hr))
  476. StringCchCopyW(szName, ARRAYSIZE(szName), L"<unavailable>");
  477. else if (! *szName)
  478. StringCchCopyW(szTitle, ARRAYSIZE(szTitle), g_szAppTitle);
  479. else
  480. {
  481. //---- remove all dirs preceeding last backslash ----
  482. WCHAR *p = wcsrchr(szName, L'\\');
  483. if (p)
  484. StringCchPrintfW(szTitle, ARRAYSIZE(szTitle), L"%s - %s", p+1, g_szAppTitle);
  485. else
  486. StringCchPrintfW(szTitle, ARRAYSIZE(szTitle), L"%s - %s", szName, g_szAppTitle);
  487. }
  488. }
  489. else
  490. StringCchCopyW(szTitle, ARRAYSIZE(szTitle), g_szAppTitle);
  491. HWND hMain = GetParent(GetParent(hwndPage));
  492. SetWindowText(hMain, szTitle);
  493. }
  494. //---------------------------------------------------------------------------
  495. BOOL GeneralPage_EnumProc( enum THEMECALLBACK tcbType, LPCWSTR pszName,
  496. LPCWSTR pszDisplayName, LPCWSTR pszToolTip, int iIndex, LPARAM lParam )
  497. {
  498. HWND hwnd = (HWND)lParam;
  499. ::SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)pszName);
  500. return TRUE;
  501. }
  502. //---------------------------------------------------------------------------
  503. BOOL CALLBACK GeneralPage_AddProccessNamesCB( HWND hwnd, LPARAM lParam )
  504. {
  505. HWND hwndPage = (HWND)lParam;
  506. _ASSERTE( IsWindow(hwndPage) );
  507. DWORD dwProcessID = 0;
  508. if( !GetWindowThreadProcessId( hwnd, &dwProcessID ) )
  509. return TRUE;
  510. HANDLE hProcess = OpenProcess( PROCESS_VM_READ|PROCESS_QUERY_INFORMATION, FALSE, dwProcessID );
  511. if( NULL == hProcess )
  512. return TRUE;
  513. HMODULE rghModules[64];
  514. DWORD cbRet1 = 0;
  515. if( EnumProcessModules( hProcess, rghModules, sizeof(rghModules), &cbRet1 ) )
  516. {
  517. for( UINT j = 0; j < (min( cbRet1, sizeof(rghModules) ))/sizeof(DWORD); j++ )
  518. {
  519. TCHAR szModule[MAX_PATH];
  520. if( GetModuleFileNameEx( hProcess, rghModules[j], szModule, ARRAYSIZE(szModule) ) )
  521. {
  522. CharLower( szModule );
  523. TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szApp[_MAX_FNAME], szExt[_MAX_EXT];
  524. _tsplitpath(szModule, szDrive, szDir, szApp, szExt);
  525. if( 0 == lstrcmp( szExt, TEXT(".exe") ) )
  526. {
  527. if( SendDlgItemMessage( hwndPage, IDC_TARGET, CB_FINDSTRINGEXACT, -1, (LPARAM)szApp ) == CB_ERR )
  528. {
  529. INT_PTR iSel = (INT_PTR)SendDlgItemMessage( hwndPage, IDC_TARGET, CB_ADDSTRING, -1, (LPARAM)szApp );
  530. if( 0 == lstrcmpi( szApp, g_options.szTargetApp ) )
  531. SendDlgItemMessage( hwndPage, IDC_TARGET, CB_SETCURSEL, iSel, 0L );
  532. }
  533. if( SendDlgItemMessage( hwndPage, IDC_UNTARGET, CB_FINDSTRINGEXACT, -1, (LPARAM)szApp ) == CB_ERR )
  534. {
  535. INT_PTR iSel = (INT_PTR)SendDlgItemMessage( hwndPage, IDC_UNTARGET, CB_ADDSTRING, -1, (LPARAM)szApp );
  536. if( 0 == lstrcmpi( szApp, g_options.szTargetApp ) )
  537. SendDlgItemMessage( hwndPage, IDC_UNTARGET, CB_SETCURSEL, iSel, 0L );
  538. }
  539. }
  540. }
  541. }
  542. }
  543. CloseHandle( hProcess );
  544. return TRUE;
  545. }
  546. //---------------------------------------------------------------------------
  547. void GeneralPage_AddProcessNamesToCombos( HWND hwndPage )
  548. {
  549. //---- this will enum all windows (top level & all child levels) ----
  550. EnumChildWindows( GetDesktopWindow(), GeneralPage_AddProccessNamesCB, (LPARAM)hwndPage );
  551. if( *g_options.szTargetApp )
  552. {
  553. if( CB_ERR == SendDlgItemMessage( hwndPage, IDC_TARGET, CB_GETCURSEL, 0, 0L ) )
  554. {
  555. INT_PTR iSel = SendDlgItemMessage( hwndPage, IDC_TARGET, CB_ADDSTRING, -1,
  556. (LPARAM)g_options.szTargetApp );
  557. SendDlgItemMessage( hwndPage, IDC_TARGET, CB_SETCURSEL, iSel, 0L );
  558. }
  559. if( CB_ERR == SendDlgItemMessage( hwndPage, IDC_UNTARGET, CB_GETCURSEL, 0, 0L ) )
  560. {
  561. INT_PTR iSel = SendDlgItemMessage( hwndPage, IDC_UNTARGET, CB_ADDSTRING, -1,
  562. (LPARAM)g_options.szTargetApp );
  563. SendDlgItemMessage( hwndPage, IDC_UNTARGET, CB_SETCURSEL, iSel, 0L );
  564. }
  565. }
  566. }