Ok after having a look around mostly in the examples folders, also at Rbz's Camouflage music disk and your advice Jim. I have managed to get a very simple and primitive example of my own.
A few things, is how to use a sound scheme if it is enabled on the pc, and I'd also like to have the arrow icon change to a hand if the button performs a task. Also, what would be nice is to have a text field show, when hovering over a particular button.
And another concern is why the background plasma effect doesnt update properlly. Maybe it's in the wrong place, a bit weird that it doesnt move at all. You did mention something about timers; will see if I can find anything on that; still would like some pointers on that.
Heres the code so far:
'
' Clyde Gets Into Windows.
' October 2008
'
Option Explicit
#Include Once "Windows.bi"
#Include Once "crt.bi"
#Include Once "media\FaceP.bas"
#Include Once "media\FaceR.bas"
#Include Once "media\Face2P.bas"
#Include Once "media\Face2R.bas"
Const As Single PI=3.14159265
Const As Single D2R=PI/180.0
Const MAXBUTTONS=2
Const XRES=640
Const YRES=480
Const APPNAME As String="Windows Framework"
Type GfxBuffer
wwidth As Integer
height As Integer
pixels As UInteger pointer
End Type
Type Button
Region As HRGN
Rect As RECT
PosX As Integer
PosY As Integer
Image1 As GFXBuffer Pointer
Image2 As GFXBuffer Pointer
State As Integer
End Type
Dim Shared As GfxBuffer Pointer Image1,Image2, ScreenBuffer, Palette1
Dim Shared As Button Pointer Button( 0 To MAXBUTTONS-1 )
Dim Shared As Single Cosine( 0 to 1500 )
Dim Shared As Integer wave1,wave2,wave3
Declare Sub InitializeWindows()
Declare Sub UpdatePlasma( ByVal Pal As GFXBuffer Pointer,_
ByVal ScreenBuffer As GFXBuffer Pointer,_
ByVal Val1 As Integer,_
ByVal Val2 As Integer,_
ByVal Val3 As Integer )
Declare Sub DrawButton( ByVal hdc as HDC,_
ByVal Buton As Button Pointer )
Declare Sub DrawGfxBuffer( ByVal hdc as HDC,_
ByVal Source As GfxBuffer Pointer,_
ByVal PosX As Integer,_
ByVal PosY As Integer )
Declare Function CreateButton( ByVal Image1 As GFXBuffer Pointer,_
ByVal Image2 As GFXBuffer Pointer,_
ByVal StartPosX As Integer,_
ByVal StartPosY As Integer ) As Button Pointer
Declare Function CreateButtonRegion( ByVal PosX0 As Integer,_
ByVal PosY0 As Integer,_
ByVal PosX1 As Integer,_
ByVal PosY1 As Integer) As HRGN
Declare Function CreateGFXBuffer( Byval WWidth As Integer,_
Byval Height As integer ) As GfxBuffer Pointer
Declare Function CreatePalettes( ByVal WWidth As Integer,_
ByVal Height As Integer,_
ByVal Val1 As Integer,_
ByVal Val2 As Integer,_
ByVal Val3 As Integer,_
ByVal Divv As Integer=360) As GFXBuffer Pointer
Declare Function LoadGraphics8Bit( ByVal WWidth As Integer,_
ByVal Height As Integer,_
ByVal Raw As UByte Pointer,_
ByVal Palet As UByte Pointer ) As GfxBuffer Pointer
Declare Function WndProc ( ByVal hWnd As HWND,_
ByVal message As UINT,_
ByVal wParam As WPARAM,_
ByVal lParam As LPARAM ) As LRESULT
Declare Function WinMain ( ByVal hInstance As HINSTANCE,_
ByVal hPrevInstance As HINSTANCE,_
ByRef szCmdLine As String,_
ByVal iCmdShow As Integer ) As Integer
WinMain( GetModuleHandle( Null ), Null, Command, SW_NORMAL )
End
Sub UpdatePlasma( ByVal Pal As GFXBuffer Pointer,_
ByVal ScreenBuffer As GFXBuffer Pointer,_
ByVal Val1 As Integer,_
ByVal Val2 As Integer,_
ByVal Val3 As Integer )
Dim As Integer x,y,d,f
For y = 0 To ScreenBuffer->Height-1
d = cosine( y + wave2 ) + cosine( y + wave3 )
For x = 0 To ScreenBuffer->WWidth-1
f = cosine( x + wave1 ) + cosine( x + y ) + d and 255
ScreenBuffer->Pixels [ x+y*ScreenBuffer->WWidth ]=Pal->Pixels[ f and 255 ]
Next
Next
wave1 = wave1 + Val1
If wave1 >= ScreenBuffer->WWidth-1 Then wave1 = wave1 - ScreenBuffer->WWidth
wave2 = wave2 + Val2
If wave2 >= ScreenBuffer->WWidth-1 Then wave2 = wave2 - ScreenBuffer->WWidth
wave3 = wave3 + Val3
If wave3 >= ScreenBuffer->WWidth-1 Then wave3 = wave3 - ScreenBuffer->WWidth
End Sub
Function CreateButton( ByVal Image1 As GFXBuffer Pointer,_
ByVal Image2 As GFXBuffer Pointer,_
ByVal StartPosX As Integer,_
ByVal StartPosY As Integer ) As Button Pointer
Dim Btn As Button Pointer=Callocate(Len( Button )+Len( UInteger ))
Btn->PosX=StartPosX
Btn->PosY=StartPosY
Btn->Image1=Image1
Btn->Image2=Image2
Btn->State=0
Btn->Region=CreateButtonRegion( StartPosX,_
StartPosY,_
StartPosX+Btn->Image1->WWidth,_
StartPosY+Btn->Image1->Height )
Btn->Rect.left =StartPosX
Btn->Rect.top =StartPosY
Btn->Rect.right =StartPosX+Btn->Image1->WWidth
Btn->Rect.bottom=StartPosY+Btn->Image1->Height
Function=Btn
End Function
Function CreateButtonRegion( ByVal PosX0 As Integer, ByVal PosY0 As Integer, ByVal PosX1 As Integer, ByVal PosY1 As Integer) As HRGN
Dim Region As HRGN
Region=CreateRectRgn( PosX0,_ ' x-coordinate of region's upper-left corner
PosY0,_ ' y-coordinate of region's upper-left corner
PosX1,_ ' x-coordinate of region's lower-right corner
PosY1 ) ' y-coordinate of region's lower-right corner
Function=Region
End Function
Sub InitializeWindows()
ScreenBuffer = CreateGFXBuffer( XRES, YRES )
Image1= LoadGraphics8bit(32,32,@facer(0),@facep(0))
Image2= LoadGraphics8bit(32,32,@facer2(0),@facep2(0))
Button(0)=CreateButton( Image1,_
Image2,_
100,_
100)
Button(1)=CreateButton( Image1,_
Image2,_
280,_
32)
Palette1=CreatePalettes(1,256,16,128,0)
Dim As Integer a
For a=0 To 1499
Cosine( a ) = Cos( (( 115*PI * a ) / ScreenBuffer->WWidth )*D2R ) * 128
Next
End Sub
Sub DrawButton( ByVal hdc as HDC,_
ByVal Buton As Button Pointer )
Select Case As Const Buton->State
Case 0:
DrawGFXBuffer( hdc, Buton->Image1, Buton->PosX, Buton->PosY )
Case 1:
DrawGFXBuffer( hdc, Buton->Image2, Buton->PosX, Buton->PosY )
End Select
End Sub
Sub DrawGfxBuffer( ByVal hdc as HDC,_
ByVal Source As GfxBuffer Pointer,_
ByVal PosX As Integer,_
ByVal PosY As Integer )
Dim bmi As BITMAPINFO
With bmi.bmiheader
.biSize = SizeOf (BITMAPINFOHEADER)
.biWidth = Source->WWidth
.biHeight = -Source->Height
.biPlanes = 1
.biBitCount = 32
.biCompression = BI_RGB
.biSizeImage = 0
.biClrUsed = 0
.biClrImportant = 0
End With
SetDIBitsToDevice( hdc,_
PosX,_
PosY,_
Source->WWidth,_
Source->Height,_
0,_
0,_
0,_
Source->Height,_
@Source->Pixels[0],_
@bmi,_
DIB_RGB_COLORS)
End Sub
Function CreatePalettes( ByVal WWidth As Integer,_
ByVal Height As Integer,_
ByVal Val1 As Integer,_
ByVal Val2 As Integer,_
ByVal Val3 As Integer,_
ByVal Divv As Integer=360) As GFXBuffer Pointer
Dim As GFXBuffer Pointer Pal=CreateGFXBuffer(WWidth,Height)
Dim As Integer a, red, grn, blu
Dim As Single m
For a=0 to 255
m = a*(Divv/255)
red = cos( (m+Val1)*D2R ) *127+127
grn = cos( (m+Val2)*D2R ) *127+127
blu = cos( (m+Val3)*D2R ) *127+127
Pal->Pixels[ a*Pal->WWidth ] = rgb(red,grn,blu)
Next
Return Pal
End Function
Function CreateGFXBuffer( Byval WWidth As Integer,_
Byval Height As Integer ) As GfxBuffer Pointer
Dim As GfxBuffer Pointer Buffer=Callocate(Len( GfxBuffer )+Len( UInteger )*WWidth*Height)
Buffer->wwidth=WWidth
Buffer->height=Height
Buffer->pixels=Cast( UInteger Pointer, Cast( Byte Pointer, Buffer )+Len( GfxBuffer ))
Function=Buffer
End Function
Function WndProc ( ByVal hWnd As HWND,_
ByVal message As UINT,_
ByVal wParam As WPARAM,_
ByVal lParam As LPARAM ) As LRESULT
Dim As PAINTSTRUCT SBuffer
Dim As HDC hDC
Dim As Integer MouseX, MouseY, a
Select Case ( message )
Case WM_CREATE
InitializeWindows()
Function=0
Case WM_PAINT
hDC = BeginPaint( hWnd, @SBuffer )
UpdatePlasma( Palette1, ScreenBuffer, 2, 4, 2 )
DrawGFXBuffer( hdc, ScreenBuffer, 0, 0 )
For a=0 To MAXBUTTONS-1
DrawButton( hdc, Button(a) )
Next
EndPaint( hWnd, @SBuffer )
Function=0
case WM_LBUTTONDOWN
'If Button(0)->State=1 'Then sleep(200)
Case WM_MOUSEMOVE
MouseX = LoWord(lParam)' and &Hffff
MouseY = HiWord(lParam)' shr 16
For a=0 To MAXBUTTONS-1
If (PtInRegion(Button(a)->Region, MouseX, MouseY) <> 0) then
Button(a)->State=1
InvalidateRect(hWnd, @Button(a)->Rect, FALSE)
Else
Button(a)->State=0
InvalidateRect(hWnd, @Button(a)->Rect, FALSE)
End if
Next
Case WM_KEYDOWN
Select Case LoByte( wParam )
Case VK_ESCAPE
PostMessage( hWnd, WM_CLOSE, 0, 0 )
Function=0
End Select
Case WM_DESTROY
PostQuitMessage( 0 )
Function=0
End Select
Function=DefWindowProc( hWnd, message, wParam, lParam )
End function
Function WinMain ( ByVal hInstance As HINSTANCE,_
ByVal hPrevInstance As HINSTANCE,_
ByRef szCmdLine As String,_
ByVal iCmdShow As Integer ) As Integer
Dim wMsg As MSG
Dim wClass As WNDCLASS
Dim hWnd As HWND
Function = 0
With wClass
.style = CS_HREDRAW or CS_VREDRAW
.lpfnWndProc = @WndProc
.cbClsExtra = 0
.cbWndExtra = 0
.hInstance = hInstance
.hIcon = LoadIcon( null, IDI_APPLICATION )
.hCursor = LoadCursor( null, IDC_ARROW )
.hbrBackground = GetStockObject( BLACK_BRUSH )
.lpszMenuName = null
.lpszClassName = StrPtr( APPNAME )
end with
If( RegisterClass( @wClass ) = False ) Then
Exit Function
End If
hWnd = CreateWindowEx( 0,_
APPNAME,_
APPNAME,_
WS_OVERLAPPEDWINDOW, _
CW_USEDEFAULT,_
CW_USEDEFAULT,_
XRES,_
YRES,_
null,_
null,_
hInstance,_
null )
ShowWindow ( hWnd, iCmdShow )
UpdateWindow( hWnd )
While ( GetMessage( @wMsg, null, 0, 0 ) <> False )
TranslateMessage( @wMsg )
DispatchMessage ( @wMsg )
Wend
Function = wMsg.wParam
End Function
Function LoadGraphics8Bit( ByVal WWidth As Integer,_
ByVal Height As Integer,_
ByVal Raw As UByte Pointer,_
ByVal Palet As UByte Pointer ) As GfxBuffer Pointer
Dim As GfxBuffer Pointer Buffer=CreateGFXBuffer( WWidth, Height )
Dim As UInteger pal(0 to 255)
Dim As Integer a,x,y
'
' Retrieve Palette Info.
'
For a=0 to 255
pal(a)=(palet[a*3] Shl 16) Or (palet[a*3+1] Shl 8) Or(palet[a*3+2])
Next
'
' Make Image Based On Colour Indexing With The Raw values.
'
For y=0 to Height-1
For x=0 to WWidth-1
Buffer->Pixels[ x+y*WWidth ]=Pal(Raw[x+y*WWidth])
Next
Next
Function=Buffer
End Function