home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / mobjm260 / multidlg.cp_ / multidlg.cp
Encoding:
Text File  |  1994-09-06  |  6.2 KB  |  280 lines

  1. //    Microworks ObjectMate  2.6
  2. //
  3. //    MultiDlg - Multiple Dialog Demonstration
  4. //
  5. //    Copyright 1992-94 Microworks Sydney, Australia.
  6. //
  7. //  MULTIDLG.CPP
  8.  
  9. /* MultiDlg creates a notebook style multiple dialog using child dialogs and
  10.  * a radio button style SFX toolbar. It's an easy and more stylish alternative
  11.  * to tabbed multiple dialogs. In the resource file multidlg.res there are two
  12.  * dialog templates: MULTIDLG and MULTIDLGC. MULTDLG is the Pascal template and
  13.  * MULTIDLGC is the C++ 4.0 template. This demonstration sets up the multiple
  14.  * dialog as a dialog window.
  15.  */
  16.  
  17. #define ID_DLG1       1
  18. #define ID_DLG2       2
  19. #define ID_DLG3       3
  20. #define ID_DLG4       4
  21. #define ID_DLG5       5
  22. #define ID_SHADE      101
  23. #define ID_TOOLBAR    102
  24. #define ID_BUT1       301
  25. #define ID_BUT2       302
  26. #define ID_BUT3       303
  27. #define ID_BUT4       304
  28. #define ID_BUT5       305
  29. #define ID_ABOUT      306
  30. #define APPNAME       "MULTIDLG"
  31.  
  32. #include <owl\owlpch.h>
  33. #include <sfx\sfx200.h>
  34. #include <sfx\sframe.h>
  35. #include <sfx\stoolbar.h>
  36. #include <sfx\sshade.h>
  37. #include <sfx\smenu.h>
  38.  
  39. //    TChildDlg  class
  40.  
  41. class TChildDlg : public TDialog
  42. {
  43.   public:
  44.     TChildDlg(TWindow*, TResId);
  45.     void CmOk();
  46.     void CmCancel();
  47.   DECLARE_RESPONSE_TABLE(TChildDlg);
  48. };
  49.  
  50. DEFINE_RESPONSE_TABLE1(TChildDlg, TDialog)
  51.   EV_CHILD_NOTIFY(IDOK, BN_CLICKED, CmOk),
  52.   EV_CHILD_NOTIFY(IDCANCEL, BN_CLICKED, CmCancel),
  53. END_RESPONSE_TABLE;
  54.  
  55. TChildDlg::TChildDlg(TWindow* parent, TResId resId)
  56.     :TDialog(parent, resId),
  57.      TWindow(parent)
  58. {
  59. }
  60.  
  61. void
  62. TChildDlg::CmOk()
  63. {
  64.     ForwardMessage(Parent->HWindow);              
  65. }
  66.  
  67. void
  68. TChildDlg::CmCancel()
  69. {
  70.     ForwardMessage(Parent->HWindow);              
  71. }
  72.  
  73. //    TMultiDlg class
  74.  
  75. class TMultiDlg : public TDialog {
  76.   public:
  77.     TChildDlg*        NextDlg;
  78.     TChildDlg*        PrevDlg;
  79.     TSFXShade*        Shade;
  80.     TSFXToolbar*      Toolbar;
  81.     TMultiDlg();
  82.     virtual char far* GetClassName();
  83.     void              SetupWindow();
  84.     void              CreateChildDialog(int dialogId, const char* title);
  85.     void              CmOk();
  86.     void              CmCancel();
  87.     void              IdBut1();
  88.     void              IdBut2();
  89.     void              IdBut3();
  90.     void              IdBut4();
  91.     void              IdBut5();
  92.   DECLARE_RESPONSE_TABLE(TMultiDlg);
  93. };
  94.  
  95. DEFINE_RESPONSE_TABLE1(TMultiDlg, TDialog)
  96.   EV_COMMAND(ID_BUT1, IdBut1),
  97.   EV_COMMAND(ID_BUT2, IdBut2),
  98.   EV_COMMAND(ID_BUT3, IdBut3),
  99.   EV_COMMAND(ID_BUT4, IdBut4),
  100.   EV_COMMAND(ID_BUT5, IdBut5),
  101.   EV_CHILD_NOTIFY(IDOK, BN_CLICKED, CmOk),
  102.   EV_CHILD_NOTIFY(IDCANCEL, BN_CLICKED, CmCancel),
  103. END_RESPONSE_TABLE;
  104.  
  105. TMultiDlg::TMultiDlg()
  106.   : TWindow((TWindow*)0),
  107.     TDialog(0, "MULTIDLGC")
  108. {
  109.     Shade = new TSFXShade(this, ID_SHADE);
  110.     Toolbar = new TSFXToolbar(this, ID_TOOLBAR);
  111.     NextDlg = 0;
  112.     PrevDlg = 0;
  113. }
  114.  
  115. char far*
  116. TMultiDlg::GetClassName()
  117. {
  118.     return "SFXDLG";
  119. }
  120.  
  121. void
  122. TMultiDlg::SetupWindow()
  123. {
  124.     TDialog::SetupWindow();
  125.     IdBut1();
  126.     Toolbar->CheckTool(ID_BUT1);
  127.     if (GetSystemMetrics(SM_CYSIZE) == 26)
  128.     {
  129.         TRect rect;
  130.         GetWindowRect(rect);
  131.         rect.right -= 22;
  132.         SetWindowPos(0, rect, SWP_NOZORDER | SWP_NOMOVE);
  133.         ::ShowWindow(GetDlgItem(IDCANCEL), SW_SHOW);
  134.     }
  135. }
  136.  
  137. void
  138. TMultiDlg::CreateChildDialog(int dialogId, const char* title)
  139. {
  140.     PrevDlg = NextDlg;
  141.     NextDlg = new TChildDlg(this, MAKEINTRESOURCE(dialogId));
  142.     NextDlg->Create();
  143.     NextDlg->SetWindowPos(HWND_TOP, 33, 50, 0, 0, SWP_NOSIZE);
  144.     Shade->SetWindowText(title);
  145.     NextDlg->Show(SW_NORMAL);
  146.     if (PrevDlg != 0 && PrevDlg->HWindow != 0)
  147.         DestroyWindow(PrevDlg->HWindow);
  148. }
  149.  
  150. void
  151. TMultiDlg::CmOk()
  152. {
  153.     Parent->CloseWindow();        
  154. }
  155.  
  156. void
  157. TMultiDlg::CmCancel()
  158. {
  159.     Parent->CloseWindow();        
  160. }
  161.  
  162. void
  163. TMultiDlg::IdBut1()
  164. {
  165.     CreateChildDialog(ID_DLG1, " Edit Controls...");
  166. }
  167.  
  168. void
  169. TMultiDlg::IdBut2()
  170. {
  171.     CreateChildDialog(ID_DLG2, " List Boxes...");
  172. }
  173.  
  174. void
  175. TMultiDlg::IdBut3()
  176. {
  177.     CreateChildDialog(ID_DLG3, " Combo Boxes...");
  178. }
  179.  
  180. void
  181. TMultiDlg::IdBut4()
  182. {
  183.     CreateChildDialog(ID_DLG4, " Check Boxes...");
  184. }
  185.  
  186. void
  187. TMultiDlg::IdBut5()
  188. {
  189.     CreateChildDialog(ID_DLG5, " Radio Buttons...");
  190. }
  191.  
  192. //    TDialogFrame class
  193.  
  194. class TDialogFrame : public TSFXFrameWindow {
  195.   public:
  196.     TDialogFrame(TWindow*, const char*, TWindow*);
  197.     virtual char far* GetClassName();
  198.     void              SetupWindow();
  199.     void              EvDrawItem(UINT, DRAWITEMSTRUCT far&);
  200.     void              EvMeasureItem(UINT, MEASUREITEMSTRUCT far&);
  201.     LRESULT           EvMenuChar(WPARAM, LPARAM);
  202.   DECLARE_RESPONSE_TABLE(TDialogFrame);
  203. };
  204.  
  205. DEFINE_RESPONSE_TABLE2(TDialogFrame, TSFXFrameWindow, TFrameWindow)
  206.   EV_WM_DRAWITEM,
  207.   EV_WM_MEASUREITEM,
  208.   EV_MESSAGE(WM_MENUCHAR, EvMenuChar),
  209. END_RESPONSE_TABLE;
  210.  
  211. TDialogFrame::TDialogFrame(TWindow* parent, const char* title, TWindow* dialog)
  212.    :TSFXFrameWindow(parent, title, dialog, TRUE),
  213.     TFrameWindow(parent, title, dialog, TRUE),
  214.     TWindow(parent, title)
  215. {
  216.     Attr.Style |= MWS_SFXFRAME | MWS_SFXCAPTION;
  217. }
  218.  
  219. char far*
  220. TDialogFrame::GetClassName()
  221. {
  222.     return APPNAME;
  223. }
  224.  
  225. void
  226. TDialogFrame::SetupWindow()
  227. {
  228.     TFrameWindow::SetupWindow();
  229.     Set3DSystemMenu(HWindow, "MultiDlg");
  230.     CenterWindow(0, HWindow);
  231. }
  232.  
  233. void
  234. TDialogFrame::EvDrawItem(UINT /*ctlId*/, DRAWITEMSTRUCT far& drawinfo)
  235. {
  236.     if (drawinfo.CtlType == ODT_MENU)
  237.         DrawMenuItem(drawinfo);
  238. }
  239.  
  240. void
  241. TDialogFrame::EvMeasureItem(UINT /*ctlId*/, MEASUREITEMSTRUCT far& measureinfo)
  242. {
  243.     if (measureinfo.CtlType == ODT_MENU)
  244.         MeasureMenuItem(HWindow, measureinfo);
  245. }
  246.  
  247. LRESULT
  248. TDialogFrame::EvMenuChar(WPARAM wParam, LPARAM lParam)
  249. {
  250.     if (LOWORD(lParam) & MF_SYSMENU)
  251.         return ProcessSystemChar(wParam);
  252.     else
  253.         return 0L;
  254. }
  255.  
  256. //    TDialogApp
  257.  
  258. class TDialogApp : public TApplication {
  259.   public:
  260.     TDialogApp(const char far* name) : TApplication(name) {}
  261.     void  InitMainWindow();
  262. };
  263.  
  264. void
  265. TDialogApp::InitMainWindow()
  266. {
  267.     TWindow* client = new TMultiDlg();
  268.     MainWindow = new TDialogFrame(0, "MultiDlg - Multiple Dialog Demonstration", client);
  269.     MainWindow->SetIcon(this, APPNAME);
  270.     MainWindow->Attr.Style &= ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX);
  271. }
  272.  
  273. //    OwlMain
  274.  
  275. int
  276. OwlMain(int /*argc*/, char* /*argv*/ [])
  277. {
  278.     return TDialogApp("MultiDlg - Multiple Dilaog Demonstration").Run();
  279. }
  280.