Source code of Windows XP (NT5)
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.

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