PDA

View Full Version : hello window oxygen



Lionheart008
17-11-2009, 23:20
hello charles, all.

I have a little question about oxygen / thinbasic to create an sdk like window you have done with your "hello win" example some month ago. I would like to know if it's possible to add buttons and colours and perhaps graduate colours background ??? it's just an idea how to create own window styles they are different from boring ms windows ;) jose roca has built such very nice things with "cWindow.inc" for powerbasic, but this I cannot use for thinbasic, but wish to realise this one too.




Uses "Oxygen","File"

%BLUE = 1001

dim src as string
src="


type WNDCLASS
;40 bytes
STYLE as long
lpfnwndproc as long
cbClsextra as long
cbWndExtra as long
hInstance as long
hIcon as long
hCursor as long
hbrBackground as long
lpszMenuName as long
lpszClassName as long
end type

type colours
blue as long
end type

type point
x as long
y as long
end type

type MSG
; 28 bytes
hwnd as long
message as long
wParam as long
lParam as long
time as long
pt as point
end type

dim kernel32,user32,GDI32 as long
kernel32=LoadLibrary `kernel32.dll`
user32=LoadLibrary `user32.dll`
GDI32=LoadLibrary `GDI32.dll`

bind kernel32
(
GetCommandLine GetCommandLineA ; @0
GetModuleHandle GetModuleHandleA ; @4
ExitProcess ExitProcess ; @4
)

bind user32
(
LoadIcon LoadIconA ; @8
LoadCursor LoadCursorA ; @8
RegisterClass RegisterClassA ; @4
MessageBox MessageBoxA ; @4
CreateWindowEx CreateWindowExA ; @48
ShowWindow ShowWindow ; @8
UpdateWindow UpdateWindow ; @4
GetMessage GetMessageA ; @16
TranslateMessage TranslateMessage ; @4
DispatchMessage DispatchMessageA ; @4
PostQuitMessage PostQuitMessage ; @4
BeginPaint BeginPaint ; @8
EndPaint EndPaint ; @8
GetClientRect GetClientRect ; @8
DrawText DrawTextA ; @20
SetTextColor SetTextColor ; @24
PostMessage PostMessageA ; @16
DefWindowProc DefWindowProcA ; @16
)


bind GDI32
(
GetStockObject GetStockObject ; @4
)

declare Function WinMain(byval inst as long ,byval prevInst as long ,byval cmdline as asciiz , byval show as long) as long
declare function WndProc(byval hWnd as long, byval wMsg as long, byval wParam as long, byval lparam as long) as long
'
def SW_NORMAL 1
def SW_SHOWDEFAULT 10


;=====================================

dim cmdline as asciiz ,inst as long

cmdline=GetCommandLine
inst=GetModuleHandle 0
'print cmdline `
'` hex inst

WinMain inst,0,cmdline,SW_NORMAL
'
freelibrary kernel32
freelibrary user32
freelibrary gdi32
terminate

'o2 !10 ; align 16 bytes

;=====================================

% CS_VREDRAW 1
% CS_HREDRAW 2
% IDI_APPLICATION 32512
% IDC_ARROW 32512
% WHITE_BRUSH 0
% MB_ICONERROR 16

def CW_USEDEFAULT 0x80000000
def WS_OVERLAPPEDWINDOW 0x00cf0000


'------------------------------------------------------------
Function WinMain(byval inst as long ,byval prevInst as long,
byval cmdline as asciiz , byval show as long) as long
'===========================================================
'
; window handle

dim a,b,c,hWnd as long
dim wc as WndClass
dim wm as MSG
dim ab as colours

with wc. '
style=CS_HREDRAW or CS_VREDRAW
lpfnWndProc=&WndProc '#long#long#long#long
cbClsExtra=0
cbWndExtra=0
hInstance=inst
hIcon=LoadIcon 0, IDI_APPLICATION
hCursor=LoadCursor 0,IDC_ARROW
hbrBackground=GetStockObject WHITE_BRUSH '
lpszMenuName=0
lpszClassName=`HelloWin`
end with

if not RegisterClass &wc
MessageBox 0,`Registration failed`,`Problem`,MB_ICONERROR
exit function
end if '

hWnd=CreateWindowEx 0,wc.lpszClassName,`Hello my new Window`,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,640,480,
0,0,inst,0

if not hWnd then
MessageBox 0,`Unable to create window`,`problem`,MB_ICONERROR
exit function
end if
'
ShowWindow hWnd,show
UpdateWindow hWnd
;
;MESSAGE LOOP
;
do while GetMessage &wm,0,0,0
TranslateMessage &wm
DispatchMessage &wm
'
'select wm.hwnd
'case hwnd
' if wm.message=256 then print `key down` : exit do
'end select
'
wend
;
function=wm.wparam

end function ; end of WinMain


type RECT
; 16 bytes
left as long
top as long
right as long
bottom as long
end type

type rgbacolor
red as byte
green as byte
blue as byte
alpha as byte
end type

type PAINTSTRUCT
; 64 bytes
hDC as long
fErase as long
rcPaint as rect
fRestore as long
fIncUpdate as long
rgb as rgbacolor
Reserved as 32
end type

% WM_CREATE 1
% WM_DESTROY 2
% WM_PAINT 15
% WM_CLOSE 16
% WM_KEYDOWN 256
% BLUE 32
'-----------------------------------------
function WndProc ( byval hWnd as long,
byval wMsg as long, byval wParam as long,
byval lparam as long ) as long callback
'=========================================

dim cRect as rect
dim Paintst as paintstruct
dim hDC as long

select wMsg

'--------------
case WM_CREATE
'=============

'--------------
case WM_DESTROY
'===============

PostQuitMessage 0

'------------
case WM_PAINT
'============

hDC=BeginPaint hWnd,&Paintst
GetClientRect hWnd,&cRect
; style
; 0x20 DT_SINGLELINE
; 0x04 DT_VCENTER
; 0x01 DT_CENTER
; 0x25
'SetTextColor hDC, %BLUE '%WHITE
DrawText hDC,`Hello my Oxygen World!`,-1,&cRect,0x25
EndPaint hWnd,&Paintst

'--------------
case WM_KEYDOWN
'==============

if wParam=27 then
PostMessage hWnd,WM_CLOSE,0,0
end if

'--------
case else
'========

function=DefWindowProc hWnd,wMsg,wParam,lParam

end select

end function ' WndProc

"
o2_basic src

'msgbox 0,o2_len+$cr+o2_error+o2_prep "o2h "+src ': stop
'File_Save("t.txt",o2_len+$cr+o2_error+o2_prep "o2h "+src ) ': stop
if len(o2_error) then msgbox 0,o2_error : stop

o2_exec


"%Blue" the oxygen script doesn't like. (row 245)
"SetTextColor" I have already defined.

best regards, Frank

Michael Clease
18-11-2009, 00:40
Frank the type below has two entries for blue is that a typo??


type rgbacolor
red as byte
green as byte
blue as byte
alpha as byte
blue as byte
end type

Lionheart008
18-11-2009, 00:45
yes, it's a typo. deleted. thanks :)

Charles Pegge
19-11-2009, 01:27
Hi Frank,

Example of HelloWin with colored text below. I am currently developing Oxygen to be able to read C headers directly which should make life much easier for SDK programming.

Charles

Lionheart008
19-11-2009, 20:37
hello charles. thanks for new colored text and text background :)

here a code part for you to make gradient background. how to include SUB correct in oxygen ? I don't know. you have only to change / translate it for oxygen. see more about at last part of this code example.


' Windows Hello World
' with winmain message loop and wndproc
' Revised 22 Mar 2009
' Charles Pegge


Uses "Oxygen","File"

dim src as string
src="

basic

type WNDCLASS
;40 bytes
STYLE as long
lpfnwndproc as long
cbClsextra as long
cbWndExtra as long
hInstance as long
hIcon as long
hCursor as long
hbrBackground as long
lpszMenuName as long
lpszClassName as long
end type

type point
x as long
y as long
end type

type MSG
; 28 bytes
hwnd as long
message as long
wParam as long
lParam as long
time as long
pt as point
end type

dim kernel32,user32,GDI32 as long
kernel32=LoadLibrary `kernel32.dll`
user32=LoadLibrary `user32.dll`
GDI32=LoadLibrary `GDI32.dll`

bind kernel32
(
GetCommandLine GetCommandLineA ; @0
GetModuleHandle GetModuleHandleA ; @4
ExitProcess ExitProcess ; @4
)

bind user32
(
LoadIcon LoadIconA ; @8
LoadCursor LoadCursorA ; @8
RegisterClass RegisterClassA ; @4
MessageBox MessageBoxA ; @4
CreateWindowEx CreateWindowExA ; @48
ShowWindow ShowWindow ; @8
UpdateWindow UpdateWindow ; @4
GetMessage GetMessageA ; @16
TranslateMessage TranslateMessage ; @4
DispatchMessage DispatchMessageA ; @4
PostQuitMessage PostQuitMessage ; @4
BeginPaint BeginPaint ; @8
EndPaint EndPaint ; @8
GetClientRect GetClientRect ; @8
DrawText DrawTextA ; @20
PostMessage PostMessageA ; @16
DefWindowProc DefWindowProcA ; @16
)


bind GDI32
(
SetBkColor SetBkColor ; @16
SetTextColor SetTextColor ; @16
GetStockObject GetStockObject ; @4
)


declare Function WinMain(byval inst as long ,byval prevInst as long ,byval cmdline as asciiz , byval show as long) as long
declare function WndProc(byval hWnd as long, byval wMsg as long, byval wParam as long, byval lparam as long) as long
'
def SW_NORMAL 1
def SW_SHOWDEFAULT 10


;=====================================

dim cmdline as asciiz ptr,inst as long
&cmdline=GetCommandLine
inst=GetModuleHandle 0
'print cmdline `
'` hex inst
'
WinMain inst,0,cmdline,SW_NORMAL
'
freelibrary kernel32
freelibrary user32
freelibrary gdi32
terminate

'o2 !10 ; align 16 bytes

;=====================================

% CS_VREDRAW 1
% CS_HREDRAW 2
% IDI_APPLICATION 32512
% IDC_ARROW 32512
% WHITE_BRUSH 0
% MB_ICONERROR 16

def CW_USEDEFAULT 0x80000000
def WS_OVERLAPPEDWINDOW 0x00cf0000


'------------------------------------------------------------
Function WinMain(byval inst as long ,byval prevInst as long,
byval cmdline as asciiz , byval show as long) as long
'===========================================================
'
; window handle

dim a,b,c,hWnd as long
dim wc as WndClass
dim wm as MSG

with wc. '
style=CS_HREDRAW or CS_VREDRAW
lpfnWndProc=&WndProc '#long#long#long#long
cbClsExtra=0
cbWndExtra=0
hInstance=inst
hIcon=LoadIcon 0, IDI_APPLICATION
hCursor=LoadCursor 0,IDC_ARROW
hbrBackground=GetStockObject WHITE_BRUSH '
lpszMenuName=0
lpszClassName=`HelloWin`
end with

if not RegisterClass &wc
MessageBox 0,`Registration failed`,`Problem`,MB_ICONERROR
exit function
end if '

hWnd=CreateWindowEx 0,wc.lpszClassName,`Hello my dear Oxygen Window`,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,640,480,
0,0,inst,0

if not hWnd then
MessageBox 0,`Unable to create window`,`problem`,MB_ICONERROR
exit function
end if
'
ShowWindow hWnd,show
UpdateWindow hWnd
;
;MESSAGE LOOP
;
do while GetMessage &wm,0,0,0
TranslateMessage &wm
DispatchMessage &wm
wend
;
function=wm.wparam

end function ; end of WinMain


type RECT
; 16 bytes
left as long
top as long
right as long
bottom as long
end type

type rgbacolor
red as byte
green as byte
blue as byte
alpha as byte
end type

type PAINTSTRUCT
; 64 bytes
hDC as long
fErase as long
rcPaint as rect
fRestore as long
fIncUpdate as long
rgb as rgbacolor
Reserved as 32
end type

% WM_CREATE 1
% WM_DESTROY 2
% WM_PAINT 15
% WM_CLOSE 16
% WM_KEYDOWN 256
% WM_ERASEBKGND 24 ' ---- ????????

'Common RGB Colors
%BLACK = &H000000
%BLUE = &HFF0000
%GREEN = &H00FF00
%CYAN = &HFFFF00
%RED = &H0000FF
%MAGENTA = &HFF00FF
%YELLOW = &H00FFFF
%WHITE = &HFFFFFF
%GRAY = &H808080
%LTGRAY = &HC0C0C0


'-----------------------------------------
function WndProc ( byval hWnd as long,
byval wMsg as long, byval wParam as long,
byval lparam as long ) as long callback
'=========================================

dim cRect as rect
dim Paintst as paintstruct

dim hDC as long

select wMsg

'--------------
case WM_CREATE
'=============

'--------------
case WM_DESTROY
'===============

PostQuitMessage 0

'------------
case WM_PAINT
'============

hDC=BeginPaint hWnd,&Paintst
GetClientRect hWnd,&cRect
; style
; 0x20 DT_SINGLELINE
; 0x04 DT_VCENTER
; 0x01 DT_CENTER
; 0x25
SetBkColor hdc,%BLUE
SetTextColor hdc,yellow
DrawText hDC,`Hello my dear Oxygen World!`,-1,&cRect,0x26
SetBkColor hdc, red
DrawText hDC,`waiting for new sdk Windows!`,-1,&cRect,0x24
SetTextColor hdc,blue
SetBkColor hdc, yellow
DrawText hDC,`the simpsons are great!`,-1,&cRect,0x25
SetBkColor hdc, red
DrawText hDC,`test`,-1,&cRect,0x23
EndPaint hWnd,&Paintst

'--------------
case WM_KEYDOWN
'==============

if wParam=27 then
PostMessage hWnd,WM_CLOSE,0,0
end if

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'-----------------------------------------
CASE WM_ERASEBKGND
hDC = wParam
DrawGradient hDC ' DrawGradient = SUB + Pass the DC of the region to repaint
'FUNCTION = 1
'EXIT FUNCTION
'=========================================
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'--------
case else
'========

function=DefWindowProc hWnd,wMsg,wParam,lParam

end select

end function ' WndProc

'------ ???????????????????????????????????????????????????????????????????????
'==============================================================================
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
'------ ???????????????????????????????????????????????????????????????????????

"

o2_asmo src

'msgbox 0,o2_len+$cr+o2_error+o2_prep src ': stop
'File_Save("t.txt",o2_len+$cr+o2_error+o2_prep src ) ': stop
if len(o2_error) then msgbox 0,o2_error : stop

o2_exec


best regards, frank lionhead

kryton9
19-11-2009, 23:17
Hi Frank,

Example of HelloWin with colored text below. I am currently developing Oxygen to be able to read C headers directly which should make life much easier for SDK programming.

Charles


Charles, I am glad I have been sitting back and letting you work... this is big news indeed about the work on C headers reading being developed. Keep up the great work!

Charles Pegge
20-11-2009, 01:09
Frank,

Shaded Window code incorporated below.

Kent,

We will soon have a composite of C and Basic :)

Charles

TomLebowski
22-11-2009, 14:28
hello frank, charles.

do you have any examples for pure win api example (ui/tbgl/console) ?
very interesting work here! :) asm and win api aren't very unknown for me from c++, but "oxygen".

relaxed sunday, tom

Charles Pegge
22-11-2009, 19:21
Hi Tom,

There are some very good examples of UI in the thinBasic\examples\UI and TBGL folders.

Oxygen is an experimental compiler that works inside thinBasic Scripts. Strings of source code are passed to Oxygen for compiling and execution. (Oxygen started out as an x86 assembler) and it is possible to pass data to and from thinBasic variables, directly or by calling functions

The Hellowin example above demonstrates how to use Oxygen to interface the SDK, but for most API operations it is easier to use thinBasic and its extension modules directly.