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.

1514 lines
40 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: layoutui.cxx
  7. //
  8. // Contents: UI implementation on Docfile Layout Tool
  9. //
  10. // Classes: CLayoutApp
  11. //
  12. // Functions:
  13. //
  14. // History: 23-Mar-96 SusiA Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "layoutui.hxx"
  18. // Constants for File Addition dialogs
  19. #define MAX_FILES_BUFFER 2048
  20. #define MAX_TITLE_LEN 256
  21. #define MAX_FILTER_LEN 256
  22. #define MAX_PREFIX_LEN 5
  23. #define WIDTH 500
  24. #define HEIGHT 300
  25. #define NULL_TERM TEXT('\0')
  26. #define BACKSLASH TEXT("\\")
  27. #define SPACE TEXT(' ')
  28. #define MALLOC(x) LocalAlloc( LMEM_FIXED , x );
  29. #define FREE(x) LocalFree( x );
  30. #define JumpOnFail(sc) if( FAILED(sc) ) goto Err;
  31. #ifdef UNICODE
  32. #define STRING_LEN(x) Laylstrlen(x)
  33. #define CopyString(dst, src) Laylstrcpy(dst, src)
  34. #define CatString(dst, src) Laylstrcat(dst, src)
  35. #else
  36. #define STRING_LEN(x) lstrlen(x)
  37. #define CopyString(dst, src) lstrcpy(dst, src)
  38. #define CatString(dst, src) lstrcat(dst, src)
  39. #endif
  40. // Since the LayoutDlgProc must be static for the Callback,
  41. // we need a way to reference the member variables inside of
  42. // LayoutDlgProc
  43. static CLayoutApp *pStaticThis;
  44. #ifdef STRICT
  45. static WNDPROC lpfnwpListBoxProc = NULL;
  46. static WNDPROC lpfnwpButtonProc = NULL;
  47. #define SUBCLASS_WNDPROC WNDPROC
  48. #else
  49. static FARPROC lpfnwpListBoxProc = NULL;
  50. static FARPROC lpfnwpButtonProc = NULL;
  51. #define SUBCLASS_WNDPROC FARPROC
  52. #endif
  53. // currently supported version of NT
  54. #define NT_MAJOR_VER 3
  55. #define NT_MINOR_VER 51
  56. // currently supported version of Win95
  57. #define WIN95_MAJOR_VER 4
  58. BOOL g_fIsNT351 = FALSE;
  59. //+---------------------------------------------------------------------------
  60. //
  61. // Function IsOperatingSystemOK
  62. //
  63. // Synopsis: Checks to see if thid OS version is compatible
  64. // with this application.
  65. // NT40 Win95 and NT3.51 are supprted.
  66. // Sets g_fIsNT351
  67. //
  68. // History: 27-July-96 SusiA Created
  69. //
  70. //----------------------------------------------------------------------------
  71. BOOL IsOperatingSystemOK(void)
  72. {
  73. OSVERSIONINFO osversioninfo = {0};
  74. // get operating system info
  75. osversioninfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  76. if (!GetVersionEx(&osversioninfo))
  77. {
  78. return FALSE;
  79. }
  80. // if NT, check version
  81. if (osversioninfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
  82. {
  83. if ( osversioninfo.dwMajorVersion < NT_MAJOR_VER )
  84. {
  85. return FALSE;
  86. }
  87. if ( osversioninfo.dwMajorVersion == NT_MAJOR_VER )
  88. if ( osversioninfo.dwMinorVersion < NT_MINOR_VER )
  89. {
  90. return FALSE;
  91. }
  92. if ( osversioninfo.dwMajorVersion == NT_MAJOR_VER )
  93. if ( osversioninfo.dwMinorVersion == NT_MINOR_VER )
  94. {
  95. g_fIsNT351 = TRUE;
  96. return TRUE;
  97. }
  98. return TRUE;
  99. }
  100. // else if Win95 check version
  101. else if (osversioninfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  102. {
  103. if ( osversioninfo.dwMajorVersion < WIN95_MAJOR_VER )
  104. {
  105. return FALSE;
  106. }
  107. else
  108. {
  109. return TRUE;
  110. }
  111. }
  112. // else unrecognized OS (should never make it here)
  113. else
  114. {
  115. return FALSE;
  116. }
  117. }
  118. //+---------------------------------------------------------------------------
  119. //
  120. // Member: CLayoutApp::CLayoutApp public
  121. //
  122. //
  123. // History: 03-April-96 SusiA Created
  124. //
  125. //----------------------------------------------------------------------------
  126. CLayoutApp::CLayoutApp(HINSTANCE hInst)
  127. {
  128. m_hInst = hInst;
  129. m_hwndMain = hwndNil;
  130. pStaticThis = this;
  131. m_bOptimizing = FALSE;
  132. m_bCancelled = FALSE;
  133. }
  134. //+---------------------------------------------------------------------------
  135. //
  136. // Member: CLayoutApp::InitApp public
  137. //
  138. // Synopsis: Initialize the application
  139. //
  140. // Returns: TRUE is sucessful, FALSE is FAILED
  141. //
  142. // History: 03-April-96 SusiA Created
  143. //
  144. //----------------------------------------------------------------------------
  145. BOOL CLayoutApp::InitApp(void)
  146. {
  147. if (!IsOperatingSystemOK())
  148. {
  149. return FALSE;
  150. }
  151. if( !InitWindow() )
  152. {
  153. DisplayMessage(NULL,
  154. IDS_MAIN_WINDOW_FAIL,
  155. IDS_MAIN_WINDOW_FAIL_TITLE,
  156. MB_ICONSTOP);
  157. return FALSE;
  158. }
  159. return TRUE;
  160. }
  161. //+---------------------------------------------------------------------------
  162. //
  163. // Member: CLayoutApp::DoAppMessageLoop public
  164. //
  165. // Synopsis: Main window message loop
  166. //
  167. //
  168. // History: 03-April-96 SusiA Created
  169. //
  170. //----------------------------------------------------------------------------
  171. INT CLayoutApp::DoAppMessageLoop(void)
  172. {
  173. MSG msg;
  174. HACCEL hAccel;
  175. hAccel = LoadAccelerators( m_hInst, MAKEINTRESOURCE(IDR_ACCELERATOR1) );
  176. while (GetMessage (&msg, NULL, 0, 0))
  177. {
  178. if (m_hwndMain == 0 || !IsDialogMessage (m_hwndMain, &msg))
  179. {
  180. TranslateMessage (&msg) ;
  181. DispatchMessage (&msg) ;
  182. }
  183. }
  184. return (INT) msg.wParam;
  185. }
  186. //+---------------------------------------------------------------------------
  187. //
  188. // Member: CLayoutApp::InitWindow public
  189. //
  190. // Synopsis: Initialize the main window
  191. //
  192. // Returns: TRUE is sucessful, FALSE is FAILED
  193. //
  194. // History: 03-April-96 SusiA Created
  195. //
  196. //----------------------------------------------------------------------------
  197. BOOL CLayoutApp::InitWindow (void)
  198. {
  199. m_hwndMain = CreateDialog( m_hInst,
  200. MAKEINTRESOURCE(IDD_MAIN),
  201. NULL,
  202. (DLGPROC)LayoutDlgProc);
  203. if( m_hwndMain == NULL )
  204. return FALSE;
  205. EnableButtons();
  206. DragAcceptFiles(m_hwndMain, TRUE);
  207. return TRUE;
  208. }
  209. //+---------------------------------------------------------------------------
  210. //
  211. // Member: CLayoutApp::InitApp public
  212. //
  213. // Synopsis: Application Callback function
  214. //
  215. // Returns: TRUE is message was handled. FALSE otherwise
  216. //
  217. // History: 03-April-96 SusiA Created
  218. //
  219. //----------------------------------------------------------------------------
  220. LONG CALLBACK CLayoutApp::ListBoxWndProc(
  221. HWND hWnd,
  222. UINT uMsg,
  223. WPARAM wParam,
  224. LPARAM lParam)
  225. {
  226. switch (uMsg)
  227. {
  228. case WM_SETCURSOR:
  229. if( (HWND)wParam == pStaticThis->m_hwndMain )
  230. SetCursor(LoadCursor(NULL, (pStaticThis->m_bCancelled ? IDC_WAIT : IDC_ARROW)));
  231. return bMsgHandled;
  232. }
  233. return (LONG) CallWindowProc(lpfnwpListBoxProc, hWnd, uMsg, wParam, lParam);
  234. }
  235. LONG CALLBACK CLayoutApp::ButtonWndProc(
  236. HWND hWnd,
  237. UINT uMsg,
  238. WPARAM wParam,
  239. LPARAM lParam)
  240. {
  241. switch (uMsg)
  242. {
  243. case WM_SETCURSOR:
  244. if( (HWND)wParam == pStaticThis->m_hwndMain )
  245. SetCursor(LoadCursor(NULL, (pStaticThis->m_bCancelled ? IDC_WAIT : IDC_ARROW)));
  246. return bMsgHandled;
  247. }
  248. return (LONG) CallWindowProc(lpfnwpButtonProc, hWnd, uMsg, wParam, lParam);
  249. }
  250. BOOL CALLBACK CLayoutApp::LayoutDlgProc(
  251. HWND hDlg,
  252. UINT uMsg,
  253. WPARAM wParam,
  254. LPARAM lParam)
  255. {
  256. SCODE sc = S_OK;
  257. WORD wId = LOWORD((DWORD)wParam);
  258. WORD wNotifyCode = HIWORD((DWORD)wParam);
  259. DWORD thrdid;
  260. static HANDLE hthread;
  261. switch (uMsg)
  262. {
  263. case WM_INITDIALOG:
  264. pStaticThis->m_hwndBtnAdd = GetDlgItem( hDlg, IDC_BTN_ADD );
  265. pStaticThis->m_hwndBtnRemove = GetDlgItem( hDlg, IDC_BTN_REMOVE );
  266. pStaticThis->m_hwndBtnOptimize = GetDlgItem( hDlg, IDC_BTN_OPTIMIZE );
  267. pStaticThis->m_hwndListFiles = GetDlgItem( hDlg, IDC_LIST_FILES );
  268. pStaticThis->m_hwndStaticFiles = GetDlgItem( hDlg, IDC_STATIC_FILES );
  269. #ifdef _WIN64
  270. lpfnwpListBoxProc = (SUBCLASS_WNDPROC)SetWindowLongPtr(
  271. pStaticThis->m_hwndListFiles,
  272. GWLP_WNDPROC,
  273. (ULONG_PTR)MakeProcInstance(
  274. (FARPROC)ListBoxWndProc,
  275. pStaticThis->m_hInst
  276. )
  277. );
  278. lpfnwpButtonProc = (SUBCLASS_WNDPROC)SetWindowLongPtr(
  279. pStaticThis->m_hwndBtnAdd,
  280. GWLP_WNDPROC,
  281. (ULONG_PTR)MakeProcInstance(
  282. (FARPROC)ButtonWndProc,
  283. pStaticThis->m_hInst
  284. )
  285. );
  286. lpfnwpButtonProc = (SUBCLASS_WNDPROC)SetWindowLongPtr(
  287. pStaticThis->m_hwndBtnRemove,
  288. GWLP_WNDPROC,
  289. (ULONG_PTR)MakeProcInstance(
  290. (FARPROC)ButtonWndProc,
  291. pStaticThis->m_hInst
  292. )
  293. );
  294. lpfnwpButtonProc = (SUBCLASS_WNDPROC)SetWindowLongPtr(
  295. pStaticThis->m_hwndBtnOptimize,
  296. GWLP_WNDPROC,
  297. (ULONG_PTR)MakeProcInstance(
  298. (FARPROC)ButtonWndProc,
  299. pStaticThis->m_hInst
  300. )
  301. );
  302. #else
  303. lpfnwpListBoxProc = (SUBCLASS_WNDPROC)SetWindowLong(
  304. pStaticThis->m_hwndListFiles,
  305. GWL_WNDPROC,
  306. (LONG)(WNDPROC)MakeProcInstance(
  307. (FARPROC)ListBoxWndProc,
  308. pStaticThis->m_hInst
  309. )
  310. );
  311. lpfnwpButtonProc = (SUBCLASS_WNDPROC)SetWindowLong(
  312. pStaticThis->m_hwndBtnAdd,
  313. GWL_WNDPROC,
  314. (LONG)(WNDPROC)MakeProcInstance(
  315. (FARPROC)ButtonWndProc,
  316. pStaticThis->m_hInst
  317. )
  318. );
  319. lpfnwpButtonProc = (SUBCLASS_WNDPROC)SetWindowLong(
  320. pStaticThis->m_hwndBtnRemove,
  321. GWL_WNDPROC,
  322. (LONG)(WNDPROC)MakeProcInstance(
  323. (FARPROC)ButtonWndProc,
  324. pStaticThis->m_hInst
  325. )
  326. );
  327. lpfnwpButtonProc = (SUBCLASS_WNDPROC)SetWindowLong(
  328. pStaticThis->m_hwndBtnOptimize,
  329. GWL_WNDPROC,
  330. (LONG)(WNDPROC)MakeProcInstance(
  331. (FARPROC)ButtonWndProc,
  332. pStaticThis->m_hInst
  333. )
  334. );
  335. #endif // _WIN64
  336. // resize dialog and center it on the screen
  337. {
  338. RECT rcScreen;
  339. GetWindowRect(GetDesktopWindow(), &rcScreen);
  340. SetWindowPos(
  341. hDlg,
  342. HWND_TOP,
  343. (rcScreen.right - rcScreen.left - WIDTH) / 2,
  344. (rcScreen.bottom - rcScreen.top - HEIGHT) / 2,
  345. WIDTH,
  346. HEIGHT,
  347. SWP_SHOWWINDOW);
  348. }
  349. return TRUE;
  350. case WM_SIZE:
  351. pStaticThis->ReSizeWindow(lParam);
  352. return bMsgHandled;
  353. case WM_GETMINMAXINFO:
  354. {
  355. LPMINMAXINFO lpminmax = (LPMINMAXINFO) lParam;
  356. lpminmax->ptMinTrackSize.x = gdxWndMin;
  357. lpminmax->ptMinTrackSize.y = gdyWndMin;
  358. }
  359. return bMsgHandled;
  360. case WM_CLOSE:
  361. DestroyWindow(hDlg);
  362. PostQuitMessage(0);
  363. return bMsgHandled;
  364. case WM_DROPFILES:
  365. {
  366. TCHAR atcFileName[MAX_PATH];
  367. HDROP hdrop = (HDROP)wParam;
  368. INT nFiles = DragQueryFile(hdrop, 0xFFFFFFFF, NULL, 0);
  369. INT i;
  370. for( i=0; i < nFiles; i++ )
  371. {
  372. if( DragQueryFile(hdrop, i, atcFileName, MAX_PATH) != 0 )
  373. pStaticThis->AddFileToListBox(atcFileName);
  374. }
  375. DragFinish(hdrop);
  376. pStaticThis->EnableButtons();
  377. }
  378. return bMsgHandled;
  379. case WM_SETCURSOR:
  380. if( (HWND)wParam == pStaticThis->m_hwndMain )
  381. SetCursor(LoadCursor(NULL, (pStaticThis->m_bCancelled ? IDC_WAIT : IDC_ARROW)));
  382. return bMsgHandled;
  383. case WM_COMMAND:
  384. switch( wId )
  385. {
  386. case IDC_BTN_ADD:
  387. pStaticThis->AddFiles();
  388. return bMsgHandled;
  389. case IDC_BTN_REMOVE:
  390. pStaticThis->RemoveFiles();
  391. return bMsgHandled;
  392. case IDC_BTN_OPTIMIZE:
  393. if (pStaticThis->m_bOptimizing) //Cancel Button click
  394. {
  395. pStaticThis->m_bCancelled = TRUE;
  396. //SetCursor(LoadCursor(NULL, IDC_WAIT));
  397. return bMsgHandled;
  398. }
  399. else //Optimize Button Click
  400. {
  401. pStaticThis->m_bOptimizing = TRUE;
  402. pStaticThis->SetActionButton( IDS_CANCEL );
  403. hthread = CreateThread(NULL,0,
  404. (LPTHREAD_START_ROUTINE) &(pStaticThis->OptimizeFiles),
  405. NULL, 0, &thrdid);
  406. return bMsgHandled;
  407. }
  408. case IDC_LIST_FILES:
  409. switch( wNotifyCode )
  410. {
  411. case LBN_SELCHANGE:
  412. pStaticThis->EnableButtons();
  413. return bMsgHandled;
  414. default:
  415. break;
  416. }
  417. default:
  418. break;
  419. }
  420. break;
  421. }
  422. return bMsgNotHandled;
  423. }
  424. //+---------------------------------------------------------------------------
  425. //
  426. // Member: CLayoutApp::ReSizeWindow public
  427. //
  428. // Synopsis: Handle resizing the main dialog
  429. //
  430. // History: 03-April-96 SusiA Created
  431. //
  432. //----------------------------------------------------------------------------
  433. VOID CLayoutApp::ReSizeWindow (LPARAM lParam)
  434. {
  435. int nW = LOWORD(lParam);
  436. int nH = HIWORD(lParam);
  437. int nBorder = 10;
  438. int nButtonH = 25;
  439. int nButtonW = 100;
  440. int nStaticH = 15;
  441. int nListY = nBorder + nStaticH;
  442. int nListW = nW - 3 * nBorder - nButtonW;
  443. int nListH = nH - nListY - nBorder;
  444. int nButtonX = 2 * nBorder + nListW;
  445. MoveWindow(m_hwndStaticFiles, nBorder, nBorder, nListW, nStaticH, TRUE);
  446. MoveWindow(m_hwndListFiles , nBorder, nListY, nListW, nH - nButtonH - nBorder, TRUE);
  447. MoveWindow(m_hwndBtnAdd , nButtonX, nListY, nButtonW, nButtonH, TRUE);
  448. MoveWindow(m_hwndBtnRemove , nButtonX, nListY + 3 * nBorder, nButtonW, nButtonH, TRUE);
  449. MoveWindow(m_hwndBtnOptimize, nButtonX, nListY + nListH - nButtonH, nButtonW, nButtonH, TRUE);
  450. }
  451. //+---------------------------------------------------------------------------
  452. //
  453. // Member: CLayoutApp::AddFiles public
  454. //
  455. // Synopsis: Add and display selected files to the dialog window
  456. //
  457. //
  458. // History: 03-April-96 SusiA Created
  459. //
  460. //----------------------------------------------------------------------------
  461. VOID CLayoutApp::AddFiles (void)
  462. {
  463. //We add 1 to atcFile so that we can double null terminate
  464. //the string they give us in the 3.51 case
  465. TCHAR atcFile[MAX_FILES_BUFFER +1 ];
  466. TCHAR atcTitle[MAX_TITLE_LEN];
  467. TCHAR atcFilter[MAX_FILTER_LEN];
  468. OPENFILENAME ofn;
  469. FillMemory( (LPVOID)&ofn, sizeof(ofn), 0 );
  470. ofn.lStructSize = sizeof( ofn );
  471. ofn.hwndOwner = m_hwndMain;
  472. ofn.hInstance = m_hInst;
  473. FormFilterString( atcFilter, MAX_FILTER_LEN );
  474. ofn.lpstrFilter = atcFilter;
  475. ofn.lpstrCustomFilter = NULL;
  476. ofn.nFilterIndex = 0;
  477. *atcFile = NULL_TERM;
  478. ofn.lpstrFile = atcFile;
  479. ofn.nMaxFile = MAX_FILES_BUFFER;
  480. ofn.lpstrFileTitle = NULL;
  481. ofn.lpstrInitialDir = NULL;
  482. LoadString( m_hInst, IDS_ADDFILES_TITLE, atcTitle, MAX_TITLE_LEN );
  483. ofn.lpstrTitle = atcTitle;
  484. if (g_fIsNT351) //NT 3.51 doesn't support OFN_EXPLORER
  485. {
  486. ofn.Flags = OFN_ALLOWMULTISELECT |
  487. OFN_HIDEREADONLY |
  488. OFN_FILEMUSTEXIST |
  489. OFN_PATHMUSTEXIST;
  490. }
  491. else
  492. {
  493. ofn.Flags = OFN_ALLOWMULTISELECT |
  494. OFN_HIDEREADONLY |
  495. OFN_EXPLORER |
  496. OFN_FILEMUSTEXIST |
  497. OFN_PATHMUSTEXIST;
  498. }
  499. if( !GetOpenFileName( &ofn ) )
  500. {
  501. DWORD dw = CommDlgExtendedError();
  502. if( dw == FNERR_BUFFERTOOSMALL )
  503. DisplayMessage( m_hwndMain,
  504. IDS_ADDFILES_BUFFERTOOSMALL,
  505. IDS_ADDFILES_BUFFERTOOSMALL_TITLE,
  506. 0);
  507. return;
  508. }
  509. WriteFilesToList( atcFile );
  510. EnableButtons();
  511. }
  512. //+---------------------------------------------------------------------------
  513. //
  514. // Member: CLayoutApp::FormFilterString public
  515. //
  516. // Synopsis: Specifies which files (with which extension are to be displayed
  517. //
  518. // History: 03-April-96 SusiA Created
  519. //
  520. //----------------------------------------------------------------------------
  521. VOID CLayoutApp::FormFilterString( TCHAR *patcFilter, INT nMaxLen )
  522. {
  523. int nLen;
  524. UINT uStrID;
  525. //NOTE: the string resources must be in sequence
  526. uStrID = IDS_FILTER_BEGIN+1;
  527. // this is an internal function and so we aren't checking for
  528. // enough room in the string buffer, patcFilter
  529. while( uStrID != IDS_FILTER_END )
  530. {
  531. LoadString( m_hInst, uStrID++, patcFilter, nMaxLen );
  532. nLen = STRING_LEN( patcFilter );
  533. nMaxLen -= nLen + 1;
  534. patcFilter += nLen;
  535. *patcFilter++ = NULL_TERM;
  536. }
  537. *patcFilter = NULL_TERM;
  538. }
  539. //+---------------------------------------------------------------------------
  540. //
  541. // Member: CLayoutApp::WriteFilesToList public
  542. //
  543. // Synopsis: For NT4.0 and Win95
  544. // Gets and writes the files, complete with path, to the File List
  545. //
  546. // History: 03-April-96 SusiA Created
  547. //
  548. //----------------------------------------------------------------------------
  549. VOID CLayoutApp::WriteFilesToList( TCHAR *patcFilesList )
  550. {
  551. TCHAR *patcDir;
  552. TCHAR atcFile[MAX_PATH];
  553. BOOL bOneFile = TRUE;
  554. patcDir = patcFilesList;
  555. if (g_fIsNT351)
  556. {
  557. // NT 3.51 stores SPACES instead of NULLs
  558. // between multiple file names
  559. // so we need some preprocessing here
  560. while ( *patcFilesList != NULL_TERM )
  561. {
  562. if (*patcFilesList == SPACE)
  563. {
  564. *patcFilesList = NULL_TERM;
  565. }
  566. patcFilesList++;
  567. }
  568. // and we need to double NULL terminate
  569. *(++patcFilesList) = NULL_TERM;
  570. //reset the pointer to the start
  571. patcFilesList = patcDir;
  572. }
  573. while( *patcFilesList++ != NULL_TERM )
  574. ;
  575. while( *patcFilesList != NULL_TERM )
  576. {
  577. bOneFile = FALSE;
  578. CopyString( atcFile, patcDir );
  579. CatString( atcFile, BACKSLASH );
  580. CatString( atcFile, patcFilesList );
  581. AddFileToListBox( atcFile );
  582. while( *patcFilesList++ != NULL_TERM )
  583. ;
  584. }
  585. // if only one file was selected,
  586. // the filename isn't separated by it's path,
  587. // but is one complete filename
  588. if( bOneFile )
  589. {
  590. AddFileToListBox( patcDir );
  591. }
  592. }
  593. //+---------------------------------------------------------------------------
  594. //
  595. // Member: CLayoutApp::AddFileToListBox public
  596. //
  597. // Synopsis: displays the file to the dialog list box
  598. //
  599. //
  600. // History: 03-April-96 SusiA Created
  601. //
  602. //----------------------------------------------------------------------------
  603. VOID CLayoutApp::AddFileToListBox( TCHAR *patcFile )
  604. {
  605. // add the file iff the file is not already displayed
  606. if (LB_ERR == SendMessage(m_hwndListFiles,
  607. LB_FINDSTRING,
  608. (WPARAM)0,
  609. (LPARAM)(LPCTSTR)patcFile))
  610. {
  611. SendMessage(m_hwndListFiles,
  612. LB_ADDSTRING,
  613. (WPARAM)0,
  614. (LPARAM)(LPCTSTR)patcFile);
  615. }
  616. SetListBoxExtent();
  617. }
  618. //+---------------------------------------------------------------------------
  619. //
  620. // Member: CLayoutApp::RemoveFileFromListBox public
  621. //
  622. // Synopsis: remove the displayed the file from the dialog list box
  623. //
  624. // History: 03-April-96 SusiA Created
  625. //
  626. //----------------------------------------------------------------------------
  627. VOID CLayoutApp::RemoveFileFromListBox( INT nIndex )
  628. {
  629. SendMessage(m_hwndListFiles,
  630. LB_DELETESTRING,
  631. (WPARAM)nIndex,
  632. (LPARAM)0);
  633. SetListBoxExtent();
  634. }
  635. //+---------------------------------------------------------------------------
  636. //
  637. // Member: CLayoutApp::SetListBoxExtent public
  638. //
  639. // Synopsis: Handles making a horizontal scroll bar if necessary
  640. //
  641. // History: 03-April-96 SusiA Created
  642. //
  643. //----------------------------------------------------------------------------
  644. VOID CLayoutApp::SetListBoxExtent( void )
  645. {
  646. INT i;
  647. INT nExtent = 0;
  648. LPARAM nItems = SendMessage( m_hwndListFiles,
  649. LB_GETCOUNT,
  650. (WPARAM)0,
  651. (LPARAM)0);
  652. TCHAR atcFile[MAX_PATH];
  653. HDC hdc = NULL;
  654. SIZE size;
  655. if( nItems == 0 )
  656. goto lSetListBoxExtent_Exit;
  657. if( (hdc = GetDC(m_hwndMain)) == NULL)
  658. goto lSetListBoxExtent_Exit;
  659. for( i=0; i < (INT) nItems; i++ )
  660. {
  661. SendMessage(m_hwndListFiles,
  662. LB_GETTEXT,
  663. (WPARAM)i,
  664. (LPARAM)(LPCTSTR)atcFile);
  665. GetTextExtentPoint32(
  666. hdc,
  667. atcFile,
  668. STRING_LEN(atcFile),
  669. &size);
  670. nExtent = max(nExtent, (INT)size.cx);
  671. }
  672. lSetListBoxExtent_Exit:
  673. if( hdc )
  674. ReleaseDC( m_hwndMain, hdc );
  675. SendMessage(m_hwndListFiles,
  676. LB_SETHORIZONTALEXTENT,
  677. (WPARAM)nExtent,
  678. (LPARAM)0);
  679. }
  680. //+---------------------------------------------------------------------------
  681. //
  682. // Member: CLayoutApp::RemoveFiles public
  683. //
  684. // Synopsis: remove one or more files from displayed list
  685. //
  686. // History: 03-April-96 SusiA Created
  687. //
  688. //----------------------------------------------------------------------------
  689. VOID CLayoutApp::RemoveFiles (void)
  690. {
  691. INT i;
  692. INT *pnSelItems;;
  693. LPARAM nSelItems = SendMessage( m_hwndListFiles,
  694. LB_GETSELCOUNT,
  695. (WPARAM)0,
  696. (LPARAM)0);
  697. if( nSelItems == 0 )
  698. return;
  699. pnSelItems = (LPINT) MALLOC( sizeof(INT)* (INT)nSelItems );
  700. if( !pnSelItems )
  701. return;
  702. SendMessage(m_hwndListFiles,
  703. LB_GETSELITEMS,
  704. (WPARAM)nSelItems,
  705. (LPARAM)(LPINT)pnSelItems);
  706. // start from bottom of list to keep the indices correct
  707. for( i= (INT)nSelItems; --i >= 0; )
  708. RemoveFileFromListBox( pnSelItems[i] );
  709. FREE( pnSelItems );
  710. EnableButtons();
  711. }
  712. //+---------------------------------------------------------------------------
  713. //
  714. // Member: CLayoutApp::DisplayMessage public
  715. //
  716. // Synopsis: message box general routine with no file names
  717. //
  718. // History: 03-April-96 SusiA Created
  719. //
  720. //----------------------------------------------------------------------------
  721. INT CLayoutApp::DisplayMessage(HWND hWnd,
  722. UINT uMessageID,
  723. UINT uTitleID,
  724. UINT uFlags)
  725. {
  726. TCHAR atcMessage[MAX_PATH];
  727. TCHAR atcTitle[MAX_PATH];
  728. LoadString(m_hInst, uMessageID, atcMessage, MAX_PATH);
  729. LoadString(m_hInst, uTitleID, atcTitle, MAX_PATH);
  730. if( hWnd )
  731. SetForegroundWindow(hWnd);
  732. return MessageBox(hWnd, atcMessage, atcTitle, uFlags);
  733. }
  734. //+---------------------------------------------------------------------------
  735. //
  736. // Member: CLayoutApp::DisplayMessageWithFileName public
  737. //
  738. // Synopsis: message box general routine with 1 file name
  739. //
  740. // History: 03-April-96 SusiA Created
  741. //
  742. //----------------------------------------------------------------------------
  743. INT CLayoutApp::DisplayMessageWithFileName(HWND hWnd,
  744. UINT uMessageIDBefore,
  745. UINT uMessageIDAfter,
  746. UINT uTitleID,
  747. UINT uFlags,
  748. TCHAR *patcFileName)
  749. {
  750. TCHAR atcMessageBefore[MAX_PATH];
  751. TCHAR atcMessageAfter[MAX_PATH];
  752. TCHAR atcTitle[MAX_PATH];
  753. TCHAR atcFileErrorMsg[MAX_PATH*2];
  754. LoadString(m_hInst, uMessageIDBefore, atcMessageBefore, MAX_PATH);
  755. LoadString(m_hInst, uMessageIDAfter, atcMessageAfter, MAX_PATH);
  756. LoadString(m_hInst, uTitleID, atcTitle, MAX_PATH);
  757. CopyString(atcFileErrorMsg, atcMessageBefore);
  758. CatString(atcFileErrorMsg, patcFileName);
  759. CatString(atcFileErrorMsg, atcMessageAfter);
  760. if( hWnd )
  761. SetForegroundWindow(hWnd);
  762. return MessageBox(hWnd, atcFileErrorMsg, atcTitle, uFlags);
  763. }
  764. //+---------------------------------------------------------------------------
  765. //
  766. // Member: CLayoutApp::DisplayMessageWithTwoFileNames public
  767. //
  768. // Synopsis: message box general routine with 2 file names
  769. //
  770. // History: 03-April-96 SusiA Created
  771. //
  772. //----------------------------------------------------------------------------
  773. INT CLayoutApp::DisplayMessageWithTwoFileNames(HWND hWnd,
  774. UINT uMessageID,
  775. UINT uTitleID,
  776. UINT uFlags,
  777. TCHAR *patcFirstFileName,
  778. TCHAR *patcLastFileName)
  779. {
  780. TCHAR atcMessage[MAX_PATH];
  781. TCHAR atcTitle[MAX_PATH];
  782. TCHAR atcFileErrorMsg[MAX_PATH*2];
  783. LoadString(m_hInst, uMessageID, atcMessage, MAX_PATH);
  784. LoadString(m_hInst, uTitleID, atcTitle, MAX_PATH);
  785. CopyString(atcFileErrorMsg, patcFirstFileName);
  786. CatString(atcFileErrorMsg, atcMessage);
  787. CatString(atcFileErrorMsg, patcLastFileName);
  788. if( hWnd )
  789. SetForegroundWindow(hWnd);
  790. return MessageBox(hWnd, atcFileErrorMsg, atcTitle, uFlags);
  791. }
  792. //+---------------------------------------------------------------------------
  793. //
  794. // Member: CLayoutApp::EnableButtons public
  795. //
  796. // Synopsis: Updates the buttons. Optimize turns to Cancel
  797. // during optimize function.
  798. // Remove is greyed if no files are displayed
  799. //
  800. // History: 03-April-96 SusiA Created
  801. //
  802. //----------------------------------------------------------------------------
  803. VOID CLayoutApp::EnableButtons( BOOL bShowOptimizeBtn )
  804. {
  805. LPARAM nItems = SendMessage( m_hwndListFiles,
  806. LB_GETCOUNT,
  807. (WPARAM)0,
  808. (LPARAM)0);
  809. LPARAM nSelItems = SendMessage( m_hwndListFiles,
  810. LB_GETSELCOUNT,
  811. (WPARAM)0,
  812. (LPARAM)0);
  813. EnableWindow( m_hwndBtnAdd, TRUE );
  814. EnableWindow( m_hwndBtnRemove, nSelItems > 0 );
  815. EnableWindow( m_hwndBtnOptimize, nItems > 0 && bShowOptimizeBtn );
  816. }
  817. //+---------------------------------------------------------------------------
  818. //
  819. // Member: CLayoutApp::OptimizeFiles public
  820. //
  821. // Synopsis: Static function to call the optimizeFiles worker routine
  822. //
  823. // Returns: Appropriate status code
  824. //
  825. // History: 03-April-96 SusiA Created
  826. //
  827. //----------------------------------------------------------------------------
  828. DWORD CLayoutApp::OptimizeFiles (void *args)
  829. {
  830. SCODE sc;
  831. sc = CoInitialize(NULL);
  832. sc = pStaticThis->OptimizeFilesWorker();
  833. CoUninitialize();
  834. pStaticThis->HandleOptimizeReturnCode(sc);
  835. pStaticThis->m_bCancelled = FALSE;
  836. pStaticThis->SetActionButton( IDS_OPTIMIZE );
  837. pStaticThis->m_bOptimizing = FALSE;
  838. //SetCursor(LoadCursor(NULL, IDC_ARROW));
  839. return 0;
  840. }
  841. //+---------------------------------------------------------------------------
  842. //
  843. // Member: CLayoutApp::OptimizeFilesWorker public
  844. //
  845. // Synopsis: Optimize all the displayed files. Make temp files,
  846. // optimize to temp file, then rename temp back to original file.
  847. //
  848. // Returns: Appropriate status code
  849. //
  850. // History: 03-April-96 SusiA Created
  851. //
  852. //----------------------------------------------------------------------------
  853. SCODE CLayoutApp::OptimizeFilesWorker (void)
  854. {
  855. INT i, j;
  856. SCODE sc = S_OK;
  857. HRESULT hr;
  858. TCHAR atcFileName[MAX_PATH];
  859. TCHAR atcTempPath[MAX_PATH];
  860. TCHAR atcTempFile[MAX_PATH];
  861. TCHAR atcPrefix[MAX_PREFIX_LEN];
  862. TCHAR **ppatcTempFiles = NULL;
  863. INT *pintErrorFlag = NULL;
  864. INT nItems = (INT) SendMessage( m_hwndListFiles,
  865. LB_GETCOUNT,
  866. (WPARAM)0,
  867. (LPARAM)0 );
  868. if( nItems == 0 )
  869. return S_OK;
  870. ppatcTempFiles = (TCHAR **) MALLOC( sizeof(TCHAR *) * nItems );
  871. if( !ppatcTempFiles )
  872. return STG_E_INSUFFICIENTMEMORY;
  873. FillMemory( (LPVOID)ppatcTempFiles, sizeof(TCHAR *) * nItems, 0 );
  874. pintErrorFlag = (INT *) MALLOC( sizeof(INT) * nItems );
  875. if( !pintErrorFlag )
  876. {
  877. sc = STG_E_INSUFFICIENTMEMORY;
  878. JumpOnFail(sc);
  879. }
  880. FillMemory( (LPVOID)pintErrorFlag, sizeof(INT) * nItems, 0 );
  881. if( GetTempPath( MAX_PATH, atcTempPath ) == 0 )
  882. {
  883. sc = GetLastError();
  884. JumpOnFail(sc);
  885. }
  886. LoadString( m_hInst, IDS_TEMPFILE_PREFIX, atcPrefix, MAX_PREFIX_LEN );
  887. for( i=0; i < nItems; i++ )
  888. {
  889. // handle Cancel pressed and cleanup
  890. if (m_bCancelled)
  891. {
  892. m_bCancelled = FALSE;
  893. for( j=0; j < i ; j++ )
  894. DeleteFile(ppatcTempFiles[j]);
  895. sc = STG_E_NONEOPTIMIZED;
  896. JumpOnFail(sc);
  897. }
  898. if( GetTempFileName( atcTempPath, atcPrefix, (UINT)0, atcTempFile ) == 0 )
  899. {
  900. sc = GetLastError();
  901. JumpOnFail(sc);
  902. }
  903. ppatcTempFiles[i] =
  904. (TCHAR *) MALLOC( (STRING_LEN(atcTempFile) + 1) * sizeof(TCHAR) );
  905. if( !ppatcTempFiles[i] )
  906. {
  907. sc = STG_E_INSUFFICIENTMEMORY;
  908. JumpOnFail(sc);
  909. }
  910. CopyString( ppatcTempFiles[i], atcTempFile );
  911. }
  912. for( i=0; i < nItems; i++ )
  913. {
  914. // handle Cancel pressed and cleanup
  915. if (m_bCancelled)
  916. {
  917. m_bCancelled = FALSE;
  918. for( j=i; j < nItems ; j++ )
  919. {
  920. DeleteFile(ppatcTempFiles[j]);
  921. pintErrorFlag[j] = 1;
  922. }
  923. sc = STG_E_NONEOPTIMIZED;
  924. for( j=nItems; --j >= 0; )
  925. {
  926. if (pintErrorFlag[j])
  927. {
  928. RemoveFileFromListBox(j);
  929. }
  930. else
  931. {
  932. sc = S_OK;
  933. }
  934. }
  935. EnableButtons();
  936. goto Err;
  937. }
  938. SendMessage( m_hwndListFiles,
  939. LB_GETTEXT,
  940. (WPARAM)i,
  941. (LPARAM)(LPINT)atcFileName );
  942. sc = DoOptimizeFile( atcFileName, ppatcTempFiles[i] );
  943. #if DBG==1
  944. //check that files are identical here.
  945. if ((SUCCEEDED(sc)) && (!IdenticalFiles( atcFileName, ppatcTempFiles[i])))
  946. {
  947. sc = STG_E_DOCFILECORRUPT;
  948. }
  949. #endif
  950. if (!SUCCEEDED(sc))
  951. {
  952. // This file could not be optimized. Display Error message
  953. switch( sc )
  954. {
  955. // the file is read only
  956. case STG_E_ACCESSDENIED:
  957. DisplayMessageWithFileName(m_hwndMain,
  958. IDS_FILE_BEFORE,
  959. IDS_FILE_AFTER_READ_ONLY,
  960. IDS_OPTIMIZE_FAILED_TITLE,
  961. 0,
  962. atcFileName);
  963. break;
  964. // the file is not in a legal docfile format.
  965. case STG_E_FILEALREADYEXISTS:
  966. DisplayMessageWithFileName(m_hwndMain,
  967. IDS_FILE_BEFORE,
  968. IDS_FILE_AFTER_NOTDOCFILE,
  969. IDS_OPTIMIZE_FAILED_TITLE,
  970. 0,
  971. atcFileName);
  972. break;
  973. default:
  974. DisplayMessageWithFileName(m_hwndMain,
  975. IDS_FILE_BEFORE,
  976. IDS_OPTIMIZE_ERROR,
  977. IDS_OPTIMIZE_FAILED_TITLE,
  978. 0,
  979. atcFileName);
  980. break;
  981. }
  982. pintErrorFlag[i] = 1;
  983. DeleteFile( ppatcTempFiles[i] );
  984. continue;
  985. }
  986. //remove the (unoptimized) original file
  987. hr = DeleteFile( atcFileName );
  988. if (!hr)
  989. {
  990. sc = GetLastError();
  991. DisplayMessageWithFileName(m_hwndMain,
  992. IDS_FILE_BEFORE,
  993. IDS_DELETE_ERROR,
  994. IDS_OPTIMIZE_FAILED_TITLE,
  995. 0,
  996. atcFileName);
  997. DisplayMessageWithTwoFileNames(m_hwndMain,
  998. IDS_RENAME_MESSAGE,
  999. IDS_OPTIMIZE_FAILED_TITLE,
  1000. 0,
  1001. atcFileName,
  1002. ppatcTempFiles[i]);
  1003. SendMessage( m_hwndListFiles,
  1004. LB_DELETESTRING,
  1005. (WPARAM)i,
  1006. (LPARAM)0);
  1007. SendMessage( m_hwndListFiles,
  1008. LB_INSERTSTRING,
  1009. (WPARAM)i,
  1010. (LPARAM)(LPINT)ppatcTempFiles[i] );
  1011. continue;
  1012. }
  1013. // rename the optimized file to the original file name
  1014. hr = MoveFile( ppatcTempFiles[i], atcFileName );
  1015. if (!hr)
  1016. {
  1017. sc = GetLastError();
  1018. DisplayMessageWithFileName(m_hwndMain,
  1019. IDS_FILE_BEFORE,
  1020. IDS_RENAME_ERROR,
  1021. IDS_OPTIMIZE_FAILED_TITLE,
  1022. 0,
  1023. ppatcTempFiles[i]);
  1024. DisplayMessageWithTwoFileNames(m_hwndMain,
  1025. IDS_RENAME_MESSAGE,
  1026. IDS_OPTIMIZE_FAILED_TITLE,
  1027. 0,
  1028. atcFileName,
  1029. ppatcTempFiles[i]);
  1030. SendMessage( m_hwndListFiles,
  1031. LB_DELETESTRING,
  1032. (WPARAM)i,
  1033. (LPARAM)0);
  1034. SendMessage( m_hwndListFiles,
  1035. LB_INSERTSTRING,
  1036. (WPARAM)i,
  1037. (LPARAM)(LPINT)ppatcTempFiles[i] );
  1038. continue;
  1039. }
  1040. DeleteFile( ppatcTempFiles[i] );
  1041. }
  1042. // remove files from list box that could not be optimized
  1043. //bSuccess is set if at least one file was sucessfully optimized.
  1044. sc = STG_E_NONEOPTIMIZED;
  1045. for( i=nItems; --i >= 0; )
  1046. {
  1047. if (pintErrorFlag[i])
  1048. {
  1049. RemoveFileFromListBox(i);
  1050. }
  1051. else
  1052. {
  1053. sc = S_OK;
  1054. }
  1055. }
  1056. EnableButtons();
  1057. Err:
  1058. if ( pintErrorFlag )
  1059. FREE( pintErrorFlag);
  1060. if( ppatcTempFiles )
  1061. {
  1062. for( i=0; i < nItems; i++ )
  1063. {
  1064. if( ppatcTempFiles[i] )
  1065. FREE( ppatcTempFiles[i] );
  1066. }
  1067. FREE( ppatcTempFiles );
  1068. }
  1069. return sc;
  1070. }
  1071. //+---------------------------------------------------------------------------
  1072. //
  1073. // Member: CLayoutApp::DoOptimizeFile public
  1074. //
  1075. // Synopsis: Monitor and relayout docfile to temp file.
  1076. //
  1077. // Returns: Appropriate status code
  1078. //
  1079. // History: 03-April-96 SusiA Created
  1080. //
  1081. //----------------------------------------------------------------------------
  1082. SCODE CLayoutApp::DoOptimizeFile( TCHAR *patcFileName, TCHAR *patcTempFile )
  1083. {
  1084. IStorage *pStg = NULL;
  1085. ILayoutStorage *pLayoutStg = NULL;
  1086. IUnknown *punkApp = NULL;
  1087. IPersistStorage *pPersist = NULL;
  1088. IOleObject *pObj = NULL;
  1089. COleClientSite *pSite = NULL;
  1090. SCODE sc = S_OK;
  1091. STATSTG stat;
  1092. OLECHAR awcNewFileName[MAX_PATH];
  1093. sc = StgOpenLayoutDocfile
  1094. (TCharToOleChar(patcFileName, awcNewFileName, MAX_PATH),
  1095. STGM_DIRECT |
  1096. STGM_READWRITE |
  1097. STGM_SHARE_EXCLUSIVE,
  1098. NULL,
  1099. &pStg);
  1100. JumpOnFail(sc);
  1101. sc = pStg->QueryInterface( IID_ILayoutStorage, (void**) &pLayoutStg );
  1102. JumpOnFail(sc);
  1103. pStg->Release();
  1104. // begin monitoring
  1105. sc = pLayoutStg->BeginMonitor();
  1106. JumpOnFail(sc);
  1107. sc = pStg->Stat(&stat, STATFLAG_NONAME);
  1108. JumpOnFail(sc);
  1109. // open the application type of the input storage
  1110. sc = CoCreateInstance( stat.clsid,
  1111. NULL,
  1112. (CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_NO_CODE_DOWNLOAD),
  1113. IID_IUnknown,
  1114. (void**) &punkApp );
  1115. JumpOnFail(sc);
  1116. // load the document through the IPersistStorage Interface
  1117. sc = punkApp->QueryInterface( IID_IPersistStorage, (void**) &pPersist );
  1118. JumpOnFail(sc);
  1119. punkApp->Release();
  1120. sc = pPersist->Load( pStg );
  1121. JumpOnFail(sc);
  1122. sc = punkApp->QueryInterface( IID_IOleObject, (void**) &pObj );
  1123. JumpOnFail(sc);
  1124. punkApp->Release();
  1125. // Open as a client
  1126. pSite = new COleClientSite;
  1127. pSite->m_patcFile = patcFileName;
  1128. sc = pObj->DoVerb(OLEIVERB_OPEN, NULL, (IOleClientSite*) pSite, 0, NULL, NULL);
  1129. JumpOnFail(sc);
  1130. pObj->Close( OLECLOSE_NOSAVE );
  1131. // end monitoring and relayout
  1132. if( pLayoutStg )
  1133. {
  1134. sc = pLayoutStg->EndMonitor();
  1135. JumpOnFail(sc);
  1136. sc = pLayoutStg->ReLayoutDocfile(
  1137. TCharToOleChar(patcTempFile, awcNewFileName, MAX_PATH) );
  1138. JumpOnFail(sc);
  1139. }
  1140. Err:
  1141. if( pStg )
  1142. pStg->Release();
  1143. if( punkApp )
  1144. punkApp->Release();
  1145. if( pSite )
  1146. pSite->Release();
  1147. return sc;
  1148. }
  1149. //+---------------------------------------------------------------------------
  1150. //
  1151. // Member: CLayoutApp::HandleOptimizeReturnCode public
  1152. //
  1153. // Synopsis: message box general routine to display apprpriate message
  1154. // based on the Optimize returned SCODE
  1155. //
  1156. // History: 03-April-96 SusiA Created
  1157. //
  1158. //----------------------------------------------------------------------------
  1159. VOID CLayoutApp::HandleOptimizeReturnCode( SCODE sc )
  1160. {
  1161. switch( sc )
  1162. {
  1163. case S_OK:
  1164. DisplayMessage(m_hwndMain, IDS_OPTIMIZE_SUCCESS, IDS_OPTIMIZE_SUCCESS_TITLE, 0);
  1165. break;
  1166. case STG_E_FILENOTFOUND:
  1167. case STG_E_INSUFFICIENTMEMORY:
  1168. DisplayMessage(m_hwndMain, IDS_OPTIMIZE_OUTOFMEM, IDS_OPTIMIZE_OUTOFMEM_TITLE, 0);
  1169. break;
  1170. case STG_E_PATHNOTFOUND:
  1171. DisplayMessage(m_hwndMain, IDS_OPTIMIZE_NOPATH, IDS_OPTIMIZE_NOPATH_TITLE, 0);
  1172. break;
  1173. case STG_E_NONEOPTIMIZED:
  1174. // already displayed errors for why each file could not be optimized.
  1175. break;
  1176. default:
  1177. DisplayMessage(m_hwndMain, IDS_OPTIMIZE_FAILED, IDS_OPTIMIZE_FAILED_TITLE, 0);
  1178. break;
  1179. }
  1180. }
  1181. //+---------------------------------------------------------------------------
  1182. //
  1183. // Member: CLayoutApp::TCharToOleChar public
  1184. //
  1185. // Synopsis: helper function for UNICODE/ANSI TCHAR to OLEchar conversion
  1186. //
  1187. // History: 03-April-96 SusiA Created
  1188. //
  1189. //----------------------------------------------------------------------------
  1190. OLECHAR *CLayoutApp::TCharToOleChar(TCHAR *patcSrc, OLECHAR *pawcDst, INT nDstLen)
  1191. {
  1192. #ifdef UNICODE
  1193. // this is already UNICODE
  1194. return patcSrc;
  1195. #else
  1196. UINT uCodePage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
  1197. *pawcDst = NULL_TERM;
  1198. // convert to UNICODE
  1199. MultiByteToWideChar(
  1200. uCodePage,
  1201. 0,
  1202. patcSrc,
  1203. -1,
  1204. pawcDst,
  1205. nDstLen-1 );
  1206. return pawcDst;
  1207. #endif
  1208. }
  1209. //+---------------------------------------------------------------------------
  1210. //
  1211. // Member: CLayoutApp::SetActionButton public
  1212. //
  1213. // Synopsis: change the text of the button
  1214. //
  1215. // History: 03-April-96 SusiA Created
  1216. //
  1217. //----------------------------------------------------------------------------
  1218. VOID CLayoutApp::SetActionButton( UINT uID )
  1219. {
  1220. TCHAR atcText[MAX_PATH];
  1221. LoadString( m_hInst, uID, atcText, MAX_PATH );
  1222. SetWindowText( m_hwndBtnOptimize, atcText );
  1223. UpdateWindow( m_hwndMain );
  1224. }