home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / MFKASM.ZIP / 386_WIN.MAC < prev    next >
Text File  |  1992-07-29  |  15KB  |  438 lines

  1. ;------------------------------------------------------
  2. ;386_win.mac Begun:Mon  05-04-1992  Revised:Thu  07-16-1992
  3. ;M. F. Kaplon
  4. ;Macros using the WINxxxx calls of OS/2 2.0
  5. ;Since using the Library that uses C-calling convention must push
  6. ;parameters in reverse order and reset the stack pointer.
  7. ;All Macro Names begin with $ and are followed in all
  8. ;cases of a WIN.... call with the name of the call
  9. ;Each WIN call macro resets the stack pointer based on number of pushes
  10. ;and the type of the push ( DWORDs)
  11. ;------------------------------------------------------
  12.  
  13. EXTRN     WinAlarm:near,WinBeginPaint:near,WinChangeSwitchEntry:near
  14. EXTRN     WinCreateMsgQueue:near,WinCreateStdWindow:near,WinDefWindowProc:near
  15. EXTRN     WinDestroyMsgQueue:near,WinDestroyWindow:near,WinDispatchMsg:near
  16. EXTRN     WinDrawText:near,WinEndPaint:near,WinFillRect:near,WinFreeErrorInfo:near
  17. EXTRN     WinGetCurrentTime:near,WinGetErrorInfo:near,WinGetKeyState:near
  18. EXTRN     WinGetMsg:near,WinGetLastError:near,WinInitialize:near,WinMessageBox:near
  19. EXTRN     WinOpenWindowDC:near
  20. EXTRN     WinQueryDesktopWindow:near,WinQuerySwitchList:near,WinQueryWindowRect:near
  21. EXTRN     WinRegisterClass:near,WinReleaseHook:near,WinReleasePS:near
  22. EXTRN     WinSetHook:near,WinTerminate:near
  23.  
  24. EXTRN     GPICreatePS:near,GpiSetDrawingMode:near
  25.  
  26. ;-------------------------- STRUCTURES --------------------------
  27.  
  28. ; for information - defined in PMWIN.H
  29. ;QMSG  STRUC
  30. ;   qmsg_hwnd DD  ?     ;handle of queue
  31. ;   qmsg_msg  DD  ?     ;message ID e.g. WM_PAINT, etc
  32. ;   qmsg_mp1  DD  ?     ;DWORD value
  33. ;   qmsg_mp2  DD  ?     ;DWORD value
  34. ;   qmsg_time DD  ?     ;time message generated
  35. ;   qmsg_ptl  DB  SIZE POINTL DUP (?)   ;pointer position whe msg generated
  36. ;   qmsg_reserved DD  ?
  37. ;QMSG  ENDS
  38.  
  39. ; for information - defined in   os2def.inc
  40. ;RECTL  STRUC   ;structure for WinFillRect
  41. ;   rcl_xLeft   DD  ?
  42. ;   rcl_yBottom DD  ?
  43. ;   rcl_xRight  DD  ?
  44. ;   rcl_yTop    DD  ?
  45. ;RECTL  ENDS
  46.  
  47. ;ERRINFO STRUC
  48. ;erri_cbFixedErrInfo DD  ?
  49. ;erri_idError  DD  ?
  50. ;erri_cDetailLevel DD  ?
  51. ;erri_offaoffszMsg DD  ?
  52. ;erri_offBinaryData  DD  ?
  53. ;ERRINFO ENDS
  54.  
  55. ;---------------- Switch List Structures in PMSHL.INC
  56. ;SWCNTRL STRUC   ;size = 96                        ;OFFSET FROM 0
  57. ;swctl_hwnd      DD      ?                              8
  58. ;swctl_hwndIcon  DD      ?                             12
  59. ;swctl_hprog     DD      ?                             16
  60. ;swctl_idProcess DD      ?                             20
  61. ;swctl_idSession DD      ?                             24
  62. ;swctl_uchVisibility     DD      ?                     28
  63. ;swctl_fbJump    DD      ?                             32
  64. ;swctl_szSwtitle DB      MAXNAMEL+4 DUP (?)            36
  65. ;swctl_bProgType DD      ?                            100
  66. ;SWCNTRL ENDS
  67.  
  68. ;SWENTRY STRUC   ;size = 4 + 96                    ;    4
  69. ;swent_hswitch   DD      ?                         ;    8
  70. ;swent_swctl     DB      SIZE SWCNTRL DUP (?)
  71. ;SWENTRY ENDS
  72.  
  73. ;SWBLOCK STRUC   ;size = 4 + (4+96)                ;
  74. ;swblk_cswentry  DD      ?                         ;     0
  75. ;swblk_aswentry  DB      SIZE SWENTRY * 1 DUP (?)  ;     4
  76. ;SWBLOCK ENDS
  77.  
  78. ;SWL_VISIBLE     EQU     04H
  79. ;SWL_INVISIBLE   EQU     01H
  80. ;SWL_GRAYED      EQU     02H
  81. ;SWL_JUMPABLE    EQU     02H
  82. ;SWL_NOTJUMPABLE EQU     01H
  83. ;MAXNAMEL        EQU     60
  84.  
  85. ;
  86. ;------------------------- General Purpose Macros --------------------------
  87.  
  88. $DefineWinBufs   MACRO    ;Define Buffers used for WIN routines
  89.     msgmsg        QMSG   {,,,,,,}
  90.     winStyle      DWORD  ?
  91.     defREsult     DWORD  ?   ;WinDefWindowProc  return value
  92.     msgResult     DWORD  ?   ;returned by WinGetMsg
  93.     rclUpdate     RECTL   {,,,}
  94. ENDM
  95.  
  96. $DefineWinHandles  MACRO
  97.     hab           DWORD   ?           ;wininitialize
  98.     hmq           DWORD   ?           ;handle to process message queue
  99.     hwndMainFrame DWORD   0           ;handle to main frame window
  100.     hwndMain      DWORD   ?           ;handle to main client window
  101.     hDeskTop      DWORD   ?           ;handle to DeskTop
  102.     hps           DWORD   ?           ;presentation space handle
  103. ENDM
  104.  
  105. ;---------------------- GPI ...  Macros -------------------------
  106.  
  107. $GpiCreatePS MACRO arg0,arg1,arg2,arg3
  108.     push     arg3         ;Options - set of or's
  109.     push     arg2         ;offset Presentation Page Size - default is 0,0
  110.     push     arg1         ;Device Context Handle
  111.     push     arg0         ;Anchor Block Handle
  112.     call     GpiCreatePS
  113.     add      esp,24
  114. ENDM
  115.  
  116. $GpiSetDrawingMode  MACRO  arg1,arg2
  117.     push     arg2          ;drawing mode
  118.     push     arg1          ;presentation space handle
  119.     call     GpiSetDrawingMode
  120.     add      esp,8
  121. ENDM
  122.  
  123. ;---------------------- WIN General Purpose Macros -------------------------
  124.  
  125. ;OS/2 does not use HAB returned by call to WinInitialize but deduces it from
  126. ;the calling thread. It is suggested for portrability considerations.
  127.  
  128. ;!!!!! Those PM calls that open a window must when linking use
  129. ;!!!!! the /PM:PM option and not /PM:VIO option
  130. ;!!!!! Using the /PM:PM option means all writing to screen must be
  131. ;!!!!! done with PM functions (i.e. WinDrawText)
  132.  
  133. $WinAlarm  MACRO  arg1,arg2 ;are WA_WARNING,WA_NOTE,WA_ERROR,WA_CWINALARMS
  134.     push     arg2          ;kind of alarm
  135.     push     arg1          ;Window Handle
  136.     call     WinAlarm
  137.     add      esp,8             ;restore stack pointer
  138. ENDM
  139.  
  140. $WinErrorMessage MACRO arg      ;sound alarm and display error box
  141.     $DWordToAscii eax,DW_Buf
  142.     $Alarm
  143.     $ConcantS1andS2ToS3 DW_Buf,arg,Concanted
  144.     $WinMessageBox HWND_DESKTOP,HWND_DESKTOP,offset Concanted,NULL,0,msgBoxErrStyle
  145.     $WinTerminate  hab
  146.     $DosExit
  147. ENDM
  148.  
  149. ;---------------------- WIN..... Macros -------------------------
  150.  
  151. $WinBeginPaint  MACRO  arg0,arg1,arg2
  152.     push     arg2                  ;address of variable to set to invalid region
  153.     push     arg1                  ;null handle for Presentation space
  154.     push     arg0                  ;client window
  155.     call     WinBeginPaint
  156.     add      esp,12             ;restore stack pointer
  157. ENDM
  158.  
  159. $WinChangeSwitchEntry  MACRO  data,handle
  160.      push    data
  161.      push    handle
  162.      call    WinChangeSwitchEntry
  163.     .IF eax != NULL
  164.        IFDEF   NOWIN
  165.           $DosErrMsg  "WinChangeSwitchEntry"
  166.           $DosExit
  167.        ELSE
  168.           $WinGetLastError  hab
  169.           $WinErrorMessage msgWinChangeSwitchEntry
  170.        ENDIF
  171.     .ENDIF
  172.     add      esp,8   ;restore stack pointer
  173. ENDM
  174.  
  175. $WinCreateMsgQueue  MACRO  arg1,arg2   ;handle returned is hmq for queue
  176.     pushd    arg2      ; Queue Size LONG
  177.     push     arg1       ;Anchor Block Handle returned by  $WinInitialize
  178.     call     WinCreateMsgQueue
  179.     add      esp,8
  180. ENDM
  181.  
  182. $WinCreateStdWindow MACRO arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8
  183.     push     arg8              ;address to receive client window handle
  184.     push     arg7              ;(Resource)Frame Window ID
  185.     push     arg6              ;Resource Module Identifier
  186.     push     arg5              ;Client window style
  187.     push     arg4              ;Offset of Title Bar Text
  188.     push     arg3              ;Offset Client Window class name
  189.     push     arg2              ;address of variable holding Frame Creation Flags
  190.     push     arg1              ;Frame window style
  191.     push     arg0              ;Parent Window Handle
  192.     call     WinCreateStdWindow
  193.     add      esp,36
  194. ENDM
  195.  
  196. $WinDefWindowProc  MACRO  arg0,arg1,arg2,arg3
  197.     push     arg3  ;mp2 = msgmsg.qmsg_mp2
  198.     push     arg2  ;mp2 = msgmsg.qmsg_mp1
  199.     push     arg1  ;msg = msgmsg.qmsg_msg
  200.     push     arg0  ;hwnd =frame window handle
  201.     call     WinDefWindowProc
  202.     add      esp,16
  203. ENDM
  204.  
  205. $WinDestroyMsgQueue MACRO  arg
  206.     push     arg                 ;message que handle
  207.     call     WinDestroyMsgQueue
  208.     add      esp,4
  209. ENDM
  210.  
  211. $WinDestroyWindow  MACRO  arg
  212.     push     arg
  213.     call     WinDestroyWindow
  214.     add      esp,4
  215. ENDM
  216.  
  217. $WinDispatchMsg  MACRO   arg0,arg1
  218.     push     arg1     ;offset message queue structure
  219.     push     arg0     ;anchor block handle
  220.     call     WinDispatchMsg    ;eax has correct return value
  221.     add      esp,8
  222. ENDM
  223.  
  224. $WinDrawText  MACRO  arg0,arg1,arg2,arg3,arg4,arg5,arg6
  225.     push     arg6             ;mode in which string is to be drawn
  226.     push     arg5             ;background_color
  227.     push     arg4             ;foreground_color
  228.     push     arg3             ;address of structure RECTL holding screen defn
  229.     push     arg2             ;address of msgID
  230.     push     arg1             ;Length of String or terminator definition
  231.     push     arg0             ;Presentation space handle
  232.     call     WinDrawText
  233.     add      esp,28              ;restore stack pointer
  234. ENDM
  235.  
  236. $WinEndPaint   MACRO arg0
  237.     push     arg0                ;presentation space cache handle
  238.     call     WinEndPaint
  239.     add      esp,4             ;restore stack pointer
  240. ENDM
  241.  
  242. $WinFillRect   MACRO  arg0,arg1,arg2
  243.     push     arg2               ;color
  244.     push     arg1               ;address of structure defining rectangle
  245.     push     arg0               ;presentation space handle
  246.     call     WinFillRect
  247.     add      esp,12            ;restore stack pointer
  248. ENDM
  249.  
  250. $WinFreeErrorInfo  MACRO    arg
  251.     push     arg    ;Pointer to Error Information Block
  252.     call     WinFreeErrorInfo
  253.     add      esp,4
  254. ENDM
  255.  
  256. $WinGetCurrentTime  MACRO  ;time in msec returned in eax
  257.     push     NULL          ;this is a sort of default HAB see above
  258.     call     WinGetCurrentTime
  259.     add      esp,4
  260. ENDM
  261.  
  262. $WinGetErrorInfo  MACRO  arg
  263.     push     arg
  264.     call     WinGetErrorInfo
  265.     add      esp,4
  266. ENDM
  267.  
  268. $WinGetKeyState  MACRO     lVK
  269.     push     ecx
  270.     push     edx
  271.     push     lVK
  272.     push     offset HWND_DESKTOP
  273.     call     WinGetKeyState
  274.     add      esp,8
  275.     pop      edx
  276.     pop      ecx
  277. ENDM
  278.  
  279. $WinGetLastError MACRO arg
  280.     push     arg
  281.     call     WinGetLastError
  282.     add      esp,4
  283. ENDM
  284.  
  285. $WinGetMsg  MACRO  arg0,arg1,arg2,arg3,arg4
  286.     push    arg4              ;last message identity
  287.     push    arg3              ;first message identity
  288.     push    arg2              ;window filter
  289.     push    arg1              ;message structure  defined  above
  290.     push    arg0              ;anchor block handle
  291.     call    WinGetMsg         ;REturns TRUE except if msg is WM_QUIT returns FALSE
  292.     add     esp,20            ;restore stack pointer
  293. ENDM
  294.  
  295. $WinInitialize  MACRO   arg
  296.      pushd   arg
  297.      call    WinInitialize
  298.      add      esp,4
  299. ENDM
  300.  
  301. $WinLoadString  MACRO  lcchMax,ulId,hmodMod
  302.     push     nnwritten         ;length of string returned
  303.     push     offset pszBuffer  ;points to buffer that received message
  304.     push     lcchMax           ;size of buffer
  305.     push     ulId              ;message identifier
  306.     push     hmodMod           ;module handle
  307.     push     hab               ;anchor block handle
  308.     call     WinLoadString
  309.     add      esp,24
  310. ENDM
  311.  
  312. $WinMessageBox  MACRO  arg0,arg1,arg2,arg3,arg4,arg5
  313.     push      arg5            ;OR defines for style
  314.     push      arg4            ;message box ID is USHORT
  315.     push      arg3            ;address of message box window title
  316.     push      arg2            ;address of text of error message Null Terminated
  317.     push      arg1            ;owner of handle of window box
  318.     push      arg0            ;handle of parent window is HWND_DESKTOP
  319.     call      WinMessageBox
  320.     add       esp,24
  321. ENDM
  322.  
  323. $WinOpenWindowDC  MACRO  arg
  324.     push     arg
  325.     call     WinOpenWindowDC
  326.     add      esp,4
  327. ENDM
  328.  
  329. $WinQueryDeskTopWindow MACRO  arg1, arg0
  330.     push     arg1       ;device context = 0 for rscreen
  331.     push     arg0       ;anchor block handle
  332.     call     WinQueryDeskTopWindow
  333.     add      esp,8
  334. ENDM
  335.  
  336. $WinQuerySwitchList MACRO lnth,blklist,anch_hdl,nitems
  337.     push     lnth
  338.     push     blklist
  339.     push     anch_hdl
  340.     call     WinQuerySwitchList
  341.    .IF eax == NULL
  342.        IFDEF   NOWIN
  343.            $DosErrMsg  <bel,nl,"WinQuerySwitchList - No Items in List",nl>
  344.            $DosExit
  345.        ELSE
  346.            $WinGetLastError  hab
  347.            $WinErrorMessage  msgWinQuerySwitchList
  348.        ENDIF
  349.     .ENDIF
  350.     add      esp,12   ;restore stack pointer
  351.     mov      nitems,eax
  352. ENDM
  353.  
  354. $WinQueryWindowProcess  MACRO   ppid,hframe
  355.      push    NULL
  356.      push    offset ppid
  357.      push    hframe
  358.      call    WinQueryWindowProcess
  359.     add      esp,12   ;restore stack pointer
  360.     .IF eax == FALSE
  361.        IFDEF   NOWIN
  362.            $DosErrMsg  <"  WinQueryWindowProcess",nl>
  363.            $DosExit
  364.        ELSE
  365.            $WinGetLastError  hab
  366.            $WinErrorMessage  msgWinQueryWindowProcess
  367.        ENDIF
  368.     .ENDIF
  369. ENDM
  370.  
  371. $WinQueryWindowRect MACRO  arg0,arg1
  372.     push     arg1       ;offset rectangle structure
  373.     push     arg0       ;handle for client window
  374.     call     WinQueryWindowRect
  375.     add      esp,8   ;restore stack pointer
  376. ENDM
  377.  
  378. $WinRegisterClass  MACRO  arg0,arg1,arg2,arg3,arg4
  379.     pushd    arg4                ;default storage WORD
  380.     pushd    arg3                ;default style DWORD
  381.     pushd    arg2                ;address of procedure to handle messages
  382.     push     arg1                ;addressof Classname associated with window procedure
  383.     push     arg0                ;Anchor block Handle
  384.     call     WinRegisterClass
  385.     add      esp,20
  386. ENDM
  387.  
  388. $WinReleaseHook  MACRO  arg0,arg1,arg2,arg3,arg4
  389.     push     arg4      ;Resource Identity
  390.     push     arg3      ;Address of Application Hook Procedure
  391.     push     arg2      ;Hook Type
  392.     push     arg1      ;QueueID - NULL for system hook chain
  393.     push     arg0      ;Anchor Block Handle
  394.     call     WinReleaseHook
  395.     add      esp,20
  396.     .IF eax == FALSE
  397.        IFDEF   NOWIN
  398.            $DosErrMsg  <"  WinReleaseHook Error",nl>
  399.            $DosExit
  400.        ELSE
  401.            $WinGetLastError  hab
  402.            $WinErrorMessage  msgWinReleaseHook
  403.        ENDIF
  404.     .ENDIF
  405. ENDM
  406.  
  407. $WinReleasePS  MACRO  arg
  408.     push     arg
  409.     call     WinReleasePS
  410.     add      esp,4
  411. ENDM
  412.  
  413. $WinSetHook  MACRO  arg0,arg1,arg2,arg3,arg4
  414.     push     arg4      ;Resource Identity
  415.     push     arg3      ;Address of Application Hook Procedure
  416.     push     arg2      ;Hook Type
  417.     push     arg1      ;QueueID - NULL for system hook chain
  418.     push     arg0      ;Anchor Block Handle
  419.     call     WinSetHook
  420.     add      esp,20
  421.     .IF eax == FALSE
  422.        IFDEF   NOWIN
  423.            $DosErrMsg  "  WinSetHook Error"
  424.            $DosExit
  425.        ELSE
  426.            $WinGetLastError  hab
  427.            $WinErrorMessage  msgWinSetHook
  428.        ENDIF
  429.     .ENDIF
  430. ENDM
  431.  
  432. $WinTerminate MACRO  arg
  433.     push    arg
  434.     call    WinTerminate
  435.     add     esp,4
  436. ENDM
  437.  
  438.