Lionheart008
16-01-2010, 16:37
I have a simple question if it's possible to create with "thinbasic" own board power a simple "hello window" (sdk) like petzold did or Charles Pegge with oxygen at this board some month ago ? Charles said this was really "... hardcore stuff" :)
link: http://community.thinbasic.com/index.php?topic=1859.0
I have made the job to collect some files (not complete!) and this example doesn't work, but it's perhaps a start for anybody here with more knowledge for this topic and check the possibility to create this kind of window / ui ?
' Empty GUI script created on 01-16-2010 15:18:58 by frank (ThinAIR)
'--------------thinbasic sdk window like petzold did it ;)
'---------------------------------------------------------------------
Uses "console", "ui"
%CS_HREDRAW = 1001
%CS_VREDRAW = 1002
%IDC_ARROW = 32512
'%IDI_APPLICATION = 32512
%TRANSPARENT = 1006
%WHITE_BRUSH = 1003
Type SECURITY_ATTRIBUTES
nLength As DWord
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Type POINTS
x As Integer
y As Integer
End Type
Type tagMSG
hwnd As DWord
message As DWord
wParam As Long
lParam As Long
time As DWord
pt As POINTAPI
End Type
Type WNDCLASSEX
cbSize As DWord
STYLE As DWord
lpfnWndProc As Long
cbClsExtra As Long
cbWndExtra As Long
hInstance As DWord
hIcon As DWord
hCursor As DWord
hbrBackground As DWord
lpszMenuName As Asciiz Ptr
lpszClassName As Asciiz Ptr
hIconSm As DWord
End Type
Type WNDCLASS
STYLE As DWord
lpfnwndproc As DWord
cbClsextra As Long
cbWndExtra As Long
hInstance As DWord
hIcon As DWord
hCursor As DWord
hbrBackground As DWord
lpszMenuName As Asciiz Ptr
lpszClassName As Asciiz Ptr
End Type
Type RECT
nLeft As Long
nTop As Long
nRight As Long
nBottom As Long
End Type
Declare Function FillRect Lib "USER32.DLL" Alias "FillRect" (ByVal hDC As DWord, lpRect As RECT, ByVal hBrush As DWord) As Long
Declare Function CreateWindowStation Lib "USER32.DLL" Alias "CreateWindowStationA" (lpszwinsta As Asciiz, ByVal dwReserved As DWord, ByVal dwDesiredAccess As DWord, lpsa As SECURITY_ATTRIBUTES) As DWord
Declare Function CreateWindowEx Lib "USER32.DLL" Alias "CreateWindowExA" (ByVal dwExStyle As DWord, lpClassName As Asciiz, lpWindowName As Asciiz, ByVal dwStyle As DWord, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As DWord, ByVal hMenu As DWord, ByVal hInstance As DWord, lpParam As Any) As DWord
Declare Function SetRect Lib "USER32.DLL" Alias "SetRect" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function CreateSolidBrush Lib "GDI32.DLL" Alias "CreateSolidBrush" (ByVal crColor As DWord) As DWord
Declare Function DeleteObject Lib "GDI32.DLL" Alias "DeleteObject" (ByVal hObject As DWord) As Long
Declare Function BeginPaint Lib "USER32.DLL" Alias "BeginPaint" (ByVal hWnd As DWord, lpPaint As PAINTSTRUCT) As Long
Declare Function SetBkMode Lib "GDI32.DLL" Alias "SetBkMode" (ByVal hdc As DWord, ByVal nBkMode As Long) As Long
Declare Function SetTextColor Lib "GDI32.DLL" Alias "SetTextColor" (ByVal hdc As DWord, ByVal crColor As DWord) As DWord
Declare Function DrawText Lib "USER32.DLL" Alias "DrawTextA" (ByVal hDC As DWord, lpStr As Asciiz, ByVal nCount As Long, lpRect As RECT, ByVal uFormat As DWord) As Long
Declare Function EndPaint Lib "USER32.DLL" Alias "EndPaint" (ByVal hWnd As DWord, lpPaint As PAINTSTRUCT) As Long
Declare Sub PostQuitMessage Lib "USER32.DLL" Alias "PostQuitMessage" (ByVal nExitCode As Long)
Declare Function DefWindowProc Lib "USER32.DLL" Alias "DefWindowProcA" (ByVal hWnd As DWord, ByVal uMsg As DWord, ByVal wParam As DWord, ByVal lParam As Long) As Long
Declare Function LoadIcon Lib "USER32.DLL" Alias "LoadIconA" (ByVal hInstance As DWord, lpIconName As Asciiz) As DWord
Declare Function LoadBitmap Lib "USER32.DLL" Alias "LoadBitmapA" (ByVal hInstance As DWord, lpBitmapName As Asciiz) As DWord
Declare Function LoadCursor Lib "USER32.DLL" Alias "LoadCursorA" (ByVal hInstance As DWord, lpCursorName As Asciiz) As DWord
Declare Function RegisterClass Lib "USER32.DLL" Alias "RegisterClassA" (pcWndClass As WNDCLASS) As Word
Declare Function RegisterClassEx Lib "USER32.DLL" Alias "RegisterClassExA" (pcWndClassEx As WNDCLASSEX) As Word
Declare Function CreateWindow Lib "USER32.DLL" Alias "CreateWindowA" (lpClassName As Asciiz, lpWindowName As Asciiz, ByVal dwStyle As DWord, ByVal xx As Long, ByVal yy As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hwndParent As DWord, ByVal hMenu As DWord, ByVal hInstance As DWord, ByVal lpParam As DWord) As Long
Declare Function ShowWindow Lib "USER32.DLL" Alias "ShowWindow" (ByVal hWnd As DWord, ByVal nCmdShow As Long) As Long
Declare Function UpdateWindow Lib "USER32.DLL" Alias "UpdateWindow" (ByVal hWnd As DWord) As Long
'Declare Function GetMessage Lib "USER32.DLL" Alias "GetMessageA" (byval lpMsg As tagMSG, ByVal hWnd As DWord, ByVal uMsgFilterMin As DWord, ByVal uMsgFilterMax As DWord) As Long
Declare Function TranslateMessage Lib "USER32.DLL" Alias "TranslateMessage" (lpMsg As tagMSG) As Long
Declare Function DispatchMessage Lib "USER32.DLL" Alias "DispatchMessageA" (lpMsg As tagMSG) As Long
Declare Function GetClientRect Lib "USER32.DLL" Alias "GetClientRect" (ByVal hwnd As DWord, lpRect As RECT) As Long
Declare Function WindowFromDC Lib "USER32.DLL" Alias "WindowFromDC" (ByVal hDC As DWord) As Long
'==============================================================================
Function WINMAIN (ByVal hInstance As DWord, _
ByVal hPrevInstance As DWord, _
ByVal lpCmdLine As Asciiz, _ 'PTR
ByVal iCmdShow As Long) As Long
'------------------------------------------------------------------------------
' Program entry point
'--------------------------------------------------------------------------
Local Msg As tagMsg
Local wce As WndClassEx
Local szAppName As Asciiz * 80
Local hWnd As DWord
' Setup and register a window class for the main window
' CODEPTR is used to pass the address of the function that will
' receive all messages sent to any window created with this class
szAppName = "HelloWin"
wce.cbSize = SizeOf(wce)
wce.STYLE = %CS_HREDRAW Or %CS_VREDRAW
wce.lpfnWndProc = CODEPTR(WndProc)
wce.cbClsExtra = 0
wce.cbWndExtra = 0
wce.hInstance = hInstance
wce.hIcon = LoadIcon(hInstance, "HELLOWIN")
wce.hCursor = LoadCursor(%NULL, ByVal %IDC_ARROW)
wce.hbrBackground = %NULL ' No class background, we do it outselves
wce.lpszMenuName = %NULL
wce.lpszClassName = VarPtr(szAppName)
wce.hIconSm = LoadIcon(hInstance, ByVal %IDI_APPLICATION)
RegisterClassEx wce
' Create a window using the registered class
hWnd = CreateWindow(szAppName, _ ' window class name
"The Hello Program", _ ' window caption
%WS_OVERLAPPEDWINDOW, _ ' window style
%CW_USEDEFAULT, _ ' initial x position
%CW_USEDEFAULT, _ ' initial y position
%CW_USEDEFAULT, _ ' initial x size
%CW_USEDEFAULT, _ ' initial y size
%NULL, _ ' parent window handle
%NULL, _ ' window menu handle
hInstance, _ ' program instance handle
ByVal %NULL) ' creation parameters
If hWnd = 0 Then ' exit on failure
MsgBox "Unable to create window"
Exit Function
End If
' Display the window on the screen
ShowWindow hWnd, iCmdShow
UpdateWindow hWnd
' Main message loop:
' Messages sent to HELLOWIN while it has the focus are received by
' GetMessage(). This loop translates each message and dispatches it
' to the appropriate handler. When PostQuitMessage() is called, the
' loop terminates which ends the application.
Do While GetMessage(Msg, %NULL, 0, 0)
TranslateMessage Msg
DispatchMessage Msg
Loop
Function = msg.wParam
End Function
'==============================================================================
Sub DrawGradient (ByVal hDC As DWord)
'------------------------------------------------------------------------------
' Custom draw procedure for gradiend fill
'--------------------------------------------------------------------------
Local rectFill As RECT
Local rectClient As RECT
Local fStep As Single
Local hBrush As DWord
Local lOnBand As Long
GetClientRect WindowFromDC(hDC), rectClient
fStep = rectClient.nbottom / 200
For lOnBand = 0 To 199
SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
hBrush = CreateSolidBrush(Rgb(0, 0, 255 - lOnBand))
Fillrect hDC, rectFill, hBrush
DeleteObject hBrush
Next
End Sub
'==============================================================================
Function WndProc (ByVal hWnd As DWord, ByVal wMsg As DWord, _
ByVal wParam As DWord, ByVal lParam As Long) Export As Long
'------------------------------------------------------------------------------
' WndProc is the message handler for all windows creating using the HelloWin
' class name. A single WndProc procedure can handle multiple windows by
' testing the hWnd variable passed to it.
'--------------------------------------------------------------------------
Local hDC As DWord
Local pPaint As PAINTSTRUCT
Local tRect As RECT
' The SELECT CASE is used to catch only those messages which the message
' handler needs to process. All other messages are passed through the
' tests to the default handler.
Select Case wMsg
Case %WM_CREATE
Case %WM_PAINT
hDC = BeginPaint(hWnd, pPaint)
GetClientRect hWnd, tRect
SetBkMode hDC, %TRANSPARENT
SetTextColor hDC, %WHITE
DrawText hDC, "Hello, Windows!", -1, tRect, %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER
EndPaint hWnd, pPaint
Function = 1
Exit Function
Case %WM_ERASEBKGND
hDC = wParam
DrawGradient hDC ' Pass the DC of the region to repaint
Function = 1
Exit Function
Case %WM_DESTROY
PostQuitMessage 0
Exit Function
End Select
' Any message which is not handled in the above SELECT CASE reaches this
' point and is processed by the Windows default message handler.
Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
End Function
MsgBox 0, "just a test for sdk window!"
I needed only one hour to collect all files they are important for making sdk window, I am thinking there is still 10 per Cent (in my eyes) missing to fulfil this task to create this window, it was just an idea to do this work around I have made from powerbasic example. So why we can't go similar way of doing ? ;)
best regards, frank
link: http://community.thinbasic.com/index.php?topic=1859.0
I have made the job to collect some files (not complete!) and this example doesn't work, but it's perhaps a start for anybody here with more knowledge for this topic and check the possibility to create this kind of window / ui ?
' Empty GUI script created on 01-16-2010 15:18:58 by frank (ThinAIR)
'--------------thinbasic sdk window like petzold did it ;)
'---------------------------------------------------------------------
Uses "console", "ui"
%CS_HREDRAW = 1001
%CS_VREDRAW = 1002
%IDC_ARROW = 32512
'%IDI_APPLICATION = 32512
%TRANSPARENT = 1006
%WHITE_BRUSH = 1003
Type SECURITY_ATTRIBUTES
nLength As DWord
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Type POINTS
x As Integer
y As Integer
End Type
Type tagMSG
hwnd As DWord
message As DWord
wParam As Long
lParam As Long
time As DWord
pt As POINTAPI
End Type
Type WNDCLASSEX
cbSize As DWord
STYLE As DWord
lpfnWndProc As Long
cbClsExtra As Long
cbWndExtra As Long
hInstance As DWord
hIcon As DWord
hCursor As DWord
hbrBackground As DWord
lpszMenuName As Asciiz Ptr
lpszClassName As Asciiz Ptr
hIconSm As DWord
End Type
Type WNDCLASS
STYLE As DWord
lpfnwndproc As DWord
cbClsextra As Long
cbWndExtra As Long
hInstance As DWord
hIcon As DWord
hCursor As DWord
hbrBackground As DWord
lpszMenuName As Asciiz Ptr
lpszClassName As Asciiz Ptr
End Type
Type RECT
nLeft As Long
nTop As Long
nRight As Long
nBottom As Long
End Type
Declare Function FillRect Lib "USER32.DLL" Alias "FillRect" (ByVal hDC As DWord, lpRect As RECT, ByVal hBrush As DWord) As Long
Declare Function CreateWindowStation Lib "USER32.DLL" Alias "CreateWindowStationA" (lpszwinsta As Asciiz, ByVal dwReserved As DWord, ByVal dwDesiredAccess As DWord, lpsa As SECURITY_ATTRIBUTES) As DWord
Declare Function CreateWindowEx Lib "USER32.DLL" Alias "CreateWindowExA" (ByVal dwExStyle As DWord, lpClassName As Asciiz, lpWindowName As Asciiz, ByVal dwStyle As DWord, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As DWord, ByVal hMenu As DWord, ByVal hInstance As DWord, lpParam As Any) As DWord
Declare Function SetRect Lib "USER32.DLL" Alias "SetRect" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function CreateSolidBrush Lib "GDI32.DLL" Alias "CreateSolidBrush" (ByVal crColor As DWord) As DWord
Declare Function DeleteObject Lib "GDI32.DLL" Alias "DeleteObject" (ByVal hObject As DWord) As Long
Declare Function BeginPaint Lib "USER32.DLL" Alias "BeginPaint" (ByVal hWnd As DWord, lpPaint As PAINTSTRUCT) As Long
Declare Function SetBkMode Lib "GDI32.DLL" Alias "SetBkMode" (ByVal hdc As DWord, ByVal nBkMode As Long) As Long
Declare Function SetTextColor Lib "GDI32.DLL" Alias "SetTextColor" (ByVal hdc As DWord, ByVal crColor As DWord) As DWord
Declare Function DrawText Lib "USER32.DLL" Alias "DrawTextA" (ByVal hDC As DWord, lpStr As Asciiz, ByVal nCount As Long, lpRect As RECT, ByVal uFormat As DWord) As Long
Declare Function EndPaint Lib "USER32.DLL" Alias "EndPaint" (ByVal hWnd As DWord, lpPaint As PAINTSTRUCT) As Long
Declare Sub PostQuitMessage Lib "USER32.DLL" Alias "PostQuitMessage" (ByVal nExitCode As Long)
Declare Function DefWindowProc Lib "USER32.DLL" Alias "DefWindowProcA" (ByVal hWnd As DWord, ByVal uMsg As DWord, ByVal wParam As DWord, ByVal lParam As Long) As Long
Declare Function LoadIcon Lib "USER32.DLL" Alias "LoadIconA" (ByVal hInstance As DWord, lpIconName As Asciiz) As DWord
Declare Function LoadBitmap Lib "USER32.DLL" Alias "LoadBitmapA" (ByVal hInstance As DWord, lpBitmapName As Asciiz) As DWord
Declare Function LoadCursor Lib "USER32.DLL" Alias "LoadCursorA" (ByVal hInstance As DWord, lpCursorName As Asciiz) As DWord
Declare Function RegisterClass Lib "USER32.DLL" Alias "RegisterClassA" (pcWndClass As WNDCLASS) As Word
Declare Function RegisterClassEx Lib "USER32.DLL" Alias "RegisterClassExA" (pcWndClassEx As WNDCLASSEX) As Word
Declare Function CreateWindow Lib "USER32.DLL" Alias "CreateWindowA" (lpClassName As Asciiz, lpWindowName As Asciiz, ByVal dwStyle As DWord, ByVal xx As Long, ByVal yy As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hwndParent As DWord, ByVal hMenu As DWord, ByVal hInstance As DWord, ByVal lpParam As DWord) As Long
Declare Function ShowWindow Lib "USER32.DLL" Alias "ShowWindow" (ByVal hWnd As DWord, ByVal nCmdShow As Long) As Long
Declare Function UpdateWindow Lib "USER32.DLL" Alias "UpdateWindow" (ByVal hWnd As DWord) As Long
'Declare Function GetMessage Lib "USER32.DLL" Alias "GetMessageA" (byval lpMsg As tagMSG, ByVal hWnd As DWord, ByVal uMsgFilterMin As DWord, ByVal uMsgFilterMax As DWord) As Long
Declare Function TranslateMessage Lib "USER32.DLL" Alias "TranslateMessage" (lpMsg As tagMSG) As Long
Declare Function DispatchMessage Lib "USER32.DLL" Alias "DispatchMessageA" (lpMsg As tagMSG) As Long
Declare Function GetClientRect Lib "USER32.DLL" Alias "GetClientRect" (ByVal hwnd As DWord, lpRect As RECT) As Long
Declare Function WindowFromDC Lib "USER32.DLL" Alias "WindowFromDC" (ByVal hDC As DWord) As Long
'==============================================================================
Function WINMAIN (ByVal hInstance As DWord, _
ByVal hPrevInstance As DWord, _
ByVal lpCmdLine As Asciiz, _ 'PTR
ByVal iCmdShow As Long) As Long
'------------------------------------------------------------------------------
' Program entry point
'--------------------------------------------------------------------------
Local Msg As tagMsg
Local wce As WndClassEx
Local szAppName As Asciiz * 80
Local hWnd As DWord
' Setup and register a window class for the main window
' CODEPTR is used to pass the address of the function that will
' receive all messages sent to any window created with this class
szAppName = "HelloWin"
wce.cbSize = SizeOf(wce)
wce.STYLE = %CS_HREDRAW Or %CS_VREDRAW
wce.lpfnWndProc = CODEPTR(WndProc)
wce.cbClsExtra = 0
wce.cbWndExtra = 0
wce.hInstance = hInstance
wce.hIcon = LoadIcon(hInstance, "HELLOWIN")
wce.hCursor = LoadCursor(%NULL, ByVal %IDC_ARROW)
wce.hbrBackground = %NULL ' No class background, we do it outselves
wce.lpszMenuName = %NULL
wce.lpszClassName = VarPtr(szAppName)
wce.hIconSm = LoadIcon(hInstance, ByVal %IDI_APPLICATION)
RegisterClassEx wce
' Create a window using the registered class
hWnd = CreateWindow(szAppName, _ ' window class name
"The Hello Program", _ ' window caption
%WS_OVERLAPPEDWINDOW, _ ' window style
%CW_USEDEFAULT, _ ' initial x position
%CW_USEDEFAULT, _ ' initial y position
%CW_USEDEFAULT, _ ' initial x size
%CW_USEDEFAULT, _ ' initial y size
%NULL, _ ' parent window handle
%NULL, _ ' window menu handle
hInstance, _ ' program instance handle
ByVal %NULL) ' creation parameters
If hWnd = 0 Then ' exit on failure
MsgBox "Unable to create window"
Exit Function
End If
' Display the window on the screen
ShowWindow hWnd, iCmdShow
UpdateWindow hWnd
' Main message loop:
' Messages sent to HELLOWIN while it has the focus are received by
' GetMessage(). This loop translates each message and dispatches it
' to the appropriate handler. When PostQuitMessage() is called, the
' loop terminates which ends the application.
Do While GetMessage(Msg, %NULL, 0, 0)
TranslateMessage Msg
DispatchMessage Msg
Loop
Function = msg.wParam
End Function
'==============================================================================
Sub DrawGradient (ByVal hDC As DWord)
'------------------------------------------------------------------------------
' Custom draw procedure for gradiend fill
'--------------------------------------------------------------------------
Local rectFill As RECT
Local rectClient As RECT
Local fStep As Single
Local hBrush As DWord
Local lOnBand As Long
GetClientRect WindowFromDC(hDC), rectClient
fStep = rectClient.nbottom / 200
For lOnBand = 0 To 199
SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
hBrush = CreateSolidBrush(Rgb(0, 0, 255 - lOnBand))
Fillrect hDC, rectFill, hBrush
DeleteObject hBrush
Next
End Sub
'==============================================================================
Function WndProc (ByVal hWnd As DWord, ByVal wMsg As DWord, _
ByVal wParam As DWord, ByVal lParam As Long) Export As Long
'------------------------------------------------------------------------------
' WndProc is the message handler for all windows creating using the HelloWin
' class name. A single WndProc procedure can handle multiple windows by
' testing the hWnd variable passed to it.
'--------------------------------------------------------------------------
Local hDC As DWord
Local pPaint As PAINTSTRUCT
Local tRect As RECT
' The SELECT CASE is used to catch only those messages which the message
' handler needs to process. All other messages are passed through the
' tests to the default handler.
Select Case wMsg
Case %WM_CREATE
Case %WM_PAINT
hDC = BeginPaint(hWnd, pPaint)
GetClientRect hWnd, tRect
SetBkMode hDC, %TRANSPARENT
SetTextColor hDC, %WHITE
DrawText hDC, "Hello, Windows!", -1, tRect, %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER
EndPaint hWnd, pPaint
Function = 1
Exit Function
Case %WM_ERASEBKGND
hDC = wParam
DrawGradient hDC ' Pass the DC of the region to repaint
Function = 1
Exit Function
Case %WM_DESTROY
PostQuitMessage 0
Exit Function
End Select
' Any message which is not handled in the above SELECT CASE reaches this
' point and is processed by the Windows default message handler.
Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
End Function
MsgBox 0, "just a test for sdk window!"
I needed only one hour to collect all files they are important for making sdk window, I am thinking there is still 10 per Cent (in my eyes) missing to fulfil this task to create this window, it was just an idea to do this work around I have made from powerbasic example. So why we can't go similar way of doing ? ;)
best regards, frank