Post by Beaker on Feb 18, 2004 19:45:16 GMT
www.blitzbasic.com/Community/posts.php?topic=30659
Info by soja:
Here is the C++ prototype:
This means that the function returns a boolean value (which translates to an int% in Blitz). A handle-type variable (HWND - Window Handle) is effectively an int% in Blitz. And PWWINDOWINFO is a pointer to a window information struct, so in the decls it would be marked with '*'. (Pointers are always marked with '*' except when you want to pass the NULL pointer, in which case you have to mark it as '%' and pass 0.) Like so:
Now if you go to MSDN, look up GetWindowInfo, and click on "WINDOWINFO" structure, it will tell you what fields it's compsed of. A C struct is very similar to a Blitz type. And in this case, we're in luck, becuase the struct does not have any strings (pointers to character arrays) in it, which means we can safely use a custom type object. (Otherwise we would have to use a bank.)
It turns out that all the parameters are full 32-bit types except for the last two, so all the fields save those two can be represented as ints%. The last two (ATOM and WORD) are both 16-bit structures, so we can combine the two into one 32-bit Int with bitwise operators.
Here is some example code that I already had written up:
Info by soja:
Here is the C++ prototype:
BOOL GetWindowInfo(
HWND hwnd, // handle to window
PWINDOWINFO pwi // window information
);
This means that the function returns a boolean value (which translates to an int% in Blitz). A handle-type variable (HWND - Window Handle) is effectively an int% in Blitz. And PWWINDOWINFO is a pointer to a window information struct, so in the decls it would be marked with '*'. (Pointers are always marked with '*' except when you want to pass the NULL pointer, in which case you have to mark it as '%' and pass 0.) Like so:
; .lib "user32.dll"
; GetWindowInfo%(hwnd%, pwi*):"GetWindowInfo"
Now if you go to MSDN, look up GetWindowInfo, and click on "WINDOWINFO" structure, it will tell you what fields it's compsed of. A C struct is very similar to a Blitz type. And in this case, we're in luck, becuase the struct does not have any strings (pointers to character arrays) in it, which means we can safely use a custom type object. (Otherwise we would have to use a bank.)
It turns out that all the parameters are full 32-bit types except for the last two, so all the fields save those two can be represented as ints%. The last two (ATOM and WORD) are both 16-bit structures, so we can combine the two into one 32-bit Int with bitwise operators.
Here is some example code that I already had written up:
; GetWindowInfo
; msdn.microsoft.com/library/default.asp?
; url=/library/en-us/winui/winui/windowsuserinterface/windowing
; /windows/windowreference/windowfunctions/getwindowinfo.asp
; .lib "user32.dll"
; GetWindowInfo%(hwnd%, pwi*):"GetWindowInfo"
Type WindowInfo
Field Size
Field leftWindow, topWindow, rightWindow, bottomWindow
Field leftClient, topClient, rightClient, bottomClient
Field Style
Field ExStyle
Field WindowStatus
Field xWindowBorders
Field yWindowBorders
Field WindowTypeAndCreatorVersion
End Type
; ----- Demo of GetWindowInfo -----
w = CreateWindow("Window", 100, 150, 100, 100, 0, 33)
b = CreateButton("Button", 10, 15, 50, 20, w)
Notify "Client Window Coords: " + ClientX(w) + ", " + ClientY(w)
Notify "Client Button Coords: " + ClientX(b) + ", " + ClientY(b)
CompleteGadgetInfo(w)
CompleteGadgetInfo(b)
End
; ---------------------------------
Function ClientX%(Gadget)
wi.WindowInfo = New WindowInfo
wi\Size = 60
If GetWindowInfo(QueryObject(Gadget,1), wi) Then
Return wi\leftClient
Else
Notify "ClientX() Failed"
Return -1 ; Failed
EndIf
End Function
Function ClientY%(Gadget)
wi.WindowInfo = New WindowInfo
wi\Size = 60
If GetWindowInfo(QueryObject(Gadget,1), wi) Then
Return wi\topClient
Else
Notify "ClientY() Failed"
Return -1 ; Failed
EndIf
End Function
Function CompleteGadgetInfo(Gadget)
wi.WindowInfo = New WindowInfo
wi\Size = 60
If GetWindowInfo(QueryObject(Gadget,1), wi) Then
Print "Window coords are ("+wi\leftWindow+","+wi\topWindow+") to ("+wi\rightWindow+","+wi\bottomWindow+")"
Print "Client coords are ("+wi\leftClient+","+wi\topClient+") to ("+wi\rightClient+","+wi\bottomClient+")"
Print "Style: " + wi\Style
Print "ExStyle: " + wi\ExStyle
Print "WindowStatus: " + wi\WindowStatus
Print "Size of Horizontal border: " + wi\xWindowBorders
Print "Size of Vertical border: " + wi\yWindowBorders
Print "Window Class Atom: " + wi\WindowTypeAndCreatorVersion Shr 16
Print "Version of Window Creator: " + (wi\WindowTypeAndCreatorVersion And $FFFF)
Else
Notify "Failed"
EndIf
End Function