Posts: 730
Threads: 30
Joined: Apr 2022
Reputation:
43
03-23-2023, 07:33 PM
(This post was last modified: 03-23-2023, 08:17 PM by SpriggsySpriggs.)
Here's the zip archive of the repo I had for my Win32 Video Player. You can look through the files and make a decision from there. If you want to compile it and play around with it, you need to use 64 bit QB64. However, there is also a precompiled executable included in the archive. All the headers are in Resources\Headers. All the code for the window is in the main bas file in the root folder. Any includes are in Resources\Includes. All the TYPEs and logic has been used in multiple projects with success each and every time. This is the result of much trouble and toil, trial and error. I can't guarantee how readable some of the code will be but the important stuff should all be recognizable to you. Just look for the functions and TYPEs you're trying to use and you'll most likely find them being used in that program. Since this is an archive of a repo I am no longer updating, there could be some code in there that I have, in fact, declared incorrectly. However, if you use the MSDN and the QB64 Wiki, you should be completely fine.
QB64-Win32-Video-Player-master.zip (Size: 6.12 MB / Downloads: 23)
Libraries - QB64 Phoenix Edition Wiki
Windows Libraries - QB64 Phoenix Edition Wiki
Windows Data Types (BaseTsd.h) - Win32 apps | Microsoft Learn
A GIF of the program in action:
Good luck.
Vince and KiloManjaro can provide you with more assistance.
Tread on those who tread on you
Posts: 1,581
Threads: 59
Joined: Jul 2022
Reputation:
52
aurel are you using 32-bit QB64(PE)? If so then you're waging a losing battle. At least QB64PE is steadily becoming 64-bit only which many people don't like, myself included, but when someone else offers code that works only on 64-bit then, well...
Might have to do this project instead in Purebasic v4.x which has the "real star" pointer type and in some cases allows an "ordinary" integer type used as fake pointer. Like from the Purebasic Code Archive I saw a lot of examples of "dot-i" variables taking in addresses, and it had to be coded that way (ie. "addres.i" instead of "*addres") or that moody compiler flagged an error. The trap about this is that it was assumed a pointer is like an integer in which the compiler has to know what is the size, such as in QB64(PE) "LONG" is always 32-bit. Maybe that's why the authors of Purebasic were forced to create the "real star". Certainly they did a lot of things in Win32 API and wanted to get as close as they could without actually using C and C++.
I don't know if the "dot-i" notation could still be used in later versions of Purebasic because the latest version which was stable that I used was v4.6 some years back. Also had v5.21 LTS but the editor was very buggy and the whole thing was becoming unusable. It was good only for that XML hacking for fancy dialogs. Otherwise v4.6 was super and I even downloaded somebody else's work for ZIP file support which worked well. Of course this was before QB64 had anything like that.
Posts: 301
Threads: 16
Joined: Apr 2022
Reputation:
51
Couldn't agree more @mnrvovrfc , purebasic would be a far more appropriate language for working with pointers and external libraries.
Btw, @mnrvovrfc , you seem to be fairly active here and are always quick to deliver insightful responses, ever considered joining us on Discord for a more opinionated conversational style of discussion?
Posts: 296
Threads: 10
Joined: Apr 2022
Reputation:
6
03-23-2023, 08:25 PM
(This post was last modified: 03-23-2023, 08:26 PM by aurel.)
Ok boys ..don't need to panic
for sure there are quirks in qb64 which are not created in VB style as i use
for example in OxygenBasic ..which is by the way better than Purebasic in some things
( it is even closer to C and even MORE BASIC than PureBasic ( i have PureBasic v4,5))
and work extremly well with external library .. i know that i use it 10 years
i made almost complete include for GUI apps in Oxygenbasic ...
but we are here in QB64 pe...
this example show strange thing
after proper compilation ...i use this time WNDCLASSEX not older WNDCLASSA
and do you know what i get - message Box with Crytical Error
Sub/Function is not in Dynamic Library ...CreateWindowEx()
so it looks that i need to use Zak method:
Code: (Select All) 'test 1 GUI win32 api in QB64pe v3.2.1 by Aurel
$SCREENHIDE
CONST IDC_ARROW = &H7F00
CONST COLOR_WINDOW = 5
CONST WS_OVERLAPPED = 0
CONST WS_CHILD = &H40000000
CONST WS_VISIBLE = &H10000000
CONST WS_MAXIMIZE = &H01000000
CONST WS_CAPTION = &H00C00000
CONST WS_VSCROLL = &H00200000
CONST WS_HSCROLL = &H00100000
CONST WS_SYSMENU = &H00080000
CONST WS_THICKFRAME = &H00040000
CONST WS_TABSTOP = &H00010000
CONST WS_MINIMIZEBOX = &H00020000
CONST WS_MAXIMIZEBOX = &H00010000
CONST WS_OVERLAPPEDWINDOW = WS_VISIBLE OR WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
CONST CW_USEDEFAULT = &H80000000
CONST CS_DBLCLKS = &H8
CONST CS_OWNDC = 32
CONST IDI_APPLICATION = 32512
CONST BS_PUSHBUTTON = 0
CONST BS_AUTOCHECKBOX = 3
CONST BS_GROUPBOX = 7
CONST BS_AUTORADIOBUTTON = 9
CONST BS_TEXT = 0
CONST BN_CLICKED = 0
CONST BM_GETCHECK = &HF0
CONST ES_LEFT = 0
CONST ES_MULTILINE = 4
CONST ES_AUTOVSCROLL = &H0040
CONST ES_AUTOHSCROLL = &H0080
CONST ES_WANTRETURN = &H1000
CONST WM_DESTROY = 2
CONST WM_GETTEXT = &H000D
CONST WM_CLOSE = &H0010
CONST WM_COMMAND = &H0111
CONST SW_SHOWDEFAULT = &HA
CONST SW_SHOW = 5
'------------------------------------------------
TYPE POINT
x AS LONG
y AS LONG
END TYPE
' for 64 bit
TYPE MSG
hwnd AS _OFFSET
message AS _OFFSET
wParam AS _UNSIGNED _OFFSET 'unsigned pointer sized integer
lParam AS _OFFSET 'pointer sized integer
time AS _INTEGER64
pt AS POINT
END TYPE
'should be before Library Declarations
TYPE WNDCLASSEX
cbSize As _INTEGER64
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
hIconSm As _OFFSET
END TYPE
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 LoadIcon%& (ByVal hinstance As Long, ByVal lpIconName As long)
'FUNCTION RegisterClassA~% (BYVAL lpWndClass%&)
FUNCTION RegisterClassExA~% (byval pcWndClassEx%&)
'FUNCTION CreateWindowEx%& (ByVal dwExStyle As Long, byval lpClassName%&, byval lpWindowName%&, 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 _OFFSET, Byval lpParam As Long )
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%&)
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 GetModuleHandleA%& (BYVAL lpModuleName%&)
'FUNCTION GetLastError~& ()
END DECLARE
'TYPE WNDCLASSA
' style AS _INTEGER64
' 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 _offset
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 wcx AS WNDCLASSEX
DIM SHARED wmsg AS MSG
DIM SHARED reg AS _UNSIGNED INTEGER
DIM SHARED buf AS STRING * 4096
DIM SHARED sw AS LONG
DIM SHARED uw AS _OFFSET
DIM SHARED t0 AS STRING
DIM SHARED t1 AS STRING
DIM SHARED ClassName AS STRING
ClassName = "QB64pe"
'DIM SHARED crlf AS STRING * 2
'crlf = MKI$(&HA0D)
hi = GetModuleHandleA(0)
wcx.cbsize = 76
wcx.style = CS_DBLCLKS OR CS_OWNDC
wcx.lpfnWndProc = GetWindowProc
wcx.cbClsExtra = 0
wcx.cbWndExtra = 0
wcx.hInstance = hi
wcx.hIcon = 0
wcx.hCursor = LoadCursorW(0, IDC_ARROW)
wcx.hbrBackground = COLOR_WINDOW + 1
wcx.lpszMenuName = 0
wcx.lpszClassName = _OFFSET(ClassName)
wcx.hIconSm = LoadIcon(0,IDI_APPLICATION )
'-----------------------------------------------------------
reg = RegisterClassExA(_OFFSET(wcx)): IF 0 = reg THEN SYSTEM
'-------------------------------------------------------------
'create main window
t1 = "QB64pe_GUI_App2"
hw = CreateWindowExA(0, _OFFSET(ClassName), _OFFSET(t1), WS_OVERLAPPEDWINDOW , 200, 200, 800, 600, 0, 0, hi, 0)
IF 0 = hw THEN SYSTEM
sw = ShowWindow(hw, SW_SHOW)
sw = UpdateWindow(hw)
'win message loop..................................
DO
bRet = GetMessageA(_OFFSET(wmsg), 0, 0, 0)
SELECT CASE bRet
CASE 0, -1: EXIT DO
END SELECT
sw = TranslateMessage(_OFFSET(wmsg))
uw = DispatchMessageA(_OFFSET(wmsg))
'wend
LOOP
'..................................................
FUNCTION WindowProc%& (hWnd AS _OFFSET, uMsg AS _UNSIGNED LONG, wParam AS _UNSIGNED _OFFSET, lParam AS _OFFSET)
SELECT CASE uMsg
CASE WM_DESTROY
PostQuitMessage(0)
' WindowProc=0 : EXIT FUNCTION
CASE ELSE
WindowProc = DefWindowProcA(hWnd, uMsg, wParam, lParam)
END SELECT
'WindowProc = DefWindowProcA(hWnd, uMsg, wParam, lParam)
END FUNCTION
Posts: 1,581
Threads: 59
Joined: Jul 2022
Reputation:
52
(03-23-2023, 08:07 PM)vince Wrote: Btw, @mnrvovrfc , you seem to be fairly active here and are always quick to deliver insightful responses, ever considered joining us on Discord for a more opinionated conversational style of discussion?
You and bplus sometimes make me feel very small with your code contributions. :O
I cannot have an account with Discord unless I have a phone on me. I have accepted Steve's invitation from this forum but what I've just said is the only barrier.
I really miss Pete around here. He was more insightful than me. I might not be active for much longer. Either Internet or portable phone, I cannot have both.
Posts: 296
Threads: 10
Joined: Apr 2022
Reputation:
6
funny thing..if i use Zak way with CUSTOMTYPE then i get ILLEGAL SUB/FUNCTION declaration error
Code: (Select All) Declare customType Library
Function CreateWindowEx%& (ByVal dwExStyle~&, Byval lpClassName As Offset, Byval lpWindowName As Offset, Byval dwStyle~&, 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
Posts: 301
Threads: 16
Joined: Apr 2022
Reputation:
51
(03-23-2023, 08:41 PM)mnrvovrfc Wrote: (03-23-2023, 08:07 PM)vince Wrote: Btw, @mnrvovrfc , you seem to be fairly active here and are always quick to deliver insightful responses, ever considered joining us on Discord for a more opinionated conversational style of discussion?
You and bplus sometimes make me feel very small with your code contributions. :O
I cannot have an account with Discord unless I have a phone on me. I have accepted Steve's invitation from this forum but what I've just said is the only barrier.
I really miss Pete around here. He was more insightful than me. I might not be active for much longer. Either Internet or portable phone, I cannot have both.
Alright, I never needed to phone verify my account but maybe things have changed. No reason to feel small, though, because you throw away your credibility by being vulnerable, and if you're not, you have nothing to worry about
Posts: 296
Threads: 10
Joined: Apr 2022
Reputation:
6
So Zak ...
why is your declaration ILLEGAL ?
Posts: 296
Threads: 10
Joined: Apr 2022
Reputation:
6
And here is complete code with your declaration for CreateWindowEx ( )
Code: (Select All) 'test 1 GUI win32 api in QB64pe v3.2.1 by Aurel
$SCREENHIDE
CONST IDC_ARROW = &H7F00
CONST COLOR_WINDOW = 5
CONST WS_OVERLAPPED = 0
CONST WS_CHILD = &H40000000
CONST WS_VISIBLE = &H10000000
CONST WS_MAXIMIZE = &H01000000
CONST WS_CAPTION = &H00C00000
CONST WS_VSCROLL = &H00200000
CONST WS_HSCROLL = &H00100000
CONST WS_SYSMENU = &H00080000
CONST WS_THICKFRAME = &H00040000
CONST WS_TABSTOP = &H00010000
CONST WS_MINIMIZEBOX = &H00020000
CONST WS_MAXIMIZEBOX = &H00010000
CONST WS_OVERLAPPEDWINDOW = WS_VISIBLE OR WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX
CONST CW_USEDEFAULT = &H80000000
CONST CS_DBLCLKS = &H8
CONST CS_OWNDC = 32
CONST IDI_APPLICATION = 32512
CONST BS_PUSHBUTTON = 0
CONST BS_AUTOCHECKBOX = 3
CONST BS_GROUPBOX = 7
CONST BS_AUTORADIOBUTTON = 9
CONST BS_TEXT = 0
CONST BN_CLICKED = 0
CONST BM_GETCHECK = &HF0
CONST ES_LEFT = 0
CONST ES_MULTILINE = 4
CONST ES_AUTOVSCROLL = &H0040
CONST ES_AUTOHSCROLL = &H0080
CONST ES_WANTRETURN = &H1000
CONST WM_DESTROY = 2
CONST WM_GETTEXT = &H000D
CONST WM_CLOSE = &H0010
CONST WM_COMMAND = &H0111
CONST SW_SHOWDEFAULT = &HA
CONST SW_SHOW = 5
'------------------------------------------------
TYPE POINT
x AS LONG
y AS LONG
END TYPE
' for 64 bit
TYPE MSG
hwnd AS _OFFSET
message AS _OFFSET
wParam AS _UNSIGNED _OFFSET 'unsigned pointer sized integer
lParam AS _OFFSET 'pointer sized integer
time AS _INTEGER64
pt AS POINT
END TYPE
'should be before Library Declarations
TYPE WNDCLASSEX
cbSize As _INTEGER64
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
hIconSm As _OFFSET
END TYPE
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 LoadIcon%& (ByVal hinstance As Long, ByVal lpIconName As long)
'FUNCTION RegisterClassA~% (BYVAL lpWndClass%&)
FUNCTION RegisterClassExA~% (byval pcWndClassEx%&)
'FUNCTION CreateWindowEx%& (ByVal dwExStyle As Long, byval lpClassName%&, byval lpWindowName%&, 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 _OFFSET, Byval lpParam As Long )
'FUNCTION CreateWindowEx%& (BYVAL dwExStyle~&, BYVAL lpClassName%&, BYVAL lpWindowName%&, BYVAL dwStyle~&, BYVAL x&, BYVAL y&, BYVAL nWidth&, BYVAL nHeight&, BYVAL hWndParent%&, BYVAL hMenu%&, BYVAL hInstance%&, BYVAL lpParam%&)
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 customType Library
Function CreateWindowEx%& (ByVal dwExStyle~&, Byval lpClassName As Offset, Byval lpWindowName As Offset, Byval dwStyle~&, 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
DECLARE DYNAMIC LIBRARY "kernel32"
FUNCTION GetModuleHandleA%& (BYVAL lpModuleName%&)
'FUNCTION GetLastError~& ()
END DECLARE
'TYPE WNDCLASSA
' style AS _INTEGER64
' 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 _offset
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 wcx AS WNDCLASSEX
DIM SHARED wmsg AS MSG
DIM SHARED reg AS _UNSIGNED INTEGER
DIM SHARED buf AS STRING * 4096
DIM SHARED sw AS LONG
DIM SHARED uw AS _OFFSET
DIM SHARED t0 AS STRING
DIM SHARED t1 AS STRING
DIM SHARED ClassName AS STRING
ClassName = "QB64pe"
'DIM SHARED crlf AS STRING * 2
'crlf = MKI$(&HA0D)
hi = GetModuleHandleA(0)
wcx.cbsize = 76
wcx.style = CS_DBLCLKS OR CS_OWNDC
wcx.lpfnWndProc = GetWindowProc
wcx.cbClsExtra = 0
wcx.cbWndExtra = 0
wcx.hInstance = hi
wcx.hIcon = 0
wcx.hCursor = LoadCursorW(0, IDC_ARROW)
wcx.hbrBackground = COLOR_WINDOW + 1
wcx.lpszMenuName = 0
wcx.lpszClassName = _OFFSET(ClassName)
wcx.hIconSm = LoadIcon(0,IDI_APPLICATION )
'-----------------------------------------------------------
reg = RegisterClassExA(_OFFSET(wcx)): IF 0 = reg THEN SYSTEM
'-------------------------------------------------------------
'create main window
t1 = "QB64pe_GUI_App2"
hw = CreateWindowEx(0, _OFFSET(ClassName), _OFFSET(t1), WS_OVERLAPPEDWINDOW , 200, 200, 800, 600, 0, 0, hi, 0)
IF 0 = hw THEN SYSTEM
sw = ShowWindow(hw, SW_SHOW)
sw = UpdateWindow(hw)
'win message loop..................................
DO
bRet = GetMessageA(_OFFSET(wmsg), 0, 0, 0)
SELECT CASE bRet
CASE 0, -1: EXIT DO
END SELECT
sw = TranslateMessage(_OFFSET(wmsg))
uw = DispatchMessageA(_OFFSET(wmsg))
'wend
LOOP
'..................................................
FUNCTION WindowProc%& (hWnd AS _OFFSET, uMsg AS _UNSIGNED LONG, wParam AS _UNSIGNED _OFFSET, lParam AS _OFFSET)
SELECT CASE uMsg
CASE WM_DESTROY
PostQuitMessage(0)
' WindowProc=0 : EXIT FUNCTION
CASE ELSE
WindowProc = DefWindowProcA(hWnd, uMsg, wParam, lParam)
END SELECT
'WindowProc = DefWindowProcA(hWnd, uMsg, wParam, lParam)
END FUNCTION
Posts: 730
Threads: 30
Joined: Apr 2022
Reputation:
43
(03-23-2023, 08:41 PM)aurel Wrote: funny thing..if i use Zak way with CUSTOMTYPE then i get ILLEGAL SUB/FUNCTION declaration error
Code: (Select All) Declare customType Library
Function CreateWindowEx%& (ByVal dwExStyle~&, Byval lpClassName As Offset, Byval lpWindowName As Offset, Byval dwStyle~&, 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
Remember, I mentioned that you would have to add the underscores back to OFFSET because I use $NOPREFIX.
Tread on those who tread on you
|