Blitz+ userlibs
BlitzPlus Forums/BlitzPlus Programming/Blitz+ userlibs
| ||
- |
| ||
* window handle USER32: FindWindow, FindWindowEx, GetWindow, GetActiveWindow, GetForegroundWindow, etc, depending on what your situation is. * window x and y positions * window width and height USER32: GetWindowInfo Return scancodes (not ASCII) for key events whether the B+ application is in 'focus' or not See this thread (among others): win32api and getting hotkeys problem? ideas? soja, james, tracer? |
| ||
- |
| ||
Sure. 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 ; http://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 Hope this works out for you. If it doesn't make sense, I'll clarify some more. |
| ||
- |
| ||
GetForegroundWindow (user32) is just about as easy as it gets. |
| ||
- |
| ||
Blitz' internal gadget handles (including window handles) are not the same thing as Windows' window handles. So if you created a window in Blitz, and it was the foreground window, like this: wnd=CreateWindow("",10,10,100,100) ...then: wnd <> GetForegroundWindow() ...BUT QueryObject(wnd,1) == GetForegroundWindow() In other words, the QueryObject command gives you the Windows handle from the Blitz handle. What all this means is that you'll have a tough time expecting Blitz commands to work with Windows handles. But it looks like what you want to do is just get the coordinates and width/height, etc, of a Window. Look at the CompleteGadgetInfo function above, but instead of calling If GetWindowInfo(QueryObject(Gadget,1), wi) Then...call If GetWindowInfo(GetForegroundWindow(), wi) Then...instead. |
| ||
- |
| ||
I'm glad to help. |