PDA

View Full Version : window sdk possible like petzold ?



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

Michael Hartlef
16-01-2010, 17:32
Okeyyyy ???? :? Franck, why you want to do this? I mean thinBasic provides windows/dialogs, why do you want to create one via API?

Edit: You need to call WINMAIN yourself. thinBasic doesn't support automatic call of a WINMAIN function.

Petr Schreiber
16-01-2010, 18:45
Hi Frank,

yes, possible.

But if you feel need for creating Windows the SDK way, pick PowerBASIC or Oxygen (compiled).
ThinBASIC is text parsing interpreter, it does not support true CODEPTR you have in your code.
Therefore there would be no reply to messages coming to the window.

But I think this is not needed in this case!

ThinBASIC provides mechanism to overcome this, with his higher level syntax for design of user interface.
This commands enable you to use Dialogs, not Windows.

As I noted in other thread, when porting code:

Make sure you examined suitability of language you ported to
Try to recreate what the code does, catch the idea
Do not port line by line


If you understand this concept, you can be happy, and see you can recreate the code you posted to ThinBASIC...

You can see the CALLBACK FUNCTION in TB is very similar in structure to your WndProc, but it autoallocates handle, message, wparam, lparam.



' 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 TBMAIN()
'------------------------------------------------------------------------------
' Program entry point
'--------------------------------------------------------------------------
Local hDlg As DWord

Dialog New 0, "Hello Win",-1,-1, 330, 203, _
%WS_POPUP Or _
%WS_VISIBLE Or _
%WS_CLIPCHILDREN Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_MINIMIZEBOX, _
0 To hDlg

Dialog Show Modal hDlg Call cbDlgProc

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


'==============================================================================
CallBack Function cbDlgProc () 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 CBMSG

Case %WM_INITDIALOG

Case %WM_PAINT
hDC = BeginPaint(cbHndl, pPaint)
GetClientRect(CBHNDL, tRect)
SetBkMode(hDC, %TRANSPARENT)
SetTextColor(hDC, %WHITE)
DrawText(hDC, "Hello, Windows!", -1, tRect, %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER)
EndPaint(CBHNDL, pPaint)
Function = 1
Exit Function

Case %WM_ERASEBKGND
hDC = CBWPARAM
DrawGradient(hDC) ' Pass the DC of the region to repaint
Function = 1
Exit Function

Case %WM_CLOSE
Exit Function

End Select

End Function


So I just ported it. It has one minor problem - I spent some minutes to make work code ... which with study of ThinBASIC and what the code does (drawing gradient and one line of text) ... would reduce to this:



Uses "UI"

Begin Const
%lText = %WM_USER + 1
End Const

' -- Create dialog here
Function TBMAIN()
Local hDlg As DWord

Dialog New 0, "Hello win",-1,-1, 330, 203, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg
Dialog Set Gradient hDlg, %GRADIENT_FILL_V, Rgb(0,0,0), Rgb(0,0,255)
' -- Place controls here
Control Add Label, hDlg, %lText, "Hello Win", 0, 0, 330, 203, %SS_CENTER Or %SS_CENTERIMAGE
Control Set Color hDlg, %lText, %WHITE, -2

Dialog Show Modal hDlg, Call cbDialog

End Function

' -- Callback for dialog
CallBack Function cbDialog()

' -- Test for messages
Select Case CBMSG

Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here

Case %WM_COMMAND
' -- You can handle controls here

Case %WM_CLOSE
' -- Put code to be executed before dialog end here

End Select

End Function


185 lines of code versus ... just 40, from which 95% pregenerated for you from template.

Resume of this experiment:

ThinBASIC does not do Window frames, but can create Dialogs for you
If you like drawing with GDI, you can use it with Dialogs and do not need Windows for it
If you need just simple stuff like gradient and centered text, you can use TB high level syntax to get job done
If you code really hardcore Win32 coding, with subclassing of controls, you better pick PowerBASIC or Oxygen

zlatkoAB
17-01-2010, 13:25
ThinBASIC does not do Window frames, but can create Dialogs

What's that mean?
If i understand properly ThinBasic can't create real Window frame
only Dialog.
How is this posibile?
And why canot create real Windows?
It sounds weird for me.
is that mean that Power Basic also can't create real windows or
anything else...?

Petr Schreiber
17-01-2010, 13:58
Hi Zlatko,

the rectangles you drag around on the desktop of Windows OS can be of 2 kinds:

windows - created using CreateWindow / CreateWindowEx from Win32

dialogs - created using CreateDialog from Win32, in fact they are subset of window class making some things easier so programmer so he does not have to care about it.

ThinBASIC is not PowerBASIC, and PowerBASIC is not ThinBASIC, so by features of one you canot imply features of second.

PowerBASIC is designed for low level Windows coders, and as a such, it of course supports both Windows and Dialogs and thanks to José Roca basically any Windows(OS) technology you can imagine.

ThinBASIC is targeted more high level, when in need of something special you can always extend it using the SDK in many languages, PowerBASIC included.

For example TBGL window is "window", not dialog.


Petr

Aurel
17-01-2010, 16:12
Hi Petr...
You dont answer on my question.
All what you say i already know.
So i see that Thin Basic create only dialog not window.
Becose window dont support Modal type .
I also know that Creative can't return pointer to lpfnWndProc becose is also interpreter.
But can create window and dialog.
I dont know why Erose use dialog and not window as main type of frame.
dialogs are from my point of view limited type of frames then window is.
However important thing is that thinBasic work fine and that is great basic interpreter. :D

ErosOlmi
17-01-2010, 19:00
Aurel? zlatkoAB? Are you going double personality? Why two users?

Anyhow, please stay calm. Petr has no any contract or duty that he "has to" reply to you. Accept what he said and use it for whatever you need.

As Petr already said: thinBasic is not Power Basic. The fact both languages shares some common constructs is just because I (repeat: I) like the elegance of Power Basic and decided to copy some syntax. That's all. Inside, thinBasic is a completely different language most of which is built from the whole Windows API.

On Windows/Dialogs understanding: thinBasic never creates Dialogs but always Windows. The fact the syntax uses DIALOG keyword is not one to one related with the idea of API dialogs but just related to the fact I liked that keyword.
What makes a real difference here is the way a thinBasic DIALOG (equal Window) is showed: modal or modeless. In modal way some standard actions/behaves takes place directly in thinBasic and (most important) code execution does not return until dialog is destroyed. In modeless way programmer have full control, and full duty, to manage a message pump loop in order for the application to remain alive.
Both ways can be used to create whatever kind of application. Is up to the programmer having the ability to use it.

What Petr was telling about impossibility to create windows using standard API in thinBasic is the fact that thinBasic cannot have pointers to script functions (because script functions exists only as source code) so it would be impossible to create a new class giving to it the pointer to a script function in place to manage window messages.

Lastly: never forget thinBasic is an interpreted language. Not a pCode, not an intermediate sort of pre-compiled code, not a byteCode intepreter but an "on the fly" interpreter that means all source code is continuously interpreted by the engine. As you know (and I'm sure you know looking at what you have already done with aBasic) keeping all up and running and managing Windows events on the fly is not something very easy to be done by an interpreter.

I hope my reply can satisfy your thirsty of thinBasic knowledge.

Eros

zlatkoAB
17-01-2010, 19:23
thinBasic never creates Dialogs but always Windows.
That's i want to here.
Yes this keyword DIALOG look very confusing.
Great explanation Eros... :)

Lionheart008
18-01-2010, 15:09
hello all :)

eros:

What Petr was telling about impossibility to create windows using standard API in thinBasic is the fact that thinBasic cannot have pointers to script functions (because script functions exists only as source code) so it would be impossible to create a new class giving to it the pointer to a script function in place to manage window messages.

I tried to explore last week-end what are the main reasons for (cannot) creation of windows using standard API with thinbasic and found a lot of new things to know about different between powerbasic / thinbasic, thanks to all here for exlanations. for me these things are new, so better to ask again and tried this way I have done with my first post. - of course, I know the very short way of creating "dialogs" with (UI) and open gl windows by "tbgl" module. I like this way and use it often, you can imagine.

about two things I wasn't quite sure how to handle with thinbasic and like michael said
You need to call WINMAIN yourself. thinBasic doesn't support automatic call of a WINMAIN function.

I found infos about: "codeptr" and "winmain"

and I thought there were similar ways for making "windows sdk" like petzold did it his example. How can I know what it's possible with thinbasic before I haven't tried it ;)

"CODEPTR" powerbasic compiles and likes it:


#COMPILE EXE
#DIM ALL

SUB MySub()

END SUB


FUNCTION PBMAIN () AS LONG

'address32 = CODEPTR({label | functionname | subname})

LOCAL MySubPtr, AS LONG, X AS STRING

MySubPtr = CODEPTR(MySub) ' Address of MySub()

MSGBOX "MySub() is located at address " + STR$(MySubPtr)

END FUNCTION
'result: 4198744


from manual of powerbasic "codeptr":

Purpose: Obtain a 32-bit address of a label, Sub or Function.

Syntax: address32 = CODEPTR({label | functionname | subname})

Remarks:
CODEPTR is particularly useful when it is necessary to pass the address of a SUB or FUNCTION to Windows for callbacks. address32 must be a Long-integer (LONG) or Double-word (DWORD) variable.



"winmain":


Purpose
WINMAIN (or its synonym MAIN) is a user-defined function called by Windows to begin execution of an application.

Syntax:
FUNCTION {WINMAIN | MAIN} ( _
BYVAL hInstance AS DWORD, _
BYVAL hPrevInst AS DWORD, _
BYVAL lpszCmdLine AS ASCIIZ PTR, _
BYVAL nCmdShow AS LONG ) AS LONG

Remarks:
The WINMAIN function is called by Windows when an executable application first loads and begins to run. It is often referred to as the "entry point" for the application. When the execution of WINMAIN is completed, the application is deemed to be finished, and Windows releases the application memory back to the heap. WINMAIN receives the following parameters:



I see and know already about some differences between powerbasic / thinbasic and it was just an idea to start this topic about sdk window because I wasn't sure if eros or anybody else could programmed with thinbasic sdk like window api's.

petr said:

But if you feel need for creating Windows the SDK way, pick PowerBASIC or Oxygen (compiled). ThinBASIC is text parsing interpreter, it does not support true CODEPTR you have in your code. Therefore there would be no reply to messages coming to the window.


thanks. that's for one part new for me and very ok. I didn't know that thinbasic is a "text parsing interpreter" and therefore the user cannot create adequate sdk window like powerbasic does it, but that's no problem, I just wanted to figure it out. see above lines.

the question 'what's the different between dialog and window' wasn't so clear for me too, as zlatko already mentioned and asked for, thanks.

eros:

On Windows/Dialogs understanding: thinBasic never creates Dialogs but always Windows. The fact the syntax uses DIALOG keyword is not one to one related with the idea of API dialogs but just related to the fact I liked that keyword.

thanks to all here and for petr's example! the more I know about a basic programming language (interpreter) like thinbasic and see differences to other basic languages I learn more and this one helps! :)

and I like the idea that "thinbasic" and "popwerbasic" are not 100 per Cent similar sisters or twins but two independent originals. good to know that! :P

topic finished, thanks, frank

ps: one other main thought was to create sdk window with thinbasic to have more "influences" and can get more "manipulations" by user for window frames than using dialogs, but that's not true I see ;)

Michael Hartlef
18-01-2010, 17:32
Franck, as I understood it, only the window creation and message handling you can't do it the SDK way. But other SDK commands should still be usable, as you have the handle fromt he window.

Michael Hartlef
18-01-2010, 17:40
Here is the slightly modified sample script from the sampleScripts/Api/Dummy folder. There you can see that SDK programming is possible because you can use the windows handle that got returned when you created the dialog/window:




uses "UI"

' -- Win32 function
DECLARE FUNCTION AnimateWindow LIB "USER32.DLL" ALIAS "AnimateWindow" (BYVAL hWnd AS DWORD, BYVAL dwTime AS DWORD, BYVAL dwFlags AS DWORD) AS LONG

begin const
%ID_BLEND = 1000
end const
Dim hwnd As DWord

function TBMain()
'DIM hwnd AS Dword

DIALOG NEW 0, "Sample window", -1, -1, 180, 180, _
%WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU TO hwnd

CONTROL ADD BUTTON, hwnd, %ID_BLEND, "Blend", 10, 10, 160, 160

DIALOG SHOW MODAL hwnd, call dlgCallback
end function

callback function dlgCallback() as long

SELECT CASE cbMsg

CASE %WM_COMMAND

SELECT CASE cbCtl

CASE %ID_BLEND
if cbCtlMsg = %BN_CLICKED then
DIALOG SHOW STATE cbHndl, %SW_HIDE
AnimateWindow hWnd, 500, %AW_BLEND
'AnimateWindow cbHndl, 500, %AW_BLEND
Dialog Show State CBHNDL, %SW_SHOW
end if

END SELECT
END SELECT

end function

Lionheart008
18-01-2010, 18:08
see also: http://community.thinbasic.com/index.php?topic=2460.0

oh yes, my example you can use from february last year too and my wish at that time was to know more about "animated window" features ;)


DECLARE FUNCTION AnimateWindow LIB "USER32.DLL" ALIAS "AnimateWindow" (BYVAL hWnd AS DWORD, BYVAL dwTime AS DWORD, BYVAL dwFlags AS DWORD) AS LONG

uses "UI" ' API

'---Global variables declaration
DIM Msg AS LONG
DIM wParam AS LONG
DIM lParam AS LONG
DIM hwnd AS LONG

DIALOG NEW 0, "Animated Sample window", -1, -1, 195, 180, _
%WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU OR %WS_OVERLAPPEDWINDOW, _
0 TO hwnd

%ID_SLIDE = 10
%ID_ACTIVATE = 20
%ID_BLEND = 30
%ID_HIDE = 40
%ID_CENTER = 50
%ID_HOR_POSITIVE = 60
%ID_HOR_NEGATIVE = 70
%ID_VER_POSITIVE = 80
%ID_VER_NEGATIVE = 90


CONTROL ADD BUTTON, hwnd, %ID_SLIDE , "Slide", 10, 20, 50, 16
CONTROL ADD BUTTON , hwnd, %ID_BLEND , "Blend", 50, 60, 50, 16
CONTROL ADD BUTTON , hwnd, %ID_Center , "Center", 80, 90, 50, 16
CONTROL ADD BUTTON , hwnd, %ID_Hor_Positive, "HorPos", 120, 120, 50, 16
CONTROL ADD BUTTON , hwnd, %ID_Ver_Negative, "NegVer", 60, 160, 50, 16
CONTROL ADD LABEL, hwnd, 1000,"Push the buttons to see the animated window effect", 5, 5, 200, 14

DIALOG SHOW MODELESS hwnd


'---Start the main message loop
WHILE IsWindow(hwnd)

'---Get the message and fill wParam and lParam
Msg = GetMessage(hwnd, wParam, lParam)

SELECT CASE Msg

CASE %WM_KEYUP

CASE %WM_COMMAND

SELECT CASE wParam

CASE %ID_SLIDE
DIALOG SHOW STATE hwnd, %SW_HIDE
AnimateWindow hwnd, 5000, %AW_SLIDE
DIALOG SHOW STATE hwnd, %SW_show

CASE %ID_BLEND
DIALOG SHOW STATE hwnd, %SW_HIDE
AnimateWindow hwnd, 2000, %AW_BLEND
DIALOG SHOW STATE hwnd, %SW_show

CASE %ID_Center
DIALOG SHOW STATE hwnd, %SW_Hide
AnimateWindow hwnd, 1500, %AW_Center
DIALOG SHOW STATE hwnd, %SW_show

CASE %ID_Hor_Positive
DIALOG SHOW STATE hwnd, %SW_Hide
AnimateWindow hwnd, 2500, %AW_Hor_Positive
DIALOG SHOW STATE hwnd, %SW_show

CASE %ID_Ver_Negative
DIALOG SHOW STATE hwnd, %SW_Hide
AnimateWindow hwnd, 1500, %AW_Ver_Negative
DIALOG SHOW STATE hwnd, %SW_show

END SELECT

CASE %WM_SYSCOMMAND

SELECT CASE wParam

CASE %SC_CLOSE
EXIT WHILE

END SELECT

END SELECT

WEND

DIALOG END hwnd


thank you michael for your example :)

by the way:
you can't start window frame with powerbasic (so I have tried some weeks ago) without wndproc() function (thinbasic: here responsible for callback functions) and you obtain only with affected using between "winmain() + wndproc()"


FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
BYVAL wParam AS DWORD, BYVAL lParam AS LONG) EXPORT AS LONG

+


FUNCTION WINMAIN (BYVAL hInstance AS DWORD, _
BYVAL hPrevInstance AS DWORD, _
BYVAL lpCmdLine AS ASCIIZ PTR, _
BYVAL iCmdShow AS LONG) AS LONG

to start your window frame (sdk). neither you can use "winmain" alone nor "wndproc" alone, you "have to" use both to start your window frame.
I have tried to make some tricks with a function as a substitute to start only by "winmain" with CODEPTR(wndproc), took "wndproc()" function in a DLL and declared this one before "FUNCTION PBMAIN () AS LONG ... END FUNCTION", but then the program says, "no!" there's missing wndproc() or can't start window or failed to start window :)

"dialog new 0" is just a very good and superb fast, easy to handling way! - If I'll find some day a way to start sdk window without oxygen I will show this code here ;)

best regards, frank

ErosOlmi
18-01-2010, 18:18
WIN_Animate (equivalent of AnimateWindow API) is now part of current thinBasic beta.
Ciao
Eros

catventure
18-01-2010, 21:12
WIN_Animate (equivalent of AnimateWindow API) is now part of current thinBasic beta.


Great! Used it already to slide my dialog windows down/up ; expand/contract when open/closed.

catventure