Usual VB method is :
Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA"(ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByRef lpParam As Long) As Long
but what i found is awkward way with :
FUNCTION CreateWindowExA%& (BYVAL dwExStyle~&, BYVAL lpClassName%&, BYVAL lpWindowName%&, BYVAL dwStyle~&, BYVAL x&, BYVAL y&, BYVAL nWidth&, BYVAL nHeight&, BYVAL hWndParent%&, BYVAL hMenu%&, BYVAL hInstance%&, BYVAL lpParam%&)
03-22-2023, 02:26 PM (This post was last modified: 03-22-2023, 03:05 PM by SpriggsySpriggs.)
Here is the declaration I use and it works great:
Code: (Select All)
Declare CustomType Library
Function CreateWindowEx%& (ByVal dwExStyle As Unsigned Long, Byval lpClassName As Offset, Byval lpWindowName As Offset, Byval dwStyle As Unsigned Long, Byval x As Long, Byval y As Long, Byval nWidth As Long, Byval nHeight As Long, Byval hWndParent As Offset, Byval hMenu As Offset, Byval hInstance As Offset, Byval lpParam As Offset)
End Declare
You really only need to use the "A" suffix when calling directly from the DLL. If you use the header files instead, Windows will automatically select the "A" version. So you won't need CreateWindowExA in my declaration but you would if you pulled it from the DLL.
things go more weird when compiler exit with syntax error about parens (
and code is this :
Code: (Select All)
FUNCTION CreateWindowEx%& (ByVal dwExStyle As Long, Byref lpClassName As String, Byref lpWindowName As String, Byval dwStyle As Long, Byval x As Long, Byval y As Long, Byval nWidth As Long, Byval nHeight As Long, Byval hWndParent As Long, Byval hMenu As Long, Byval hInstance As Long, Byval lpParam As Long )
DECLARE LIBRARY "win"
FUNCTION GetWindowProc%& ()
END DECLARE
DECLARE DYNAMIC LIBRARY "user32"
FUNCTION SendMessageA%& (BYVAL hWnd%&, BYVAL Msg~&, BYVAL wParam~%&, BYVAL lParam%&)
FUNCTION DefWindowProcA%& (BYVAL hWnd%&, BYVAL Msg~&, BYVAL wParam~%&, BYVAL lParam%&)
SUB PostQuitMessage (BYVAL nExitCode&)
FUNCTION LoadCursorW%& (BYVAL hInstance%&, BYVAL lpCursorName%&)
FUNCTION RegisterClassA~% (BYVAL lpWndClass%&)
FUNCTION CreateWindowEx%& (ByVal dwExStyle As Long, byval lpClassName As _OFFSET,byval lpWindowName As _OFFSET, Byval dwStyle As Long, Byval x As Long, Byval y As Long, Byval nWidth As Long, Byval nHeight As Long, Byval hWndParent As Long, Byval hMenu As Long, Byval hInstance As Long, Byval lpParam As Long )
FUNCTION ShowWindow& (BYVAL hWnd%&, BYVAL nCmdShow&)
FUNCTION UpdateWindow& (BYVAL hWnd%&)
FUNCTION GetMessageA& (BYVAL lpMsg%&, BYVAL hWnd%&, BYVAL wMsgFilterMin~&, BYVAL wMsgFilterMax~&)
FUNCTION TranslateMessage& (BYVAL lpMsg%&)
FUNCTION DispatchMessageA%& (BYVAL lpmsg%&)
END DECLARE
DECLARE DYNAMIC LIBRARY "kernel32"
FUNCTION GetModuleHandleW%& (BYVAL lpModuleName%&)
'FUNCTION GetLastError~& ()
END DECLARE
TYPE POINT
x AS LONG
y AS LONG
END TYPE
' $IF 32BIT THEN
TYPE MSG
hwnd AS LONG
message AS LONG
wParam AS LONG 'unsigned pointer sized integer
lParam AS _OFFSET 'pointer sized integer
time AS LONG
pt AS POINT
END TYPE
TYPE WNDCLASSA
style AS LONG
lpfnWndProc AS _OFFSET
cbClsExtra AS LONG
cbWndExtra AS LONG
hInstance AS _OFFSET
hIcon AS _OFFSET
hCursor AS _OFFSET
hbrBackground AS _OFFSET
lpszMenuName AS _OFFSET
lpszClassName AS _OFFSET
END TYPE
DIM SHARED hi AS _OFFSET
DIM SHARED bRet AS LONG
DIM SHARED hw AS LONG
DIM SHARED hwb0 AS _OFFSET
DIM SHARED hwb1 AS _OFFSET
DIM SHARED hwcb AS _OFFSET
DIM SHARED hwgb AS _OFFSET
DIM SHARED hwr0 AS _OFFSET
DIM SHARED hwr1 AS _OFFSET
DIM SHARED hwe AS _OFFSET
DIM SHARED wc AS WNDCLASSA
DIM SHARED wmsg AS MSG
DIM SHARED at AS _UNSIGNED INTEGER
DIM SHARED buf AS STRING * 4096
'DIM SHARED discardb AS LONG
'DIM SHARED discardp AS _OFFSET
DIM SHARED t0 AS STRING
DIM SHARED t1 AS STRING
DIM SHARED ClassName AS STRING
ClassName = "QB64pe" + CHR$(0)
'DIM SHARED crlf AS STRING * 2
'crlf = MKI$(&HA0D)
03-22-2023, 08:05 PM (This post was last modified: 03-22-2023, 08:11 PM by SpriggsySpriggs.)
It looks like this is because you defined "hw" as LONG but CreateWindowEx returns an OFFSET. Make sure all your handles are OFFSETs.
As for the underscore vs not.... I usually code with $NOPREFIX turned on and I just copied and pasted from code I had opened. Oops. Also, your declaration for CreateWindowEx has some variable type mismatches. Copy the declaration I gave you (but fix the underscores) and also replace DECLARE DYNAMIC LIBRARY "user32" in your code with DECLARE CUSTOMTYPE LIBRARY. Otherwise, you're going to need the "A" at the end of CreateWindowEx. If you don't change either the library declaration or the name of the function, then you will hit a runtime error saying that function doesn't exist in the library.
(03-22-2023, 08:13 PM)aurel Wrote: all handles must be _OFFSET ..why ..in other windows compilers there are INTEGER or LONG
why is in QB64 pointer?
It was a half-successful attempt to ease the life of the programmer moving from 32-bit to 64-bit. A pointer isn't supposed to be dictated by what's its size. Remember that _OFFSET and _MEM are necessary in QB64(PE) because otherwise it would have to look like Freebasic or Purebasic which, in turn, look the most like C and C++.
I guess in this case use ConvertOffset&&() function that Steve wrote and is in QB64 Wiki. But that returns _INTEGER64 and not INTEGER or LONG. INTEGER is always 16-bit integer in QuickBASIC and descendants, shouldn't be discussed any longer in systems programming.
03-22-2023, 08:34 PM (This post was last modified: 03-22-2023, 08:35 PM by SpriggsySpriggs.)
A HANDLE is a long pointer. In QB64, our equivalent is an OFFSET. A long pointer is 4 bytes in 32 bit and 8 in 64. In QB64, an OFFSET is 4 bytes in 32 bit and 8 in 64. It's our closest approximation. As for the class name with the "at AND &HFFFF~&", I'm not sure where they would have gotten that value for their class. Very odd. I've not seen something like that before. If I were you, I'd instead use the actual name of the class and keep the declaration with OFFSET. It looks like you defined it as "QB64pe". So just pass it as _OFFSET(ClassName) in your call there rather than that weird "at AND &HFFFF~&".