home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2BAS.ZIP / WINDIALG.BAS < prev    next >
BASIC Source File  |  1989-09-01  |  16KB  |  399 lines

  1. '***********************************************************
  2. '*
  3. '* Program Name: WinDialg.BAS
  4. '*
  5. '* Include File: WinDialg.BI
  6. '*
  7. '* Functions   :
  8. '*               WinLoadDlg
  9. '*               WinDlgBox
  10. '*               WinDismissDlg
  11. '*               WinQueryDlgItemShort
  12. '*               WinSetDlgItemShort
  13. '*               WinSetDlgItemText
  14. '*               WinQueryDlgItemText
  15. '*               WinQueryDlgItemTextLength
  16. '*               WinDefDlgProc
  17. '*               WinAlarm
  18. '*               WinMessageBox
  19. '*               WinProcessDlg
  20. '*               WinSendDlgItemMsg
  21. '*               WinMapDlgPoints
  22. '*               WinEnumDlgItem
  23. '*               WinSubstituteStrings
  24. '*               WinCreateDlg
  25. '*
  26. '* Description : This program demonstrates the various dialog
  27. '*               box functions.  Within the ClientWndProc
  28. '*               function, the system receives messages about
  29. '*               either a key press or a mouse button being
  30. '*               pressed.  Depending on the message, various
  31. '*               functions are executed to bring up a dialog.
  32. '*               Those functions which do not produce notable
  33. '*               results send their return value to a file
  34. '*               called:  WinDialg.OUT.  Each function is
  35. '*               documented to what it is going to do just prior
  36. '*               to the call.
  37. '***********************************************************
  38.  
  39. '********* Internal SUB and FUNCTION Declaration *********
  40.  
  41. DECLARE SUB MakeMessageBox (hwnd&)
  42. DECLARE FUNCTION DosGetResource% (BYVAL p1 AS INTEGER,_
  43.                                   BYVAL p2 AS INTEGER,_
  44.                                   BYVAL p3 AS INTEGER,_
  45.                                   SEG p4 AS INTEGER)
  46. DECLARE FUNCTION RegBas1&
  47. DECLARE FUNCTION RegBas2&
  48.  
  49. '*********         Initialization section        *********
  50.  
  51. REM $INCLUDE: 'PMBase.BI'
  52. REM $INCLUDE: 'WinDialg.BI'
  53. REM $INCLUDE: 'WinInput.BI'       Needed for messages
  54. REM $INCLUDE: 'OS2Def.BI'         Needed for POINTL type
  55. REM $INCLUDE: 'WinButtn.BI'       Needed for setting BMSETCHECK
  56.  
  57. OPEN "WinDialg.OUT" FOR OUTPUT AS #1
  58.  
  59. DIM aqmsg AS QMSG
  60.  
  61. flFrameFlags&  = FCFTITLEBAR      OR FCFSYSMENU OR_
  62.                  FCFSIZEBORDER    OR FCFMINMAX  OR_
  63.                  FCFSHELLPOSITION OR FCFTASKLIST
  64.  
  65. szClientClass$ = "ClassName" + CHR$(0)
  66.  
  67. hab&  = WinInitialize    (0)
  68. hmq&  = WinCreateMsgQueue(hab&, 0)
  69.  
  70. bool% = WinRegisterClass(hab&,_
  71.         MakeLong(VARSEG(szClientClass$), SADD(szClientClass$)),_
  72.         RegBas,_
  73.         0,_
  74.         0)
  75.  
  76. hwndFrame& = WinCreateStdWindow(HWNDDESKTOP,  WSVISIBLE,_
  77.              MakeLong(VARSEG(flFrameFlags&),  VARPTR(flFrameFlags&)),_
  78.              MakeLong(VARSEG(szClientClass$), SADD(szClientClass$)),_
  79.              0, 0, 0, 0,_
  80.              MakeLong(VARSEG(hwndClient&),    VARPTR(hwndClient&)))
  81.  
  82. '**************         Message loop         ***************
  83.  
  84. WHILE WinGetMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)), 0, 0, 0)
  85.   bool% = WinDispatchMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)))
  86. WEND
  87.  
  88. '***********         Finalize section        ***************
  89.  
  90. bool% = WinDestroyWindow   (hwndFrame&)
  91. bool% = WinDestroyMsgQueue (hmq&)
  92. bool% = WinTerminate       (hab&)
  93.  
  94. CLOSE #1
  95.  
  96. END
  97.  
  98. '***********         Window procedure        ***************
  99.  
  100. FUNCTION ClientWndProc& (hwnd&, msg%, mp1&, mp2&) STATIC
  101.      DIM ClientRect AS RECTL
  102.      ClientWndProc& = 0
  103.      SELECT CASE msg%
  104.      CASE WMCREATE     'Tasks to perform during creation.
  105.         Text$  = "Press A Key Or Mouse Button To Bring Up"
  106.         Text$  = Text$ + " The Dialog Boxes..." + CHR$(0)
  107.         Title$ = "Dialog Sampler" + CHR$(0)
  108.  
  109.         '**** WinAlarm sounds a  beep.
  110.         bool%   =  WinAlarm(HWNDDESKTOP, WAERROR)
  111.         PRINT #1, "WinAlarm:", bool%
  112.  
  113.         '**** WinMessageBox creates the initial message box.
  114.         bool% = WinMessageBox(HWNDDESKTOP, HWNDDESKTOP,_
  115.                 MakeLong(VARSEG(Text$),  SADD(Text$)),_
  116.                 MakeLong(VARSEG(Title$), SADD(Title$)), 1,_
  117.                 MBOK OR MBICONEXCLAMATION OR MBSYSTEMMODAL OR MBDEFBUTTON1)
  118.         PRINT #1, "WinMessageBox:", bool%
  119.  
  120.      CASE WMPAINT     'Paint the window with background color
  121.         hps&  = WinBeginPaint(hwnd&, 0,_
  122.                 MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)))
  123.         bool% = WinFillRect(hps&,_
  124.                 MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)), 0)
  125.         bool% = WinEndPaint(hps&)
  126.      CASE WMBUTTON1DOWN     'Left Mouse Button Down, WinDlgBox
  127.  
  128.         '**** WinDlgBox loads and processes dialog box in ClientWndProc1
  129.         bool%   =  WinDlgBox(HWNDDESKTOP, hwnd&, RegBas1, 0, 300, 0)
  130.         PRINT #1, "WinDlgBox:", bool%
  131.  
  132.         ClientWndProc& = WinDefWindowProc(hwnd&, msg%, mp1&, mp2&)
  133.  
  134.      CASE WMBUTTON2DOWN     'Right Mouse Button Down, WinLoadDlg
  135.  
  136.         '**** WinLoadDlg loads and processes dialog box in ClientWndProc2
  137.         hwndDlg& = WinLoadDlg(HWNDDESKTOP, hwnd&, RegBas2, 0, 600, 0)
  138.         PRINT #1, "WinLoadDlg:", HEX$(hwndDlg&)
  139.  
  140.      CASE WMCHAR      ' Key Pressed, WinCreateDlg
  141.         '* Load a dialog resource into memory and grab the selector
  142.         bool% = DosGetResource(0, 4, 300, a%)
  143.  
  144.         '**** WinCreateDlg create the dialog from a dialog template defined
  145.         '*    by the selector returned from DosGetResource and return a
  146.         '*    handle to that dialog.  This also is processed in ClientWndProc1.
  147.         MyDlgHwnd& = WinCreateDlg&(HWNDDESKTOP, 0, RegBas1,_
  148.                      MakeLong(a%, 0), 0)
  149.         PRINT #1, "WinCreateDlg:", HEX$(MyDlgHwnd&)
  150.  
  151.      CASE ELSE        'Pass control to system for other messages
  152.         ClientWndProc& = WinDefWindowProc(hwnd&, msg%, mp1&, mp2&)
  153.      END SELECT
  154. END FUNCTION
  155.  
  156. '****
  157. '** ClientWndProc1 is the dialog procedure for WinDlgBox and WinCreateDlg.
  158. '** It allows the user to define and bring up a message box.
  159.  
  160. FUNCTION ClientWndProc1& (hwnd&, msg%, mp1&, mp2&) STATIC
  161.      ClientWndProc1& = 0
  162.      UserCaption$ = "Default Caption" + CHR$(0)
  163.      UserTitle$ = "Default Title" + CHR$(0)
  164.      Substitute$ = "Dummy %1 String" + CHR$(0)
  165.      SELECT CASE msg%
  166.      CASE WMINITDLG
  167.         '**** WinEnumDlgItem returns handle to the 1st group item in dialog
  168.         DummyHwnd& = WinEnumDlgItem(HWNDDESKTOP, hwnd&, EDIFIRSTGROUPTITEM, 0)
  169.         PRINT #1, "WinEnumDlgItem:", HEX$(DummyHwnd&)
  170.  
  171.         '**** WinSendDlgItemMsg to set the radio buttons in the dialog box.
  172.         mresult& = WinSendDlgItemMsg(hwnd&, 258, BMSETCHECK, 1, 0)
  173.         PRINT #1, "WinSendDlgItemMsg:", mresult&
  174.         bool&    = WinSendDlgItemMsg(hwnd&, 267, BMSETCHECK, 1, 0)
  175.         PRINT #1, "WinSendDlgItemMsg:", mresult&
  176.         bool&    = WinSendDlgItemMsg(hwnd&, 276, BMSETCHECK, 1, 0)
  177.         PRINT #1, "WinSendDlgItemMsg:", mresult&
  178.  
  179.         '**** WinSubstituteStrings will look for a %n and send the message
  180.         '*    WMSUBSTITUTESTRING to replace that marker with some text.
  181.         bool% = WinSubstituteStrings(hwnd&,_
  182.                 MakeLong(VARSEG(Substitute$), SADD(Substitute$)), 25,_
  183.                 MakeLong(VARSEG(Substitute$), SADD(Substitute$)))
  184.         PRINT #1, "WinSubstituteStrings:", bool%
  185.  
  186.         '**** WinSetDlgItemText sets the text of a dialog item.
  187.         bool%    = WinSetDlgItemText(hwnd&, 284,_
  188.                    MakeLong(VARSEG(UserCaption$), SADD(UserCaption$)))
  189.         PRINT #1, "WinSetDlgItemText:", bool%
  190.         bool%    = WinSetDlgItemText(hwnd&, 285,_
  191.                    MakeLong(VARSEG(UserTitle$), SADD(UserTitle$)))
  192.         PRINT #1, "WinSetDlgItemText:", bool%
  193.  
  194.      CASE WMSUBSTITUTESTRING  'A %n character was received in the source string
  195.         PRINT #1, "### In WMSUBSTITUTESTRING Message Handler ###"
  196.  
  197.      CASE WMCOMMAND
  198.         CALL BreakLong(mp1&, HiWord%, LoWord%)
  199.         SELECT CASE LoWord%
  200.            CASE 257     'WinAlarm Pressed.
  201.               Alarm& = 0
  202.               FOR i = 258 TO 260
  203.                  '**** WinSendDlgItemMsg to find which radio button is checked
  204.                  Alarm&  =  WinSendDlgItemMsg(hwnd&, i, BMQUERYCHECK, 0, 0)
  205.                  PRINT #1, "WinSendDlgItemMsg:", Alarm&
  206.                  IF Alarm& THEN
  207.                     SELECT CASE i
  208.                        CASE 258
  209.                           bool% = WinAlarm(HWNDDESKTOP, WANOTE)
  210.                        CASE 259
  211.                           bool% = WinAlarm(HWNDDESKTOP, WAWARNING)
  212.                        CASE 260
  213.                           bool% = WinAlarm(HWNDDESKTOP, WAERROR)
  214.                     END SELECT
  215.                  END IF
  216.               NEXT i
  217.  
  218.            CASE 263     'WinMessageBox Pressed.
  219.               CALL MakeMessageBox(hwnd&)
  220.  
  221.            CASE 262     'Cancel Pressed.
  222.               '**** WinDismissDlg dismisses and hides current dialog
  223.               bool%   =  WinDismissDlg%(hwnd&, 262)
  224.               PRINT #1, "WinDismissDlg:", bool%
  225.  
  226.               '**** WinProcessDlg determines the result of dialog
  227.               Result% =  WinProcessDlg(hwnd&)
  228.               PRINT #1, "WinProcessDlg:", Result%
  229.  
  230.         END SELECT
  231.      CASE ELSE        'Pass control to system for other messages
  232.         ClientWndProc1& = WinDefDlgProc(hwnd&, msg%, mp1&, mp2&)
  233.      END SELECT
  234. END FUNCTION
  235.  
  236. '****
  237. '** ClientWndProc2 is the dialog procedure for WinDlgBox.  It allows
  238. '** the user to input points and map them to two coordinate spaces.
  239. FUNCTION ClientWndProc2& (hwnd&, msg%, mp1&, mp2&) STATIC
  240.      DIM DialogPts AS POINTL
  241.      ClientWndProc2& = 0
  242.      SELECT CASE msg%
  243.      CASE WMINITDLG     'Initialize before showing dialog.
  244.         x1% = 0
  245.         y1% = 0
  246.  
  247.         '**** WinSetDlgItemShort to set x and y coordinates
  248.         bool% = WinSetDlgItemShort(hwnd&, 263, x1%, 0)
  249.         bool% = WinSetDlgItemShort(hwnd&, 260, y1%, 0)
  250.  
  251.         bool% = WinSetDlgItemShort(hwnd&, 264, x1%, 0)
  252.         bool% = WinSetDlgItemShort(hwnd&, 265, y1%, 0)
  253.  
  254.         bool% = WinSetDlgItemShort(hwnd&, 267, x1%, 0)
  255.         bool% = WinSetDlgItemShort(hwnd&, 268, y1%, 0)
  256.         PRINT #1, "WinSetDlgItemShort:", bool%
  257.  
  258.      CASE WMCOMMAND
  259.         CALL BreakLong(mp1&, HiWord%, LoWord%)
  260.         SELECT CASE LoWord%
  261.         CASE 269     'Cancel Pressed.
  262.            '**** WinDismissDlg dismisses and hides the dialog
  263.            bool%   =  WinDismissDlg%(hwnd&, 269)
  264.            PRINT #1, "WinDismissDlg:", bool%
  265.  
  266.            '**** WinProcessDlg determines the result of dialog
  267.            Result% =  WinProcessDlg(hwnd&)
  268.            PRINT #1, "WinProcessDlg:", Result%
  269.  
  270.         CASE 270     'WinMapDlgPoints Pressed.
  271.            '**** WinQueryDlgItemShort will return an integer representation
  272.            '*    of a dialog field
  273.            bool%    = WinQueryDlgItemShort(hwnd&, 263,_
  274.                       MakeLong(VARSEG(x1%), VARPTR(x1%)), 0)
  275.            bool%    = WinQueryDlgItemShort(hwnd&, 260,_
  276.                       MakeLong(VARSEG(y1%), VARPTR(y1%)), 0)
  277.            PRINT #1, "WinQueryDlgItemShort:", bool%
  278.  
  279.            DialogPts.x = x1%
  280.            DialogPts.y = y1%
  281.  
  282.            '**** WinMapDlgPoints converts points to dialog coordinates
  283.            bool%    = WinMapDlgPoints(hwnd&,_
  284.                       MakeLong(VARSEG(DialogPts), VARPTR(DialogPts)), 1, 0)
  285.            PRINT #1, "WinMapDlgPoints:", bool%
  286.  
  287.            x2% = DialogPts.x
  288.            y2% = DialogPts.y
  289.  
  290.            '**** WinSetDlgItemShort will put the integer values into the
  291.            '*    dialog item declared in the call
  292.            bool%    = WinSetDlgItemShort(hwnd&, 264, x2%, 0)
  293.            bool%    = WinSetDlgItemShort(hwnd&, 265, y2%, 0)
  294.            PRINT #1, "WinSetDlgItemShort:", bool%
  295.  
  296.            DialogPts.x = x1%
  297.            DialogPts.y = y1%
  298.  
  299.            '**** WinMapDlgPoints converts points to window coordinates
  300.            bool%    = WinMapDlgPoints(hwnd&,_
  301.                       MakeLong(VARSEG(DialogPts), VARPTR(DialogPts)), 1, 1)
  302.            PRINT #1, "WinMapDlgPoints:", bool%
  303.  
  304.            x2% = DialogPts.x
  305.            y2% = DialogPts.y
  306.  
  307.            '**** WinSetDlgItemShort will put the integer values into the
  308.            '*    dialog item declared in the call
  309.            bool%    = WinSetDlgItemShort(hwnd&, 267, x2%, 0)
  310.            bool%    = WinSetDlgItemShort(hwnd&, 268, y2%, 0)
  311.            PRINT #1, "WinSetDlgItemShort:", bool%
  312.         END SELECT
  313.  
  314.      CASE ELSE        'Pass control to system for other messages
  315.         ClientWndProc2& = WinDefDlgProc(hwnd&, msg%, mp1&, mp2&)
  316.      END SELECT
  317. END FUNCTION
  318.  
  319.  
  320.  
  321. SUB MakeMessageBox (hwnd&)
  322.    Result&  = 0
  323.    Options& = 0
  324.    FOR i%   = 264 TO 283
  325.       '**** WinSendDlgItemMsg checks if the item is checked
  326.       Result& = WinSendDlgItemMsg(hwnd&, i%, BMQUERYCHECK, 0, 0)
  327.  
  328.       IF Result& THEN
  329.          SELECT CASE i%     'Get Dialog options
  330.              CASE 264
  331.                 Options& = MBABORTRETRYIGNORE
  332.              CASE 265
  333.                 Options& = MBENTER
  334.              CASE 266
  335.                 Options& = MBENTERCANCEL
  336.              CASE 267
  337.                 Options& = MBOK
  338.              CASE 268
  339.                 Options& = MBOKCANCEL
  340.              CASE 269
  341.                 Options& = MBRETRYCANCEL
  342.              CASE 270
  343.                 Options& = MBYESNO
  344.              CASE 271
  345.                 Options& = MBYESNOCANCEL
  346.              CASE 272
  347.                 Options& = Options& OR MBICONASTERISK
  348.              CASE 273
  349.                 Options& = Options& OR MBICONEXCLAMATION
  350.              CASE 274
  351.                 Options& = Options& OR MBICONHAND
  352.              CASE 275
  353.                 Options& = Options& OR MBICONQUESTION
  354.              CASE 276
  355.                 Options& = Options& OR MBNOICON
  356.              CASE 277
  357.                 Options& = Options& OR MBDEFBUTTON1
  358.              CASE 278
  359.                 Options& = Options& OR MBDEFBUTTON2
  360.              CASE 279
  361.                 Options& = Options& OR MBDEFBUTTON3
  362.              CASE 280
  363.                 Options& = Options& OR MBAPPLMODAL
  364.              CASE 281
  365.                 Options& = Options& OR MBSYSTEMMODAL
  366.              CASE 282
  367.                 Options& = Options& OR MBHELP
  368.              CASE 283
  369.                 Options& = Options& OR MBMOVEABLE
  370.          END SELECT
  371.       END IF
  372.    NEXT i%
  373.  
  374.    '**** WinQueryDlgItemTextLength determines dialog string length.
  375.    Length%  = WinQueryDlgItemTextLength(hwnd&, 284)
  376.    PRINT #1, "WinQueryDlgItemTextLength:", Length%
  377.  
  378.    UserTitle$ = SPACE$(Length% + 1)
  379.    '**** WinQueryDlgItemText returns the string from a specific dialog entry
  380.    bool% = WinQueryDlgItemText(hwnd&, 284, Length% + 1,_
  381.            MakeLong(VARSEG(UserTitle$), SADD(UserTitle$)))
  382.  
  383.    '**** WinQueryDlgItemTextLength determines dialog string length.
  384.    Length%  = WinQueryDlgItemTextLength(hwnd&, 285)
  385.    PRINT #1, "WinQueryDlgItemTextLength:", Length%
  386.  
  387.    UserCaption$ = SPACE$(Length% + 1)
  388.    '**** WinQueryDlgItemText returns the string from a specific dialog entry
  389.    bool% = WinQueryDlgItemText(hwnd&, 285, Length% + 1,_
  390.            MakeLong(VARSEG(UserCaption$), SADD(UserCaption$)))
  391.  
  392.    '**** WinMessageBox will create the user's dialog box.
  393.    bool% = WinMessageBox%(HWNDDESKTOP,    hwnd&,_
  394.            MakeLong(VARSEG(UserTitle$),   SADD(UserTitle$)),_
  395.            MakeLong(VARSEG(UserCaption$), SADD(UserCaption$)),_
  396.            1, Options&)
  397.    PRINT #1, "WinMessageBox:", bool%
  398. END SUB
  399.