home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / mswindo / programm / misc / 4483 < prev    next >
Encoding:
Text File  |  1992-12-27  |  7.7 KB  |  277 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!convex!darwin.sura.net!spool.mu.edu!sdd.hp.com!ux1.cso.uiuc.edu!news.iastate.edu!martin
  3. From: martin@iastate.edu (Martin R Calsyn)
  4. Subject: Re: Borland C++ OWL; want hybrid of MDI child and Dialog box
  5. Message-ID: <BzxnJo.GE0@news.iastate.edu>
  6. Sender: news@news.iastate.edu (USENET News System)
  7. Organization: Iowa State University, Ames, IA
  8. References: <1992Dec26.213715.6956@cuug.ab.ca>
  9. Distribution: comp.os.ms-windows.programmer.misc
  10. Date: Sun, 27 Dec 1992 19:30:59 GMT
  11. Lines: 264
  12.  
  13. In article <1992Dec26.213715.6956@cuug.ab.ca> terbergd@cuug.ab.ca (Denis Terberg 283-8245) writes:
  14. >I want to create an MDI child window with some (but not all)
  15. >of the properties of a Dialog Box.
  16. > [...]
  17.  
  18. I think the following should fit the bill.  I've mentioned this here
  19. before and mailed it out extensively.
  20.  
  21. What follows are three files:
  22.     TMDIDLOG.H        The interface for modeless MDI-child dialogs.
  23.     TMDIDLOG.CPP        The implementation of same
  24.     EXAMPLE.CPP        An (partial) example of using the
  25.                 TMDIDLOG classes.
  26.  
  27. You need to sub-class TMDIDialogWindow in order to give your MDI child a
  28. unique icon, etc (not shown in the example) and to implement the
  29. CreateChildDialog abstract method.  And, of course, you need to
  30. sub-class TMDIDialog in order to establish a transfer structure,
  31. interface objects and all the things you usually do with sub-classes of
  32. TDialog.
  33.  
  34. The classes included below work by presenting the dialog as a child of a
  35. TBWindow which is itself a child of the MDI.  These classes are based on
  36. tips and suggestions offered by the Borland advisor line.
  37.  
  38. The transfer of this technique to MS MFC is trivial.
  39.  
  40. ----------------------------- TMDIDLOG.H ---------------------------------
  41.  
  42. // -*- C -*-
  43. #ifndef __tmdidlog_h__
  44. #define __tmdidlog_h__
  45. //
  46. //  Copyright 1992 Software Innovations, Incorporated
  47. //
  48. //  $Source: C:\MDIDLOG\tmdidlog.h-v $
  49. //  $Author: martin $
  50. //  $Date: 92/12/27 13:05:35 $
  51. //  $Revision: 1.1 $
  52. //
  53.  
  54. #include <owl.h>
  55. #include <bwindow.h>
  56.  
  57. _CLASSDEF(TMDIDialog)
  58. _CLASSDEF(TMDIDialogWindow)
  59.  
  60. class TMDIDialog : public TDialog
  61. {
  62. public:
  63.     TMDIDialog(PTWindowsObject AParent,LPSTR AName,PTModule AModule=NULL) :
  64.     TDialog(AParent, AName, AModule) {};
  65.     TMDIDialog(PTWindowsObject AParent,int ResourceId,PTModule AModule=NULL):
  66.     TDialog( AParent, ResourceId, AModule ) {};
  67.     virtual void WMSetFocus( RTMessage Msg ) = [WM_FIRST + WM_SETFOCUS];
  68.     virtual void CloseWindow( int ret );
  69.     virtual void CloseWindow();
  70.     virtual void Cancel( RTMessage msg ) = [ID_FIRST + IDCANCEL];
  71.  
  72.     friend class TMDIDialogWindow;
  73.  
  74. protected:
  75.     TMDIDialogWindow    *mdiw;
  76. };
  77.  
  78. class TMDIDialogWindow : public TBWindow
  79. {
  80. public:
  81.     TMDIDialogWindow(PTWindowsObject aParent,LPSTR aName,
  82.                      PTModule aModule = NULL);
  83.     virtual void WMMDIActivate( RTMessage Msg ) = [WM_FIRST + WM_MDIACTIVATE];
  84.     virtual void WMSetFocus( RTMessage Msg ) = [WM_FIRST + WM_SETFOCUS];
  85.     virtual void WMSize( RTMessage Msg ) = [WM_FIRST + WM_SIZE];
  86.     virtual void SetupWindow();
  87.     virtual LPSTR GetClassName() { return "_TMDIDialogWindow"; };
  88.     virtual void GetWindowClass( WNDCLASS& aWndClass );
  89.     virtual void WMGetMinMaxInfo( RTMessage msg ) = [WM_FIRST + WM_GETMINMAXINFO];
  90.     virtual TMDIDialog *CreateChildDialog() = 0;
  91.  
  92. private:
  93.     PTMDIDialog dlog;
  94. };
  95.  
  96. #endif
  97.  
  98. ------------------------------ TMDIDLOG.CPP -------------------------------
  99.  
  100. // -*- C -*-
  101. //
  102. //  Copyright 1992 Software Innovations, Incorporated
  103. //
  104. //  $Source: C:\MDIDLOG\tmdidlog.c-v $
  105. //  $Author: martin $
  106. //  $Date: 92/12/27 13:05:09 $
  107. //  $Revision: 1.1 $
  108. //
  109.  
  110. #include "tmdidlog.h"
  111.  
  112. TMDIDialogWindow::TMDIDialogWindow(PTWindowsObject aParent,
  113.              LPSTR aName,
  114.              PTModule aModule) :
  115.          TBWindow(aParent,aName,aModule)
  116. {
  117.     dlog = NULL;
  118.     GetApplication()->SetKBHandler( this );
  119.     SetFlags( WB_KBHANDLER, FALSE );
  120. }
  121.  
  122. void TMDIDialogWindow::WMMDIActivate( RTMessage Msg )
  123. {
  124.     TWindow::WMMDIActivate( Msg );
  125.  
  126.     if ( Msg.WParam == TRUE ) {
  127.         GetApplication()->SetKBHandler(this);
  128.         if (dlog!=NULL)
  129.             SetFocus(((PTDialog)dlog)->HWindow );
  130.     }
  131. }
  132.  
  133. void TMDIDialogWindow::GetWindowClass( WNDCLASS& aWndClass )
  134. {
  135.     TWindow::GetWindowClass(aWndClass);
  136. }
  137.  
  138. void TMDIDialogWindow::WMSetFocus(RTMessage Msg)
  139. {
  140.     PostMessage(HWindow, WM_MDIACTIVATE, TRUE, 0L );
  141.     DefWndProc(Msg);
  142. }
  143.  
  144. void TMDIDialogWindow::SetupWindow()
  145. {
  146.     TWindow::SetupWindow();
  147.  
  148.     dlog = CreateChildDialog();
  149.     if (dlog) {
  150.         dlog->mdiw = this;
  151.         RECT r;
  152.         GetApplication()->MakeWindow(dlog);
  153.         SetFocus(dlog->HWindow);
  154.         GetWindowRect(HWindow,&r);
  155.         Attr.X = r.left;
  156.         Attr.Y = r.top;
  157.         GetWindowRect(dlog->HWindow,&r);
  158.         AdjustWindowRect(&r,WS_CAPTION|WS_BORDER,0);
  159.         Attr.W = r.right - r.left;
  160.         Attr.H = r.bottom - r.top;
  161.         MoveWindow(HWindow,Attr.X, Attr.Y, Attr.W, Attr.H, 1);
  162.     }
  163. }
  164.  
  165. void TMDIDialogWindow::WMGetMinMaxInfo( RTMessage msg )
  166. {
  167.     if (dlog) {
  168.         MINMAXINFO *lpmmi = (MINMAXINFO *)msg.LParam;
  169.         RECT r;
  170.         POINT pt1,pt2;
  171.         GetWindowRect(HWindow,&r);
  172.         pt1.x = r.left;
  173.         pt1.y = r.top;
  174.         GetWindowRect(dlog->HWindow,&r);
  175.         AdjustWindowRect(&r,WS_CAPTION|WS_BORDER,0);
  176.         pt2.x = r.right - r.left;
  177.         pt2.y = r.bottom - r.top;
  178.         lpmmi->ptMaxSize = pt2;
  179.         lpmmi->ptMaxPosition = pt1;
  180.         lpmmi->ptMinTrackSize = pt2;
  181.         lpmmi->ptMaxTrackSize = pt2;
  182.     }
  183. }
  184.  
  185. void TMDIDialogWindow::WMSize( RTMessage Msg )
  186. {
  187.     RECT r;
  188.     TWindow::WMSize( Msg );
  189.     if (!IsIconic(HWindow)) {
  190.         GetWindowRect(dlog->HWindow,&r);
  191.         AdjustWindowRect(&r,WS_CAPTION|WS_BORDER,0);
  192.         Attr.W = r.right - r.left;
  193.         Attr.H = r.bottom - r.top;
  194.         MoveWindow(HWindow, Attr.X, Attr.Y, Attr.W, Attr.H, 1);
  195.     }
  196. }
  197.  
  198. //
  199. //  TMDIDialog methods...
  200. //
  201.  
  202. void TMDIDialog::WMSetFocus( RTMessage Msg )
  203. {
  204.     GetApplication()->SetKBHandler( this );
  205.     DefWndProc( Msg );
  206. }
  207.  
  208. void TMDIDialog::CloseWindow(int ret)
  209. {
  210.     TDialog::CloseWindow(ret);
  211.     mdiw->CloseWindow();
  212. }
  213.  
  214. void TMDIDialog::CloseWindow()
  215. {
  216.     TDialog::CloseWindow();
  217.     mdiw->CloseWindow();
  218. }
  219.  
  220. void TMDIDialog::Cancel(RTMessage msg)
  221. {
  222.     CloseWindow(IDCANCEL);
  223. }
  224.  
  225. ------------------------------- EXAMPLE.CPP -------------------------------
  226.  
  227. //
  228. //  #include owl, tmdidlog.h and others as needed
  229. //
  230.  
  231. //
  232. //  ChildDialog is a dialog box defined in the RC file under
  233. //    the name 'MY_DLOG'.  The definition of MY_DLOG is pretty plain
  234. //    except that it should have the following attributes:
  235. //              STYLE WS_CHILD | WS_VISIBLE
  236. //    and optionally CLASS "BORDLG"
  237. //  That is, it should have no caption, sys menu, or border of any type.
  238. //   It should also have an origin of 0,0 otherwise it will be offset
  239. //   within the MDI child window.
  240. //
  241. //  An instance of ClientDialog can be created as a modeless MDI client
  242. //   by doing : `new ChildDialogWindow(this, "Title", NULL)' from your
  243. //   MDI frame object or other appropriate place.
  244. //
  245.  
  246. class ChildDialog : public TMDIDialog
  247. {
  248. public:
  249.     ChildDialog(PTWindowsObject aParent,
  250.                  LPSTR aName, PTModule aModule = NULL);
  251.  
  252. };
  253.  
  254. ChildDialogWindow::ChildDialogWindow(PTWindowsObject aParent,LPSTR aName,
  255.                                        PTModule aModule)
  256.         : TMDIDialogWindow(aParent,aName,aModule)
  257. {
  258.     obj_id = object_id;
  259. }
  260.  
  261. TMDIDialog* ChildDialogWindow::CreateChildDialog()
  262. {
  263.     return (TMDIDialog*)new ChildDialog(this,(LPSTR)"MY_DLOG",NULL);
  264. }
  265.  
  266. ChildDialog::ChildDialog(PTWindowsObject aParent,
  267.                            LPSTR aName, PTModule aModule)
  268.         : TMDIDialog(aParent,aName,aModule)
  269. {
  270.     // The usual stuff:  Initialize the transfer structure, create
  271.     //  interface objects, etc.
  272.  
  273. }
  274.  
  275. --------------------------------- The End ------------------------------
  276.  
  277.