Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Wed May 12, 2004 8:36 am Post subject: |
|
|
It may be handy to create a little topic about converting API calls from other languages into VDS syntax. How does this look with the example code which bbelcher gave?
| Declarations wrote: | Option Explicit
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Private Const MF_BYPOSITION = &H400& |
| Code wrote: | Public Function DisableCloseButton(frm As Form) As Boolean
'PURPOSE: Removes X button from a form
'EXAMPLE: DisableCloseButton Me
'RETURNS: True if successful, false otherwise
'NOTES: Also removes Exit Item from
' Control Box Menu
Dim lHndSysMenu As Long
Dim lAns1 As Long, lAns2 As Long
lHndSysMenu = GetSystemMenu(frm.hwnd, 0)
'remove close button
lAns1 = RemoveMenu(lHndSysMenu, 6, MF_BYPOSITION)
'Remove seperator bar
lAns2 = RemoveMenu(lHndSysMenu, 5, MF_BYPOSITION)
'Return True if both calls were successful
DisableCloseButton = (lAns1 <> 0 And lAns2 <> 0)
End Function |
First of all, you need to look which DLLs are used and open them which the loadlib function. In this case, it is the user32.dll, so we need that one. At the declarations code, you see a long line with the name of the function, the dll name, the parameters between brackets and last off all the type of the stuff returned by the API. Now, let us convert the code into VDS language:
| Code: | #define function,DisableCloseButton
if @DisableCloseButton(<your window name here>)
info The close button is disabled.
else
warn The close button IS NOT disabled.
end
exit
# Public Function DisableCloseButton(frm As Form) As Boolean
:DisableCloseButton
# Because VDS can't give functions parameters like "frm", we should change %1 info %%frm
%%frm = %1
# Load the proper library
loadlib user32.dll
# 'PURPOSE: Removes X button from a form
# 'EXAMPLE: DisableCloseButton Me
# 'RETURNS: True if successful, false otherwise
# 'NOTES: Also removes Exit Item from
# ' Control Box Menu
# We don't have to declare variables, so just rem-them-out... We do have to 'declare' the
# pre-made variables from within the declarations code, so we can use their values. Note that &H
# should be converted into a $ sign, and that the last & can be left away.
# Dim lHndSysMenu As Long
# Dim lAns1 As Long, lAns2 As Long
# Private Const MF_BYPOSITION = &H400&
%%MF_BYPOSITION = $400
# Because in VB API code is declared, the dll name and parameter type don't have to be declared in the
# script itself. Because that isn't the case with VDS, we should use the following lines of VB code:
#
# Private Declare Function GetSystemMenu Lib "user32" _
# (ByVal hwnd As Long, _
# ByVal bRevert As Long) As Long
#
# This is about the same syntax as the @lib() function. The @lib() function should be called like this:
# @lib(<dll name>,<function name>,<return type>,<parameters>,<...>)
#
# When filling it in, you get this:
# @lib(user32.dll,GetSystemMenu,INT: (the VDS equivement of LONG),%%hwnd,%%bRevert)
#
# Now, just use the same variables as the VB code:
# lHndSysMenu = GetSystemMenu(frm.hwnd, 0)
%%frm_hwnd = @strdel(@winexists(%%frm),1,1)
%%lHndSysMenu = @lib(user32,GetSystemMenu,INT:,%%frm_hwnd,0)
# 'remove close button
# lAns1 = RemoveMenu(lHndSysMenu, 6, MF_BYPOSITION)
%%lAns1 = @lib(user32.dll,RemoveMenu,INT:,%%lHndSysMenu,6,%%MF_BYPOSITION)
# 'Remove seperator bar
# lAns2 = RemoveMenu(lHndSysMenu, 5, MF_BYPOSITION)
%%lAns2 = @lib(user32.dll,RemoveMenu,INT:,%%lHndSysMenu,5,%%MF_BYPOSITION)
# Unload the library
freelib user32.dll
# 'Return True if both calls were successful
# DisableCloseButton = (lAns1 <> 0 And lAns2 <> 0)
# End Function
exit @both(%%lAns1,%%lAns2) |
I hope it is understandable, otherwise, could somebody maybe write another example for people to learn how to use API functions?  _________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|