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.

712 lines
19 KiB

  1. #include "pch.hxx"
  2. #include "globals.h"
  3. #include "resource.h"
  4. #include "util.h"
  5. #include "frame.h"
  6. #include "mehost.h"
  7. void SaveFocus(BOOL fActive, HWND *phwnd);
  8. CMDIFrame::CMDIFrame()
  9. {
  10. m_hwnd = 0;
  11. m_hToolbar = 0;
  12. m_hStatusbar = 0;
  13. m_fToolbar = TRUE;
  14. m_fStatusbar = TRUE;
  15. m_cRef = 1;
  16. m_pInPlaceActiveObj=0;
  17. m_hwndFocus=0;
  18. }
  19. CMDIFrame::~CMDIFrame()
  20. {
  21. SafeRelease(m_pInPlaceActiveObj);
  22. }
  23. ULONG CMDIFrame::AddRef()
  24. {
  25. return ++m_cRef;
  26. }
  27. ULONG CMDIFrame::Release()
  28. {
  29. if (--m_cRef==0)
  30. {
  31. delete this;
  32. return 0;
  33. }
  34. return m_cRef;
  35. }
  36. HRESULT CMDIFrame::QueryInterface(REFIID riid, LPVOID *lplpObj)
  37. {
  38. if(!lplpObj)
  39. return E_INVALIDARG;
  40. *lplpObj = NULL; // set to NULL, in case we fail.
  41. if (IsEqualIID(riid, IID_IOleInPlaceFrame))
  42. *lplpObj = (LPVOID)(LPOLEINPLACEFRAME)this;
  43. else if (IsEqualIID(riid, IID_IOleInPlaceUIWindow))
  44. *lplpObj = (LPVOID)(IOleInPlaceUIWindow *)this;
  45. else
  46. return E_NOINTERFACE;
  47. AddRef();
  48. return NOERROR;
  49. }
  50. HRESULT CMDIFrame::HrInit(LPSTR pszCmdLine)
  51. {
  52. static char szAppName[] = "Mepad";
  53. HWND hwnd = NULL;
  54. WNDCLASSEX wndclass;
  55. HRESULT hr=E_FAIL;
  56. wndclass.cbSize = sizeof(wndclass);
  57. wndclass.style = 0;
  58. wndclass.lpfnWndProc = CMDIFrame::ExtWndProc;
  59. wndclass.cbClsExtra = 0;
  60. wndclass.cbWndExtra = 0;
  61. wndclass.hInstance = g_hInst;
  62. wndclass.hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(idiApp));
  63. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  64. wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  65. wndclass.lpszMenuName = MAKEINTRESOURCE(idmrMainMenu);
  66. wndclass.lpszClassName = szAppName;
  67. wndclass.hIconSm = LoadIcon(g_hInst, MAKEINTRESOURCE(idiApp));
  68. RegisterClassEx(&wndclass);
  69. hwnd = CreateWindowEx(WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT,
  70. szAppName,
  71. "Mepad",
  72. WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
  73. CW_USEDEFAULT, CW_USEDEFAULT,
  74. CW_USEDEFAULT, CW_USEDEFAULT,
  75. NULL, NULL, g_hInst, (LPVOID)this);
  76. if(!hwnd)
  77. goto error;
  78. ShowWindow(hwnd, SW_SHOWNORMAL);
  79. UpdateWindow(hwnd);
  80. hr = NOERROR;
  81. if (pszCmdLine)
  82. hr = OpenDoc(pszCmdLine);
  83. error:
  84. return hr;
  85. }
  86. LRESULT CALLBACK CMDIFrame::ExtWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  87. {
  88. CMDIFrame *pFrame=0;
  89. if(msg==WM_CREATE)
  90. {
  91. pFrame=(CMDIFrame *)((LPCREATESTRUCT)lParam)->lpCreateParams;
  92. if(pFrame && pFrame->WMCreate(hwnd))
  93. return 0;
  94. else
  95. return -1;
  96. }
  97. pFrame = (CMDIFrame *)GetWindowLong(hwnd, GWL_USERDATA);
  98. if(pFrame)
  99. return pFrame->WndProc(hwnd, msg, wParam, lParam);
  100. else
  101. return DefWindowProc(hwnd, msg, wParam, lParam);
  102. }
  103. enum
  104. {
  105. itbNew,
  106. itbOpen,
  107. itbSave,
  108. itbBack,
  109. itbForward,
  110. itbPrint,
  111. itbAbout,
  112. itbEditDoc,
  113. ctbToolbar
  114. };
  115. #define cxButtonSep 8
  116. #define dxToolbar 16
  117. #define dxStatusbar 14
  118. static TBBUTTON rgtbbutton[] =
  119. {
  120. { itbNew, idmNew,
  121. TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, -1 },
  122. { itbOpen, idmOpen,
  123. TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, -1 },
  124. { itbSave, idmSave,
  125. TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, -1 },
  126. { itbEditDoc, idmEditDocument,
  127. TBSTATE_ENABLED, TBSTYLE_BUTTON|TBSTYLE_CHECK, {0}, 0L, -1 }
  128. };
  129. #define ctbbutton (sizeof(rgtbbutton) / sizeof(TBBUTTON))
  130. BOOL CMDIFrame::WMCreate(HWND hwnd)
  131. {
  132. HMENU hMenu;
  133. MENUITEMINFO mii;
  134. hMenu = GetMenu(hwnd);
  135. mii.cbSize = sizeof(MENUITEMINFO);
  136. mii.fMask = MIIM_ID | MIIM_SUBMENU;
  137. GetMenuItemInfo(hMenu, idmPopupWindow, FALSE, &mii);
  138. SetWindowLong(hwnd, GWL_USERDATA, (LONG)this);
  139. AddRef();
  140. m_hwnd=hwnd;
  141. // toolbar
  142. m_hToolbar = CreateToolbarEx(
  143. hwnd,
  144. WS_CLIPCHILDREN|WS_CHILD|TBSTYLE_TOOLTIPS|WS_VISIBLE|WS_BORDER,
  145. 0,
  146. ctbToolbar,
  147. g_hInst,
  148. idbToolbar,
  149. rgtbbutton, ctbbutton,
  150. dxToolbar, dxToolbar, dxToolbar, dxToolbar,
  151. sizeof(TBBUTTON));
  152. m_hStatusbar = CreateWindowEx(
  153. 0,
  154. STATUSCLASSNAME,
  155. "",
  156. WS_CHILD|WS_VISIBLE|WS_BORDER|SBS_SIZEGRIP,
  157. 0,0,0,0,
  158. hwnd,
  159. 0,
  160. g_hInst,
  161. NULL);
  162. CLIENTCREATESTRUCT ccs;
  163. ccs.hWindowMenu = (HMENU)mii.hSubMenu;
  164. ccs.idFirstChild = 100;
  165. m_hwndClient = CreateWindowEx(
  166. 0,
  167. "MDICLIENT",
  168. "",
  169. WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
  170. 0,0,0,0,
  171. hwnd,
  172. 0,
  173. g_hInst,
  174. (LPVOID)&ccs);
  175. SendMessage(m_hwndClient, WM_MDISETMENU, (WPARAM)hMenu, (LPARAM)mii.hSubMenu);
  176. SetToolbar();
  177. SetStatusbar();
  178. return TRUE;
  179. }
  180. void CMDIFrame::WMDestroy()
  181. {
  182. PostQuitMessage(0);
  183. SetWindowLong(m_hwnd, GWL_USERDATA, 0);
  184. Release();
  185. }
  186. LRESULT CMDIFrame::WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  187. {
  188. LONG lRet;
  189. switch (iMsg)
  190. {
  191. case WM_CLOSE:
  192. HWND hwndKid;
  193. hwndKid = ::GetWindow(m_hwndClient, GW_CHILD);
  194. while (hwndKid)
  195. {
  196. if (SendMessage(hwndKid, WM_CLOSE, 0, 0))
  197. return 1;
  198. hwndKid = ::GetWindow(hwndKid, GW_HWNDNEXT);
  199. }
  200. break;
  201. case WM_ACTIVATE:
  202. if (m_pInPlaceActiveObj)
  203. m_pInPlaceActiveObj->OnFrameWindowActivate(LOWORD(wParam) != WA_INACTIVE);
  204. break;
  205. case WM_SIZE:
  206. WMSize();
  207. return 0;
  208. case WM_COMMAND:
  209. if(HrWMCommand(GET_WM_COMMAND_HWND(wParam, lParam),
  210. GET_WM_COMMAND_ID(wParam, lParam),
  211. GET_WM_COMMAND_CMD(wParam, lParam))==S_OK)
  212. return 0;
  213. break;
  214. case WM_NOTIFY:
  215. WMNotify(wParam, (NMHDR*)lParam);
  216. return 0;
  217. case WM_INITMENUPOPUP:
  218. return WMInitMenuPopup(hwnd, (HMENU)wParam, (UINT)LOWORD(lParam));
  219. case WM_MENUSELECT:
  220. if(m_hStatusbar)
  221. HandleMenuSelect(m_hStatusbar, wParam, lParam);
  222. return 0;
  223. case WM_DESTROY :
  224. WMDestroy();
  225. return 0 ;
  226. }
  227. lRet = DefFrameProc(hwnd, m_hwndClient, iMsg, wParam, lParam);
  228. if(iMsg==WM_ACTIVATE)
  229. {
  230. // post-process wm_activates to set focus back to
  231. // controls
  232. SaveFocus((BOOL)(LOWORD(wParam)), &m_hwndFocus);
  233. }
  234. return lRet;
  235. }
  236. void CMDIFrame::WMNotify(WPARAM wParam, NMHDR* pnmhdr)
  237. {
  238. switch(pnmhdr->code)
  239. {
  240. case TTN_NEEDTEXT:
  241. ProcessTooltips((LPTOOLTIPTEXT) pnmhdr);
  242. break;
  243. }
  244. }
  245. HRESULT CMDIFrame::HrWMCommand(HWND hwnd, int id, WORD wCmd)
  246. {
  247. HWND hwndChild;
  248. CMeHost *pHost;
  249. HRESULT hr = S_FALSE;
  250. switch(id)
  251. {
  252. case idmOptions:
  253. DoOptions();
  254. break;
  255. case idmToggleToolbar:
  256. m_fToolbar = !m_fToolbar;
  257. SetToolbar();
  258. break;
  259. case idmToggleStatusbar:
  260. m_fStatusbar = !m_fStatusbar;
  261. SetStatusbar();
  262. break;
  263. case idmPopupFile:
  264. break;
  265. case idmTile:
  266. SendMessage(m_hwndClient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
  267. break;
  268. case idmCascade:
  269. SendMessage(m_hwndClient, WM_MDICASCADE, 0, 0);
  270. break;
  271. case idmNew:
  272. pHost = new CMeHost();
  273. if (pHost)
  274. {
  275. hr = pHost->HrInit(m_hwndClient, (IOleInPlaceFrame *)this);
  276. pHost->Release();
  277. }
  278. if (FAILED(hr))
  279. MessageBox(hwnd, "Failed", "Mepad", MB_OK);
  280. break;
  281. case idmClose:
  282. PostMessage(m_hwnd, WM_CLOSE, 0, 0);
  283. return 0;
  284. case idmPageSetup:
  285. case idmPopupGo :
  286. case idmPopupHelp:
  287. MessageBox(hwnd, "Not Implemented yet", "Mepad", MB_OK);
  288. hr = NOERROR;
  289. break;
  290. case idmAbout:
  291. MessageBox(hwnd, "MimeEdit Pad\nA test container for MimeEdit.\n(c) brettm", "Mepad", MB_OK);
  292. break;
  293. }
  294. // delegate the the active MDI child window
  295. hwndChild = (HWND)SendMessage(m_hwndClient, WM_MDIGETACTIVE, 0, 0);
  296. if (hwndChild)
  297. {
  298. pHost = (CMeHost *)GetWindowLong(hwndChild, GWL_USERDATA);
  299. if (pHost)
  300. pHost->OnCommand(hwnd, id, wCmd);
  301. }
  302. return hr;
  303. }
  304. void CMDIFrame::WMSize()
  305. {
  306. RECT rcToolbar,
  307. rc,
  308. rcStatus;
  309. int cy;
  310. SetWindowPos(m_hToolbar, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER);
  311. SetWindowPos(m_hStatusbar, NULL, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOZORDER);
  312. GetClientRect(m_hToolbar, &rcToolbar);
  313. GetClientRect(m_hToolbar, &rcStatus);
  314. GetClientRect(m_hwnd, &rc);
  315. cy = rc.bottom - rcToolbar.bottom - rcStatus.bottom + 3;
  316. SetWindowPos(m_hwndClient, NULL, 0, rcToolbar.bottom, rc.right-rc.left, cy, SWP_NOACTIVATE|SWP_NOZORDER);
  317. }
  318. void CMDIFrame::SetToolbar()
  319. {
  320. ShowWindow(m_hToolbar, m_fToolbar?SW_SHOW:SW_HIDE);
  321. WMSize();
  322. InvalidateRect(m_hwnd, NULL, TRUE);
  323. }
  324. void CMDIFrame::SetStatusbar()
  325. {
  326. ShowWindow(m_hStatusbar, m_fStatusbar?SW_SHOW:SW_HIDE);
  327. WMSize();
  328. InvalidateRect(m_hwnd, NULL, TRUE);
  329. }
  330. LRESULT CMDIFrame::WMInitMenuPopup(HWND hwnd, HMENU hmenuPopup, UINT uPos)
  331. {
  332. MENUITEMINFO mii;
  333. HMENU hmenuMain;
  334. UINT ustate;
  335. HWND hwndChild;
  336. CMeHost *pHost;
  337. hmenuMain = GetMenu(hwnd);
  338. mii.cbSize = sizeof(MENUITEMINFO);
  339. mii.fMask = MIIM_ID | MIIM_SUBMENU;
  340. GetMenuItemInfo(hmenuMain, uPos, TRUE, &mii);
  341. // grey all the commands handled by the children, then can reenable them
  342. EnableMenuItem(hmenuPopup, idmOpen, MF_BYCOMMAND|MF_GRAYED);
  343. EnableMenuItem(hmenuPopup, idmEditDocument, MF_BYCOMMAND|MF_GRAYED);
  344. EnableMenuItem(hmenuPopup, idmCut, MF_BYCOMMAND|MF_GRAYED);
  345. EnableMenuItem(hmenuPopup, idmCopy, MF_BYCOMMAND|MF_GRAYED);
  346. EnableMenuItem(hmenuPopup, idmPaste, MF_BYCOMMAND|MF_GRAYED);
  347. EnableMenuItem(hmenuPopup, idmUndo, MF_BYCOMMAND|MF_GRAYED);
  348. EnableMenuItem(hmenuPopup, idmRedo, MF_BYCOMMAND|MF_GRAYED);
  349. EnableMenuItem(hmenuPopup, idmSelectAll, MF_BYCOMMAND|MF_GRAYED);
  350. EnableMenuItem(hmenuPopup, idmPrint, MF_BYCOMMAND|MF_GRAYED);
  351. EnableMenuItem(hmenuPopup, idmSaveAs, MF_BYCOMMAND|MF_GRAYED);
  352. EnableMenuItem(hmenuPopup, idmFind, MF_BYCOMMAND|MF_GRAYED);
  353. EnableMenuItem(hmenuPopup, idmRot13, MF_BYCOMMAND|MF_GRAYED);
  354. EnableMenuItem(hmenuPopup, idmNoHeader, MF_BYCOMMAND|MF_GRAYED);
  355. EnableMenuItem(hmenuPopup, idmPreview, MF_BYCOMMAND|MF_GRAYED);
  356. EnableMenuItem(hmenuPopup, idmMiniHeader, MF_BYCOMMAND|MF_GRAYED);
  357. EnableMenuItem(hmenuPopup, idmFormatBar, MF_BYCOMMAND|MF_GRAYED);
  358. EnableMenuItem(hmenuPopup, idmFmtPreview, MF_BYCOMMAND|MF_GRAYED);
  359. switch (mii.wID)
  360. {
  361. case idmPopupView:
  362. ustate = (m_fToolbar?MF_CHECKED:MF_UNCHECKED) | MF_BYCOMMAND;
  363. CheckMenuItem(hmenuPopup, idmToggleToolbar, ustate);
  364. ustate = (m_fStatusbar?MF_CHECKED:MF_UNCHECKED) | MF_BYCOMMAND;
  365. CheckMenuItem(hmenuPopup, idmToggleStatusbar, ustate);
  366. break;
  367. }
  368. // delegate to the active MDI child window
  369. hwndChild = (HWND)SendMessage(m_hwndClient, WM_MDIGETACTIVE, 0, 0);
  370. if (hwndChild)
  371. {
  372. pHost = (CMeHost *)GetWindowLong(hwndChild, GWL_USERDATA);
  373. if (pHost)
  374. pHost->OnInitMenuPopup(hwnd, hmenuPopup, uPos);
  375. }
  376. return 0;
  377. }
  378. static HACCEL hAccel=0;
  379. HRESULT CMDIFrame::TranslateAcclerator(LPMSG lpmsg)
  380. {
  381. HWND hwndChild;
  382. if (!hAccel)
  383. hAccel = LoadAccelerators(g_hInst, MAKEINTRESOURCE(idacMeHost));
  384. if(::TranslateAccelerator(m_hwnd, hAccel, lpmsg))
  385. return S_OK;
  386. hwndChild = (HWND)SendMessage(m_hwndClient, WM_MDIGETACTIVE, 0, 0);
  387. if(hwndChild &&
  388. ::TranslateAccelerator(hwndChild, hAccel, lpmsg))
  389. return S_OK;
  390. if (TranslateMDISysAccel(m_hwndClient, lpmsg))
  391. return S_OK;
  392. if (m_pInPlaceActiveObj)
  393. return m_pInPlaceActiveObj->TranslateAccelerator(lpmsg);
  394. return S_FALSE;
  395. }
  396. // *** IOleInPlaceFrame methods ***
  397. HRESULT CMDIFrame::InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
  398. {
  399. return NOERROR;
  400. }
  401. HRESULT CMDIFrame::SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
  402. {
  403. return NOERROR;
  404. }
  405. HRESULT CMDIFrame::RemoveMenus(HMENU hmenuShared)
  406. {
  407. return NOERROR;
  408. }
  409. HRESULT CMDIFrame::SetStatusText(LPCOLESTR pszStatusText)
  410. {
  411. if (pszStatusText)
  412. {
  413. TCHAR rgch[MAX_PATH];
  414. WideCharToMultiByte(CP_ACP, 0, pszStatusText, -1, rgch, MAX_PATH, NULL, NULL);
  415. SendMessage(m_hStatusbar, SB_SIMPLE, (WPARAM)TRUE, 0);
  416. SendMessage(m_hStatusbar, SB_SETTEXT, SBT_NOBORDERS|255, (LPARAM) rgch);
  417. }
  418. else
  419. {
  420. SendMessage(m_hStatusbar, SB_SIMPLE, (WPARAM)FALSE, 0);
  421. }
  422. return S_OK;
  423. }
  424. HRESULT CMDIFrame::EnableModeless(BOOL fEnable)
  425. {
  426. return E_NOTIMPL;
  427. }
  428. HRESULT CMDIFrame::TranslateAccelerator(LPMSG lpMsg, WORD wID)
  429. {
  430. return E_NOTIMPL;
  431. }
  432. HRESULT CMDIFrame::GetWindow(HWND *phwnd)
  433. {
  434. *phwnd = m_hwnd;
  435. return S_OK;
  436. }
  437. HRESULT CMDIFrame::ContextSensitiveHelp(BOOL)
  438. {
  439. return E_NOTIMPL;
  440. }
  441. // *** IOleInPlaceUIWindow methods ***
  442. HRESULT CMDIFrame::GetBorder(LPRECT)
  443. {
  444. return E_NOTIMPL;
  445. }
  446. HRESULT CMDIFrame::RequestBorderSpace(LPCBORDERWIDTHS)
  447. {
  448. return E_NOTIMPL;
  449. }
  450. HRESULT CMDIFrame::SetBorderSpace(LPCBORDERWIDTHS)
  451. {
  452. return E_NOTIMPL;
  453. }
  454. HRESULT CMDIFrame::SetActiveObject(IOleInPlaceActiveObject *pInPlaceActiveObj, LPCOLESTR)
  455. {
  456. ReplaceInterface(m_pInPlaceActiveObj, pInPlaceActiveObj);
  457. return S_OK;
  458. }
  459. void CMDIFrame::DoOptions()
  460. {
  461. DialogBoxParam(g_hInst, MAKEINTRESOURCE(iddOptions), m_hwnd, ExtOptDlgProc, (LPARAM)this);
  462. }
  463. INT_PTR CALLBACK CMDIFrame::ExtOptDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  464. {
  465. CMDIFrame *pFrame=(CMDIFrame *)GetWindowLong(hwnd, DWL_USER);
  466. if (msg==WM_INITDIALOG)
  467. {
  468. pFrame = (CMDIFrame *)lParam;
  469. SetWindowLong(hwnd, DWL_USER, lParam);
  470. }
  471. return pFrame?pFrame->OptDlgProc(hwnd, msg, wParam, lParam):FALSE;
  472. }
  473. BOOL g_fHTML =TRUE,
  474. g_fIncludeMsg =TRUE,
  475. g_fQuote =FALSE,
  476. g_fSlideShow =FALSE,
  477. g_fAutoInline =TRUE,
  478. g_fSendImages =TRUE,
  479. g_fComposeFont =TRUE,
  480. g_fBlockQuote =TRUE,
  481. g_fAutoSig =FALSE,
  482. g_fSigHtml =FALSE;
  483. CHAR g_chQuote ='>';
  484. CHAR g_szComposeFont[MAX_PATH] = "0,1,0,2,0.0.128,,Verdana";
  485. LONG g_lHeaderType = 0;
  486. CHAR g_szSig[MAX_PATH] = "<your signature goes here>";
  487. INT_PTR CALLBACK CMDIFrame::OptDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  488. {
  489. char sz[5];
  490. int i;
  491. switch (msg)
  492. {
  493. case WM_COMMAND:
  494. switch (LOWORD(wParam))
  495. {
  496. case IDOK:
  497. g_fHTML = IsDlgButtonChecked(hwnd, idcHTML);
  498. g_fIncludeMsg = IsDlgButtonChecked(hwnd, idcInclude);
  499. g_fQuote = IsDlgButtonChecked(hwnd, idcQuote);
  500. g_fSlideShow = IsDlgButtonChecked(hwnd, idcSlide);
  501. g_fAutoInline = IsDlgButtonChecked(hwnd, idcAuto);
  502. g_fSendImages = IsDlgButtonChecked(hwnd, idcSendImages);
  503. g_fComposeFont = IsDlgButtonChecked(hwnd, idcComposeFont);
  504. g_fAutoSig = IsDlgButtonChecked(hwnd, idcSig);
  505. g_fSigHtml = IsDlgButtonChecked(hwnd, idcSigHtml);
  506. GetWindowText(GetDlgItem(hwnd, ideComposeFont), g_szComposeFont, MAX_PATH);
  507. GetWindowText(GetDlgItem(hwnd, ideSig), g_szSig, MAX_PATH);
  508. GetWindowText(GetDlgItem(hwnd, ideQuote), sz, 1);
  509. g_chQuote = sz[0];
  510. g_fBlockQuote = IsDlgButtonChecked(hwnd, idcBlockQuote);
  511. for (i=0; i<4; i++)
  512. if (IsDlgButtonChecked(hwnd, idrbNone+i))
  513. g_lHeaderType = i;
  514. // fall tro'
  515. case IDCANCEL:
  516. EndDialog(hwnd, LOWORD(wParam));
  517. return TRUE;
  518. }
  519. break;
  520. case WM_INITDIALOG:
  521. CheckDlgButton(hwnd, idcHTML, g_fHTML ? BST_CHECKED:BST_UNCHECKED);
  522. CheckDlgButton(hwnd, idcInclude, g_fIncludeMsg ? BST_CHECKED:BST_UNCHECKED);
  523. CheckDlgButton(hwnd, idcQuote, g_fQuote ? BST_CHECKED:BST_UNCHECKED);
  524. CheckDlgButton(hwnd, idcSlide, g_fSlideShow ? BST_CHECKED:BST_UNCHECKED);
  525. CheckDlgButton(hwnd, idcAuto, g_fAutoInline ? BST_CHECKED:BST_UNCHECKED);
  526. CheckDlgButton(hwnd, idcSendImages, g_fSendImages ? BST_CHECKED:BST_UNCHECKED);
  527. CheckDlgButton(hwnd, idcComposeFont, g_fComposeFont ? BST_CHECKED:BST_UNCHECKED);
  528. CheckDlgButton(hwnd, idcSig, g_fAutoSig ? BST_CHECKED:BST_UNCHECKED);
  529. CheckDlgButton(hwnd, idcSigHtml, g_fSigHtml ? BST_CHECKED:BST_UNCHECKED);
  530. sz[0] = g_chQuote;
  531. sz[1] = 0;
  532. SetWindowText(GetDlgItem(hwnd, ideQuote), sz);
  533. SetWindowText(GetDlgItem(hwnd, ideComposeFont), g_szComposeFont);
  534. SetWindowText(GetDlgItem(hwnd, ideSig), g_szSig);
  535. CheckRadioButton(hwnd, idrbNone, idrbPrint, idrbNone+g_lHeaderType);
  536. CheckDlgButton(hwnd, idcBlockQuote, g_fBlockQuote ? BST_CHECKED:BST_UNCHECKED);
  537. break;
  538. }
  539. return FALSE;
  540. }
  541. void SaveFocus(BOOL fActive, HWND *phwnd)
  542. {
  543. if(fActive&&IsWindow(*phwnd))
  544. SetFocus(*phwnd);
  545. else
  546. *phwnd=GetFocus();
  547. }
  548. HRESULT CMDIFrame::OpenDoc(LPSTR pszFileName)
  549. {
  550. CMeHost *pHost;
  551. HRESULT hr;
  552. if (pszFileName && *pszFileName)
  553. {
  554. pHost = new CMeHost();
  555. if (pHost)
  556. {
  557. hr = pHost->HrInit(m_hwndClient, (IOleInPlaceFrame *)this);
  558. if (!FAILED(hr))
  559. hr = pHost->HrLoadFile(pszFileName);
  560. pHost->Release();
  561. }
  562. if (FAILED(hr))
  563. MessageBox(m_hwnd, "Failed to open file", "Mepad", MB_OK);
  564. }
  565. return S_OK;
  566. }