Button color mouseover issue

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 1318
Joined: Sun May 14, 2017 1:48 am

Re: Button color mouseover issue

Post by AZJIO »

Code: Select all

EnableExplicit
Declare MyWindowCallback(hWin, Msg, wParam, lParam)
#BCN_HOTITEMCHANGE = -1249
#img0 = 0
#img1 = 1

Structure NMBHOTITEM Extends NMHDR
	dwFlags.l
EndStructure

Global k = 0, btn1, btn2 

OpenWindow(0, 0, 0, 350, 170,"", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget)

EditorGadget(1, 2, 45, 345, 122, #ES_AUTOVSCROLL | #WS_VSCROLL | #ES_NOHIDESEL | #ES_WANTRETURN)
SetGadgetText(1, "Hover the cursor over the button")
; GetGadgetColor(1 , $fffbd7)

If CreateImage(#img0, 70, 25) And StartDrawing(ImageOutput(#img0))
	Box(#img0, 0, 70, 25, RGB(Random(255), Random(255), Random(255)))
	StopDrawing()
EndIf

If CreateImage(#img1, 70, 25) And StartDrawing(ImageOutput(#img1))
	Box(#img1, 0, 70, 25, RGB(Random(255), Random(255), Random(255)))
	StopDrawing()
EndIf

; LoadImage(0, "pic1.bmp")
; LoadImage(1, "pic2.bmp")


btn1 = ButtonImageGadget(2, 100, 10, 70, 25, ImageID(#img0))
btn2 = ButtonImageGadget(3, 200, 10, 70, 25, ImageID(#img0))

SetWindowCallback(@MyWindowCallback())

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Procedure MyWindowCallback(hWin, Msg, wParam, lParam)
	Protected Text$
	Protected Result = #PB_ProcessPureBasicEvents
	Protected *pnmhdr.NMHDR = lParam
	Protected *pnmbh.NMBHOTITEM
	
	Select Msg
		Case #WM_NOTIFY
			k + 1
			SetWindowTitle(0 , "Call " + k + " ID =" + wParam)
			Select *pnmhdr\hWndFrom
				Case btn1, btn2
					*pnmbh.NMBHOTITEM=lParam
					Text$ = ""
					Select *pnmbh\Code
						Case #BCN_HOTITEMCHANGE
							If *pnmbh\dwFlags & 16
								Text$ = "hovered"
								SetGadgetAttribute(*pnmhdr\IDFrom, #PB_Button_Image, ImageID(#img1))
							ElseIf *pnmbh\dwFlags & 32
								Text$ = "abandoned"
								SetGadgetAttribute(*pnmhdr\IDFrom, #PB_Button_Image, ImageID(#img0))
							EndIf
							SetGadgetText(1, 
							              "Button " + GetGadgetText(*pnmhdr\IDFrom) + " " + Text$ + #CRLF$ + 
							              "identifier" + #TAB$ + Str(*pnmbh\IDFrom) + #CRLF$ + 
							              "handle:" + #TAB$ + Str(*pnmhdr\hWndFrom))
					EndSelect
			EndSelect
	EndSelect
	
	ProcedureReturn Result
EndProcedure


Code: Select all

EnableExplicit
Declare MyWindowCallback(hWin, Msg, wParam, lParam)
#BCN_HOTITEMCHANGE = -1249
#img0 = 0
#img1 = 1

Structure NMBHOTITEM Extends NMHDR
	dwFlags.l
EndStructure

Global k = 0, btn1, btn2, hDC, Color

OpenWindow(0, 0, 0, 350, 170,"", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget)

EditorGadget(1, 2, 45, 345, 122, #ES_AUTOVSCROLL | #WS_VSCROLL | #ES_NOHIDESEL | #ES_WANTRETURN)
SetGadgetText(1, "Hover the cursor over the button")
; GetGadgetColor(1 , $fffbd7)
Global hIcon, hfont
ExtractIconEx_("C:\WINDOWS\System32\Shell32.dll", 3, 0, @hIcon, 1)
hfont = LoadFont(0, "Arial", 11, #PB_Font_HighQuality)

If CreateImage(#img0, 110, 30) And StartDrawing(ImageOutput(#img0))
	Color = RGB(Random(255), Random(255), Random(255))
	Box(#img0, 0, 110, 30, Color)
	DrawingFont(hfont)
	DrawText(32, 6, "PureBasic", $000000, Color)
	DrawImage(hIcon, 7, 7)
	StopDrawing()
EndIf

If CreateImage(#img1, 110, 30) And StartDrawing(ImageOutput(#img1))
	Color = RGB(Random(255), Random(255), Random(255))
	Box(#img1, 0, 110, 30, Color)
	DrawingFont(hfont)
	DrawText(32, 6, "PureBasic", $000000, Color)
	DrawImage(hIcon, 7, 7)
	StopDrawing()
EndIf

; LoadImage(0, "pic1.bmp")
; LoadImage(1, "pic2.bmp")


btn1 = ButtonImageGadget(2, 80, 10, 110, 30, ImageID(#img0))
btn2 = ButtonImageGadget(3, 200, 10, 110, 30, ImageID(#img0))

SetWindowCallback(@MyWindowCallback())

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Procedure MyWindowCallback(hWin, Msg, wParam, lParam)
	Protected Text$
	Protected Result = #PB_ProcessPureBasicEvents
	Protected *pnmhdr.NMHDR = lParam
	Protected *pnmbh.NMBHOTITEM
	
	Select Msg
		Case #WM_NOTIFY
			k + 1
			SetWindowTitle(0 , "Call " + k + " ID =" + wParam)
			Select *pnmhdr\hWndFrom
				Case btn1, btn2
					*pnmbh.NMBHOTITEM=lParam
					Text$ = ""
					Select *pnmbh\Code
						Case #BCN_HOTITEMCHANGE
							If *pnmbh\dwFlags & 16
								Text$ = "hovered"
								SetGadgetAttribute(*pnmhdr\IDFrom, #PB_Button_Image, ImageID(#img1))
							ElseIf *pnmbh\dwFlags & 32
								Text$ = "abandoned"
								SetGadgetAttribute(*pnmhdr\IDFrom, #PB_Button_Image, ImageID(#img0))
							EndIf
							SetGadgetText(1, 
							              "Button " + " " + Text$ + #CRLF$ + 
							              "identifier" + #TAB$ + Str(*pnmbh\IDFrom) + #CRLF$ + 
							              "handle:" + #TAB$ + Str(*pnmhdr\hWndFrom))
					EndSelect
			EndSelect
	EndSelect
	
	ProcedureReturn Result
EndProcedure
Post Reply