So updated the Code, Enabled Disableing and Made the code easyer to read.
First how can I recognize a Mouseover event? I guess It has something to do with #BCN_HOTITEMCHANGE but It's not declared.
Second. #WS_TABSTOP isn't working, does someone know why? I guess I need #BS_NOTIFY as a Window Parameter but it isn't declared.
Code: Select all
EnableExplicit
Global DisableButton
Structure IntParts
Part1.w
Part2.w
EndStructure
OpenLibrary(1,"Msimg32.dll") ;load te Command GradientFill_() because it's missing in the PB predeclared Api Things
Prototype GradientFill_(hdc,*Vert,Int,*Rect,Int2,Flags)
Global GradientFill_.GradientFill_=GetFunction(1,"GradientFill")
Procedure DrawButton(hwnd,hdc,*Coor.RECT,State)
Protected Dim Vert.TRIVERTEX(1) ;Allocate an array with 2 Element. One is the top the other one the bottom color
Protected TCol.l
Protected Rect.GRADIENT_RECT
Protected x.l
Protected y.l
Protected w.l
Protected h.l
Protected SysCol.l
Protected Text.s{255} ;Allocating the Text for getting the Text
Protected Pen
Protected OldPen
With *Coor
x.l=\Left
y.l=\top
w.l=\right-\left
h.l=\bottom-\top
EndWith
If State & #ODS_SELECTED ;{ Button down (selected)
With Vert(0) ;Set the Colors
\x=1
\y=1
\Blue=$FF00
EndWith
With Vert(1)
\x=w-1
\y=h-1
\Red=$9700
\Green=$BF00
\Blue=$F000
EndWith
TCol=$DDDDDD
;}
ElseIf State & #ODS_HOTLIGHT ;{ Mouseover
With Vert(0) ;Set the Colors
\x=w-1
\y=h-1
\Blue=$FF00
EndWith
With Vert(1)
\x=1
\y=1
\Red=$9700
\Green=$BF00
\Blue=$F000
EndWith
TCol=$DDDDDD
;}
ElseIf State & #ODS_FOCUS ;{ Focus
With Vert(0) ;Set the Colors
\x=w-1
\y=h-1
\Blue=$FF00
EndWith
With Vert(1)
\x=1
\y=1
\Red=$9700
\Green=$BF00
\Blue=$F000
EndWith
TCol=$DDDDDD
;}
ElseIf State & #ODS_DISABLED ;{ Disabled
With Vert(1)
\x=1
\y=1
\Red=$FF00
\Green=$FF00
\Blue=$FF00
EndWith
With Vert(0) ;Set the Colors
\x=1
\y=1
\Red=$EE00
\Green=$E400
\Blue=$E900
EndWith
TCol=$CCCCCC
;}
Else ;{ Normal
With Vert(0)
\x=1
\y=1
\Red=$EE00
\Green=$E400
\Blue=$E900
EndWith
With Vert(1)
\x=w-1
\y=h-1
\Red=$C700
\Green=$B900
\Blue=$C200
EndWith
TCol=$222222
;}
EndIf
;Set the Elements of te Array wich are used (here 0 and 1)
With Rect
\UpperLeft = 0
\LowerRight = 1
EndWith
Rectangle_(hdc,0,0,w,h) ;Draw a black rectangle on te hdc of the Gadget
GradientFill_(hdc,@Vert(),2,Rect,1,#GRADIENT_FILL_RECT_V) ;Make the gradiant 2 and 1 stands for the Elements of the Array
SysCol=$FFFFFF;GetSysColor_(COLOR_WINDOW+6) ;Choose a color for te Edges of the Button
SetPixelV_(hdc,0,0,SysCol) ;Draw the 4 Pixels at the Edges
SetPixelV_(hdc,w-1,0,SysCol)
SetPixelV_(hdc,0,h-1,SysCol)
SetPixelV_(hdc,w-1,h-1,SysCol)
SetBkMode_(hdc,#TRANSPARENT) ;Make the Background Transparent
SetTextColor_(hdc,TCol) ;Set a Text Color
SendMessage_(hwnd,#WM_GETTEXT,255,Text.s) ;Get the Text
DrawText_(hdc,Text.s,-1,*Coor,#DT_CENTER|#DT_VCENTER|#DT_SINGLELINE) ;Draw the Text u want to draw, -1 sows that it's 0 terminated.
If State & #ODS_FOCUS
Pen=CreatePen_(#PS_DOT,1,0)
oldpen=GetCurrentObject_(hdc,#OBJ_PEN)
SelectObject_(hdc,Pen)
;Rectangle_(hdc,2,2,w-3,h-3)
MoveToEx_(hdc,2,2,0)
LineTo_(hdc,w-3,2)
LineTo_(hdc,w-3,h-3)
LineTo_(hdc,2,h-3)
LineTo_(hdc,2,2)
SelectObject_(hdc,oldpen)
DeleteObject_(Pen)
EndIf
EndProcedure
Procedure WindowCallback(Window, Message, wParam, lParam)
Protected Result
Protected *Item.DRAWITEMSTRUCT
Protected *Parts.IntParts
Select Message ;selecting the Message of the callback
Case #WM_CLOSE ;If the [x] is pressed
DestroyWindow_(Window)
Case #WM_DESTROY ;If close Is made
PostQuitMessage_(0)
Result = 0
Case #WM_INITDIALOG ;initializing of the Button
Debug "Init"
Case #WM_DRAWITEM ;if the Gadget has to be redrawn
Debug "Draw"
*Item=lParam ;Set the Pointer To the Structure
With *Item
DrawButton(\hwndItem,\hdc,\rcItem,\itemState)
EndWith
Result=1
Case #WM_COMMAND
*Parts=@wParam
Select *Parts\Part2
Case #BN_CLICKED
Debug "Click"
If IsWindowEnabled_(DisableButton)
EnableWindow_(DisableButton,0)
Else
EnableWindow_(DisableButton,1)
EndIf
Case #BN_SETFOCUS
Debug "Focus"
EndSelect
ProcedureReturn 0
Default
Result = DefWindowProc_(Window, Message, wParam, lParam)
EndSelect
ProcedureReturn Result
EndProcedure
#Style = #WS_VISIBLE | #WS_BORDER | #WS_SYSMENU
#StyleEx = #WS_EX_OVERLAPPEDWINDOW
Define WindowClass.s
Define wc.WNDCLASSEX
Define hWndMain
Define msg.MSG
Define Init.INITCOMMONCONTROLSEX
With Init
\dwSize=SizeOf(INITCOMMONCONTROLSEX)
\dwICC=#ICC_STANDARD_CLASSES
EndWith
InitCommonControlsEx_(Init)
WindowClass.s = "My Window" ;register a Window
wc\cbSize = SizeOf(WNDCLASSEX)
wc\lpfnWndProc = @WindowCallback()
wc\hCursor = LoadCursor_(0, #IDC_ARROW); #IDC_ARROW = Arrow
wc\hbrBackground = CreateSolidBrush_($FFFFFF)
wc\lpszClassName = @WindowClass
RegisterClassEx_(@wc)
;
hWndMain = CreateWindowEx_(#StyleEx, WindowClass, "Test-Window", #Style, 10, 10, 500, 500, 0, 0, 0, 0) ;Crerate the MainWindow
CreateWindowEx_(0, "Button", "Button 1", #WS_CHILD | #WS_VISIBLE|#WS_TABSTOP|#BS_OWNERDRAW , 10, 10, 60,60, hWndMain, 1337,0, 0) ;Create the Button 1
DisableButton=CreateWindowEx_(0, "Button", "Button 2", #WS_CHILD|#WS_TABSTOP| #WS_VISIBLE|#BS_OWNERDRAW , 100, 100, 200,30, hWndMain, 1338,0, 0) ;Create the Button 2
CreateWindowEx_(0, "Button", "Button 3", #WS_CHILD | #WS_VISIBLE|#WS_TABSTOP|#BS_OWNERDRAW , 300, 300, 100,100, hWndMain, 1339,0, 0) ;Create the Button 3
ShowWindow_(hWndMain, #SW_SHOWDEFAULT) ;U Don't need it but it's saver
UpdateWindow_(hWndMain);
While GetMessage_(msg, #Null, 0, 0 ) ;Windowevent()
TranslateMessage_(msg)
DispatchMessage_(msg)
Wend