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.

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