home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sibdemo3.zip / SAMPLES.DAT / SAMPLES / TUTORIAL / CHAP03 / WELCOME4.PAS < prev    next >
Pascal/Delphi Source File  |  1997-08-01  |  7KB  |  160 lines

  1. PROGRAM WELCOME4;
  2.  
  3. /*-------------------------------------------------------------
  4.    WELCOME4.PAS -- Creates a Top-Level Window and Three Children
  5.                  (c) Charles Petzold, 1993
  6.   -------------------------------------------------------------*/
  7.  
  8. /*-------------------------------------------------------
  9.    from the book "OS/2 Presentation Manager Programming"
  10.    by Charles Petzold, Ziff-Davis Press 1994
  11.  
  12.    (c) Ziff Davis Press, All rights reserved.
  13.    Restricted rights, duplication, disclosure and
  14.    commericially distribution prohibited.
  15.  
  16.    Translated to Speed-Pascal/2 by Rene Nürnberger
  17.    (c) SpeedSoft GbR, 1995
  18.  -------------------------------------------------------*/
  19.  
  20. USES Os2Def,PMWIN;
  21.  
  22. CONST
  23.      ID_BUTTON = 1;
  24.      ID_SCROLL = 2;
  25.      ID_ENTRY  = 3;
  26.  
  27.      szClientClass:STRING = 'Welcome4' ;
  28.      flFrameFlags:ULONG   = FCF_TITLEBAR OR FCF_SYSMENU OR
  29.                             FCF_BORDER OR FCF_MINBUTTON OR
  30.                             FCF_SHELLPOSITION OR FCF_TASKLIST ;
  31.  
  32. VAR
  33.     ahab : HAB ;
  34.     ahmq : HMQ ;
  35.     hwndFrame,  hwndClient : HWND;
  36.     aqmsg : QMSG;
  37.     rcl : RECTL;
  38.  
  39.  
  40. FUNCTION ClientWndProc (ahwnd:HWND;msg:ULONG;mp1:MPARAM;mp2:MPARAM):MRESULT; CDECL;
  41. BEGIN
  42.      CASE msg OF
  43.          WM_COMMAND:
  44.          BEGIN
  45.               CASE lo(mp1) OF
  46.                   ID_BUTTON:
  47.                   BEGIN
  48.                         WinAlarm (HWND_DESKTOP, WA_NOTE) ;
  49.                         ClientWndProc:=0;
  50.                         exit;
  51.                   END;
  52.               END; {case}
  53.          END;
  54.          WM_ERASEBACKGROUND:
  55.          BEGIN
  56.               ClientWndProc:=MRFROMSHORT (1) ;
  57.               exit;
  58.          END;
  59.  
  60.          ELSE ClientWndProc:=WinDefWindowProc (ahwnd, msg, mp1, mp2) ;
  61.      END; {case}
  62. END;
  63.  
  64. BEGIN
  65.      ahab := WinInitialize (0) ;
  66.      ahmq := WinCreateMsgQueue (ahab, 0) ;
  67.  
  68.      WinRegisterClass (
  69.                     ahab,                { Anchor block handle             }
  70.                     szClientClass,       { Name of class being registered  }
  71.                     @ClientWndProc,      { Window procedure for class      }
  72.                     CS_SIZEREDRAW,       { Class style                     }
  73.                     0) ;                 { Extra bytes to reserve          }
  74.  
  75.      hwndFrame := WinCreateStdWindow (
  76.                     HWND_DESKTOP,        { Parent window handle            }
  77.                     WS_VISIBLE,          { Style of frame window           }
  78.                     flFrameFlags,        { Pointer to control data         }
  79.                     szClientClass,       { Client window class name        }
  80.                     NIL,                 { Title bar text                  }
  81.                     0,                   { Style of client window          }
  82.                     0,                   { Module handle for resources     }
  83.                     0,                   { ID of resources                 }
  84.                     hwndClient) ;        { Pointer to client window handle }
  85.  
  86.           /*--------------------------------------------------------
  87.              Find dimensions of client window for sizes of children
  88.             --------------------------------------------------------*/
  89.  
  90.      WinQueryWindowRect (hwndClient, rcl) ;
  91.      rcl.xRight := rcl.xright DIV 3 ;    { divide width in thirds          }
  92.  
  93.           /*---------------------------
  94.              Create push button window
  95.             ---------------------------*/
  96.  
  97.      WinCreateWCWindow (
  98.                     hwndClient,                   { Parent window handle   }
  99.                     WC_BUTTON,                    { Window class           }
  100.                     'Big Button',                 { Window text            }
  101.                     WS_VISIBLE OR BS_PUSHBUTTON , { Window style           }
  102.                     10,                           { Window position        }
  103.                     10,
  104.                     rcl.xRight - 20,              { Window size            }
  105.                     rcl.yTop - 20,
  106.                     hwndClient,                   { Owner window handle    }
  107.                     HWND_BOTTOM,                  { Placement window handle}
  108.                     ID_BUTTON,                    { Child window ID        }
  109.                     NIL,                          { Control data           }
  110.                     NIL) ;                        { Presentation parameters}
  111.  
  112.           /*--------------------------
  113.              Create scroll bar window
  114.             --------------------------*/
  115.  
  116.      WinCreateWCWindow (
  117.                     hwndClient,                   { Parent window handle   }
  118.                     WC_SCROLLBAR,                 { Window class           }
  119.                     NIL,                          { Window text            }
  120.                     WS_VISIBLE OR SBS_VERT,       { Window style           }
  121.                     rcl.xRight + 10,              { Window position        }
  122.                     10,
  123.                     rcl.xRight - 20,              { Window size            }
  124.                     rcl.yTop - 20,
  125.                     hwndClient,                   { Owner window handle    }
  126.                     HWND_BOTTOM,                  { Placement window handle}
  127.                     ID_SCROLL,                    { Child window ID        }
  128.                     NIL,                          { Control data           }
  129.                     NIL) ;                        { Presentation parameters}
  130.  
  131.           /*-------------------------------------
  132.              Create multiline entry field window
  133.             -------------------------------------*/
  134.  
  135.      WinCreateWCWindow (
  136.                     hwndClient,                   { Parent window handle   }
  137.                     WC_MLE,                       { Window class           }
  138.                     NIL,                          { Window text            }
  139.                     WS_VISIBLE OR MLS_BORDER      { Window style           }
  140.                                OR MLS_VSCROLL
  141.                                OR MLS_WORDWRAP,
  142.                     2 * rcl.xRight + 10,          { Window position        }
  143.                     10,
  144.                     rcl.xRight - 20,              { Window size            }
  145.                     rcl.yTop - 20,
  146.                     hwndClient,                   { Owner window handle    }
  147.                     HWND_BOTTOM,                  { Placement window handle}
  148.                     ID_ENTRY,                     { Child window ID        }
  149.                     NIL,                          { Control data           }
  150.                     NIL) ;                        { Presentation parameters}
  151.  
  152.      WHILE WinGetMsg (ahab, aqmsg, NULLHANDLE, 0, 0) DO
  153.           WinDispatchMsg (ahab, aqmsg) ;
  154.  
  155.      WinDestroyWindow (hwndFrame) ;
  156.      WinDestroyMsgQueue (ahmq) ;
  157.      WinTerminate (ahab) ;
  158. END.
  159.  
  160.