Gadget Blues Again - [FIXED]
Posted: Fri Jul 13, 2007 9:23 pm
In the following code I have 3 bugs/problems I cannot find a solution for
1) enabling line after ;Disable/Enable following line will cause all buttons in container not to work
**FIXED
2) the image button added to toolbar is not visible though if you click it, it appears
**FIXED
3) to dissapear again when the about window comes on
**FIXED
I have done this code with help recieved from the forum, so any mistakes are mine
cheers
KingLestat
**EDIT
Thanks to srod's suggestion and (again) from srod own posts I found a routine SizeBackImage which seems to do the job + some other of er...srods code again...modified the callback routine
1) enabling line after ;Disable/Enable following line will cause all buttons in container not to work
**FIXED
2) the image button added to toolbar is not visible though if you click it, it appears
**FIXED
3) to dissapear again when the about window comes on
**FIXED
I have done this code with help recieved from the forum, so any mistakes are mine
Code: Select all
Enumeration
#MainWindow
#MainImage
#lv_image
#Button1
#Button2
#Button3
#MainTB
#TBButton1
#TBButton2
#TBButton3
#TBButton4
#TBButton5
#TBButton6
#BTN2www
#StaticTextFont
#Container1
#Container2
#TestButton1
#TestButton2
#TestButton3
#TextGadget1
#TextGadget2
#AboutWindow
EndEnumeration
#SBSizeMain = 400
#SBSizeField = 50
#SBClearDelay = 9000
#CONTAINER_Y = 36
#CONTAINER_SIZEX = 400
#CONTAINER_SIZEY = 200
Macro GadIMG ( GadNUM, ImgBrush )
SetClassLong_ ( GadgetID ( GadNUM ), #GCL_HBRBACKGROUND, ImgBrush )
InvalidateRect_ ( GadgetID ( GadNUM ), 0 ,1 )
EndMacro
Macro SetStyle ( GadNUM )
SetWindowLong_ ( GadgetID ( GadNUM ), #GWL_STYLE, GetWindowLong_ ( GadgetID ( GadNUM ), #GWL_STYLE) | #WS_CLIPSIBLINGS )
SetWindowPos_ ( GadgetID ( GadNUM ), GadgetID ( GadNUM ), 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE )
EndMacro
Global gWindowID.l
Global gStatusBar.l
Global gOldContainerProc1.l
Global gOldContainerProc2.l
Global ghBrushBack2.l
;/===============================================
;/ Procedure: SizeBackImage
;/===============================================
Procedure.l SizeBackImage(hwnd, *rc.RECT)
Protected hdc, dc
If IsImage(#lv_image)
ResizeImage ( #lv_image, *rc\right-*rc\left, *rc\bottom-*rc\top)
Else
CreateImage ( #lv_image, *rc\right-*rc\left, *rc\bottom-*rc\top)
EndIf
hdc=StartDrawing ( ImageOutput ( #lv_image ) )
dc = CreateCompatibleDC_(hdc)
If dc
SelectObject_(dc,ImageID ( #MainImage ) )
StretchBlt_(hdc, 0,0,*rc\right-*rc\left, *rc\bottom-*rc\top,dc,0,0,ImageWidth ( #MainImage ),ImageHeight ( #MainImage ),#SRCCOPY)
DeleteDC_(dc)
result=1
Else
result=0
EndIf
StopDrawing()
ProcedureReturn result
EndProcedure
Procedure ContainerProc1 ( hwnd.l, msg.l, wParam.l, lParam.l )
Protected gadRc.RECT, lvDc, bgDc
;...
If msg = #WM_ERASEBKGND
GetClientRect_ ( hwnd, gadRc )
SizeBackImage ( hwnd, gadRc )
lvDc = GetDC_ ( hwnd )
;...Get image DC
bgDc = StartDrawing(ImageOutput(#lv_image))
BitBlt_ ( lvDc, 0, 0, gadRc\right - gadRc\left, gadRc\bottom - gadRc\top, bgDc, 0, 0, #SRCCOPY)
;... Clean up
ReleaseDC_ ( hwnd, lvDc )
StopDrawing()
ProcedureReturn 0
EndIf
ProcedureReturn CallWindowProc_ ( gOldContainerProc1, hwnd, msg, wParam, lParam )
EndProcedure
Procedure Open_MainWindow()
Protected hwnd.l
Protected winopts.l
Protected font.l
winopts = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_WindowCentered
hwnd = OpenWindow ( #MainWindow, 34, 25, 400, 340, "test", winopts )
If Not hwnd
ProcedureReturn #False
EndIf
gWindowID = WindowID ( #MainWindow )
gStatusBar = CreateStatusBar ( #MainWindow, gWindowID )
If Not gStatusBar
ProcedureReturn #False
EndIf
AddStatusBarField ( #SBSizeMain )
AddStatusBarField ( #SBSizeField )
AddStatusBarField ( #SBSizeField )
If Not CreateGadgetList ( gWindowID )
ProcedureReturn #False
EndIf
CatchImage ( #Button1, ?btn1 )
CatchImage ( #Button2, ?btn2 )
CatchImage ( #Button3, ?btn3 )
CatchImage ( #MainImage, ?background )
ButtonImageGadget ( #BTN2www, 250, 4, 100, 24, ImageID ( #Button3 ) )
CreateTB ( #MainTB, hwnd, 24, 24, #TBpro_FLAT | #TBpro_TRANSPARENT | #TBpro_BORDER )
SetTBimage ( 0, 0, #TBpro_NORMAL )
SetTBimage ( 0, 0, #TBpro_HOT )
SetTBimage ( 0, 0, #TBpro_DISABLED )
AddTBsysIcons ()
AddTBbutton ( #TBButton1, #TBpro_CUT, #TBpro_BUTTON )
AddTBbutton ( #TBButton2, #TBpro_PASTE, #TBpro_BUTTON )
AddTBseparator ( 12 )
AddTBbutton ( #TBButton3, #TBpro_DELETE, #TBpro_CheckBUTTON )
AddTBbutton ( #TBButton4, #TBpro_FIND, #TBpro_CheckBUTTON )
AddTBbutton ( #TBButton5, #TBpro_REPLACE, #TBpro_CheckBUTTON )
AddTBseparator ( 12 )
UpdateTB ()
UseTB ( #MainTB )
AddTBgadget ( GadgetID ( #BTN2www ), 250, 4 )
font = LoadFont ( #StaticTextFont, "Palatino", 11, #PB_Font_Bold )
ContainerGadget ( #Container1, 0, #CONTAINER_Y, #CONTAINER_SIZEX, #CONTAINER_SIZEY )
ButtonGadget ( #TestButton1, 50, 80, 100, 50, "Test Button 1" )
ButtonGadget ( #TestButton2, 250, 80, 100, 50, "Test Button 2" )
StringGadget ( #TextGadget1, 50, 30, 200, 25, "" )
CloseGadgetList()
gOldContainerProc1 = SetWindowLong_ ( GadgetID ( #Container1 ), #GWL_WNDPROC, @ContainerProc1() )
ProcedureReturn #True
EndProcedure
Procedure Open_AboutWindow ()
Protected hwnd.l
Protected winopts.l
Protected font.l
Protected id.l
winopts = #PB_Window_WindowCentered
hwnd = OpenWindow ( #AboutWindow, 0, 0, 380, 200, "About - Test", winopts, gWindowID )
If Not hwnd
ProcedureReturn #False
EndIf
id = WindowID ( #AboutWindow )
If Not CreateGadgetList ( id )
ProcedureReturn #False
EndIf
ghBrushBack2 = CreatePatternBrush_ ( ImageID ( #MainImage ) )
font = LoadFont ( #StaticTextFont, "Garamond", 12, #PB_Font_Bold )
ContainerGadget ( #Container2, 0, 0, 380, 200 )
ButtonGadget ( #TestButton3, 40, 40, 95, 35, "Close" )
StringGadget ( #TextGAdget2, 40, 140, 300, 20, "" )
CloseGadgetList()
GadIMG ( #Container2, ghBrushBack2 )
ProcedureReturn #True
EndProcedure
Procedure Main ()
Protected id.l, idpos.l ,result.l
Protected EventID.l
Protected ButtonState.l
Protected nEvents.l
If Open_MainWindow()
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
nEvents = EventGadget()
If nEvents = #TestButton3
CloseWindow ( #AboutWindow )
ElseIf nEvents = #TestButton1 Or nEvents = #TestButton2
Open_AboutWindow ()
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
EndIf
EndProcedure
Main()
End
;- Data Section
DataSection
background: IncludeBinary "back.bmp"
btn1: IncludeBinary "buttona.BMP"
btn2: IncludeBinary "buttonb.BMP"
btn3: IncludeBinary "buttonc.BMP"
EndDataSection
KingLestat
**EDIT
Thanks to srod's suggestion and (again) from srod own posts I found a routine SizeBackImage which seems to do the job + some other of er...srods code again...modified the callback routine