#Include "Demo.bi"

hInstance = GetModuleHandle(NULL)
iccex.dwSize = SizeOf(INITCOMMONCONTROLSEX)
iccex.dwICC = ICC_BAR_CLASSES or ICC_WIN95_CLASSES
InitCommonControlsEx(@iccex)
ExitProcess(DialogBoxParam(hInstance,Cast(LPCSTR,1001),0,@DlgProc,0))
'=====================================================================

Function DlgProc(hWnd As HWND,iMsg As DWORD,wParam As WPARAM, lParam As LPARAM) As Integer

	Dim BtnStruct As XXBUTTON
	Dim hBtn      As HWND
	Dim Rct       As RECT

	If	iMsg = WM_INITDIALOG Then

		zeromemory(@BtnStruct, sizeof(XXBUTTON))

		'========================About========================================
		BtnStruct.hIcon_normal = LoadIcon(hInstance,Cast(LPCSTR,IDI_ABOUT))
		BtnStruct.hIcon_hover = FALSE
		BtnStruct.m_flat = TRUE
		BtnStruct.m_border = TRUE
		BtnStruct.m_IconAlign = BS_LEFT
		BtnStruct.hCursor_hover = LoadCursor(NULL, IDC_HAND)
		hBtn = GetDlgItem(hWnd, IDC_ABOUT )
		RedrawButton(hBtn, @BtnStruct)
		'========================Left Icon ===================================
		BtnStruct.hIcon_normal = LoadIcon(hInstance,Cast(LPCSTR, IDI_OK ))
		BtnStruct.m_flat = FALSE
		BtnStruct.m_IconAlign = BS_LEFT
		BtnStruct.hCursor_hover = 0
		hBtn = GetDlgItem(hWnd, IDC_BUTTONLEFT )
		RedrawButton(hBtn, @BtnStruct)
		'========================Right Icon====================================
		BtnStruct.m_IconAlign = BS_RIGHT
		hBtn = GetDlgItem(hWnd, IDC_BUTTONRIGHT )
		RedrawButton(hBtn, @BtnStruct)
		'========================Top Icon======================================
		BtnStruct.hIcon_normal = LoadIcon(hInstance, Cast(LPCSTR,IDI_CANSEL ))
		BtnStruct.m_IconAlign = BS_TOP
		hBtn = GetDlgItem(hWnd, IDC_BUTTONTOP )
		RedrawButton(hBtn, @BtnStruct)
		'========================Only Icon - Left==============================
		BtnStruct.hIcon_normal = LoadIcon(hInstance,Cast(LPCSTR, IDI_LEFT ))
		BtnStruct.m_flat = TRUE
		hBtn = GetDlgItem(hWnd, IDC_SLEFT )
		RedrawButton(hBtn, @BtnStruct)
		'========================Only Icon - Right=============================
		BtnStruct.hIcon_normal = LoadIcon(hInstance, Cast(LPCSTR,IDI_RIGHT ))
		hBtn = GetDlgItem(hWnd, IDC_SRIGHT )
		RedrawButton(hBtn, @BtnStruct)
		'========================Only Text=====================================
		BtnStruct.hIcon_normal = 0
		hBtn = GetDlgItem(hWnd, IDC_TEXT )
		RedrawButton(hBtn, @BtnStruct)
		'========================Disabled======================================
		BtnStruct.hIcon_normal = LoadIcon(hInstance,Cast(LPCSTR, IDI_OK ))
		BtnStruct.m_flat = FALSE
		BtnStruct.m_IconAlign = BS_LEFT
		hBtn = GetDlgItem(hWnd, IDC_DISABLED )
		RedrawButton(hBtn,@BtnStruct)
		'========================Flat Disabled=================================
		BtnStruct.hIcon_normal = LoadIcon(hInstance, Cast(LPCSTR,IDI_OK ))
		BtnStruct.m_flat = TRUE
		BtnStruct.m_IconAlign = BS_TOP
		hBtn = GetDlgItem(hWnd, IDC_FLATDISABLED )
		RedrawButton(hBtn, @BtnStruct)
		'========================Lamp Flat=====================================
		BtnStruct.hIcon_normal = LoadIcon(hInstance, Cast(LPCSTR,IDI_LAMP2 ))
		BtnStruct.hIcon_hover = LoadIcon(hInstance, Cast(LPCSTR,IDI_LAMP1 ))
		BtnStruct.m_flat = TRUE
		hBtn = GetDlgItem(hWnd, IDC_LAMP )
		RedrawButton(hBtn, @BtnStruct)
		'========================Lamp2=========================================
		BtnStruct.hIcon_normal = LoadIcon(hInstance, Cast(LPCSTR,IDI_LAMP2 ))
		BtnStruct.hIcon_hover = LoadIcon(hInstance, Cast(LPCSTR,IDI_LAMP1 ))
		BtnStruct.m_border = FALSE
		hBtn = GetDlgItem(hWnd, IDC_LAMP2 )
		RedrawButton(hBtn, @BtnStruct)

		'========================Light Text ===================================
		BtnStruct.hIcon_normal = NULL
		BtnStruct.hIcon_hover = NULL
		BtnStruct.m_border = TRUE
		BtnStruct.m_IconAlign = BS_LEFT

		BtnStruct.m_flat = FALSE

		BtnStruct.hover_clr = BGR( 0, 0, 255)
		BtnStruct.push_clr = BGR( 128, 128, 0)
		BtnStruct.normal_clr = BGR(128, 0, 96)

		hBtn = GetDlgItem(hWnd, IDC_NTEXT )
		RedrawButton(hBtn, @BtnStruct)
		'========================Link==========================================
		BtnStruct.hIcon_normal = NULL
		BtnStruct.hIcon_hover = NULL
		BtnStruct.m_border = FALSE

		hFnt = CreateFontIndirect(@lgFnt)
		BtnStruct.hFont_normal = hFnt

		hFntFocus = CreateFontIndirect(@lgFntFocus)
		BtnStruct.hFont_hover = hFntFocus

		LoadCursor(NULL, IDC_HAND)
		BtnStruct.hCursor_hover = LoadCursor(NULL, IDC_HAND)

		BtnStruct.Sound_hover = LoadResource(NULL, FindResource(NULL,Cast(LPCSTR, IDW_HOVER), RT_RCDATA))

		hBtn = GetDlgItem(hWnd, IDC_LINK )
		RedrawButton(hBtn, @BtnStruct)

		'========================Bitmap buttons=================================
		'=======================================================================
		'============================Noise======================================

		backASM:

		zeromemory(@BtnStruct, sizeof(XXBUTTON))

		BtnStruct.hIcon_normal = NULL
		BtnStruct.hIcon_hover = NULL
		BtnStruct.m_border = TRUE
		BtnStruct.hFont_normal = NULL
		BtnStruct.hFont_hover = NULL
		BtnStruct.hCursor_hover = NULL
		BtnStruct.Sound_hover = NULL
		BtnStruct.hover_clr = NULL
		BtnStruct.push_clr = NULL
		BtnStruct.normal_clr = NULL

		hBtn = GetDlgItem(hWnd, IDC_NOISE )
		GetWindowRect(hBtn, @Rct)
		hBmpNoiseNormal = CreateFillBmp(FILL_NOISE, @Rct, 30, 15, 0, 0 )
		Asm
			mov [hBmpNoiseHover], edx
		End Asm
		BtnStruct.hBitmap_hover = hBmpNoiseHover
		BtnStruct.hBitmap_normal = hBmpNoiseNormal
		RedrawButton(hBtn,@BtnStruct)

		'========================Soft Bump=====================================

		hBtn = GetDlgItem(hWnd, IDC_SOFTBUMP )
		GetWindowRect(hBtn, @Rct)
		hBmpSoftBumpNormal = CreateFillBmp(FILL_SOFTBUMP, @Rct, 8, 10, 0, 0)
		Asm
			mov [hBmpSoftBumpHover],edx
		End Asm
		BtnStruct.hBitmap_hover = hBmpSoftBumpHover
		BtnStruct.hBitmap_normal = hBmpSoftBumpNormal
		RedrawButton(hBtn, @BtnStruct)

		'========================V Bump========================================

		hBtn = GetDlgItem(hWnd, IDC_VBUMP )
		GetWindowRect(hBtn, @Rct)
		hBmpVBumpNormal = CreateFillBmp(FILL_VBUMP, @Rct, 8, 20, 5,BGR (55,55,255))
		Asm
			mov [hBmpVBumpHover],edx
		End Asm
		BtnStruct.hBitmap_hover = hBmpVBumpHover
		BtnStruct.hBitmap_normal = hBmpVBumpNormal
		RedrawButton(hBtn, @BtnStruct)

		'========================H Bump========================================

		hBtn = GetDlgItem(hWnd, IDC_HBUMP )
		GetWindowRect(hBtn, @Rct)
		hBmpHBumpNormal = CreateFillBmp(FILL_HBUMP, @Rct, 8, 20, 5, BGR(55,55,255))
		Asm
			mov [hBmpHBumpHover], edx
		End Asm
		BtnStruct.hBitmap_hover = hBmpHBumpHover
		BtnStruct.hBitmap_normal = hBmpHBumpNormal
		RedrawButton(hBtn, @BtnStruct)

		'========================H Shade========================================

		hBtn = GetDlgItem(hWnd, IDC_HSHADE )
		GetWindowRect(hBtn, @Rct)
		hBmpHShadeNormal = CreateFillBmp(FILL_HSHADE,@Rct, 8, 20, 5,BGR(55,55,255))
		Asm
			mov [hBmpHShadeHover], edx
		End Asm
		BtnStruct.hBitmap_hover = hBmpHShadeHover
		BtnStruct.hBitmap_normal = hBmpHShadeNormal
		RedrawButton(hBtn,@BtnStruct)

		'========================V Shade========================================

		hBtn = GetDlgItem(hWnd, IDC_VSHADE )
		GetWindowRect(hBtn, @Rct)
		hBmpVShadeNormal = CreateFillBmp(FILL_VSHADE, @Rct, 8, 20, 5, BGR(55,55,255))
		Asm
			mov [hBmpVShadeHover], edx
		End Asm
		BtnStruct.hBitmap_hover = hBmpVShadeHover
		BtnStruct.hBitmap_normal = hBmpVShadeNormal
		RedrawButton(hBtn, @BtnStruct)

		'========================Diagonal Shade=================================

		hBtn = GetDlgItem(hWnd, IDC_DIAGSHADE )
		GetWindowRect(hBtn, @Rct)
		hBmpDShadeNormal = CreateFillBmp(FILL_DIAGSHADE, @Rct, 8, 20, 10, bgr(80,255,220))
		Asm
			mov [hBmpDShadeHover], edx
		End Asm
		BtnStruct.hBitmap_hover = hBmpDShadeHover
		BtnStruct.hBitmap_normal = hBmpDShadeNormal
		BtnStruct.hover_clr = BGR(0, 50, 255)
		BtnStruct.normal_clr = BGR(168, 0, 96)
		RedrawButton(hBtn, @BtnStruct)

		'========================Hard Bump======================================

		hBtn = GetDlgItem(hWnd, IDC_HARDBUMP )
		GetWindowRect(hBtn, @Rct)
		hBmpHardBumpNormal = CreateFillBmp(FILL_HARDBUMP, @Rct, 8, 10, 0, 0)
		Asm
			mov [hBmpHardBumpHover], edx
		End Asm
		BtnStruct.hBitmap_hover = hBmpHardBumpHover
		BtnStruct.hBitmap_normal = hBmpHardBumpNormal
		BtnStruct.hover_clr = 0
		BtnStruct.push_clr = 0
		BtnStruct.normal_clr = 0
		RedrawButton(hBtn,@BtnStruct)

		'========================Metal==========================================

		hBtn = GetDlgItem(hWnd, IDC_METAL )
		GetWindowRect(hBtn,@Rct)
		hBmpMetalNormal = CreateFillBmp(FILL_METAL,@Rct, 8, 10, 0, 0 )
		Asm
			mov [hBmpMetalHover], edx
		End Asm
		BtnStruct.hBitmap_hover = hBmpMetalHover
		BtnStruct.hBitmap_normal = hBmpMetalNormal
		RedrawButton(hBtn, @BtnStruct)

		'========================User===========================================

		hBtn = GetDlgItem(hWnd, IDC_USERBMP )
		GetWindowRect(hBtn, @Rct)
		BtnStruct.hBitmap_normal = LoadBitmap(hInstance,Cast(LPCSTR, 500))
		BtnStruct.hBitmap_hover = LoadBitmap(hInstance, Cast(LPCSTR,501))
		BtnStruct.hBitmap_push = LoadBitmap(hInstance, Cast(LPCSTR,502))

		BtnStruct.m_border = FALSE
		RedrawButton(hBtn,@BtnStruct)

		'========================Exit=========================================
		BtnStruct.m_flat = FALSE
		BtnStruct.m_border = TRUE
		BtnStruct.hBitmap_push = hBmpNoiseHover
		BtnStruct.hBitmap_normal = hBmpNoiseNormal
		BtnStruct.hBitmap_hover = hBmpNoiseHover
		BtnStruct.hCursor_hover = LoadCursor(hInstance, Cast(LPCSTR,ID_CUR1))

		hBtn = GetDlgItem(hWnd, IDC_EXIT )
		RedrawButton(hBtn,@BtnStruct)

	ElseIf iMsg = WM_SYSCOLORCHANGE Then

		DeleteBitmap()

		GOTO backASM

	ElseIf	iMsg = WM_CLOSE Then

		DeleteBitmap()
		DeleteObject(hFntFocus)
		DeleteObject(hFnt)
		EndDialog(hWnd, NULL)

	ElseIf iMsg = WM_COMMAND Then

		If	HIWORD(wParam) = BN_CLICKED Then
			If	LOWORD(wParam) = IDC_EXIT then
				SendMessage(hWnd, WM_CLOSE, NULL, NULL)
			ElseIf	LOWORD(wParam) = IDC_LINK Then
				ShellExecute(0, 0, "http://freebasic.narod.ru/" ,0 , 0, SW_SHOWNORMAL)
			EndIf
		EndIf

	Else

		Return FALSE

	EndIf

	Return TRUE

End Function

' Free gdi resource.

Sub DeleteBitmap()
	DeleteObject(hBmpNoiseNormal)
	DeleteObject(hBmpNoiseHover)
	DeleteObject(hBmpSoftBumpNormal)
	DeleteObject(hBmpSoftBumpHover)
	DeleteObject(hBmpVBumpNormal)
	DeleteObject(hBmpVBumpHover)
	DeleteObject(hBmpHBumpNormal)
	DeleteObject(hBmpHBumpHover)
	DeleteObject(hBmpHShadeNormal)
	DeleteObject(hBmpHShadeHover)
	DeleteObject(hBmpVShadeNormal)
	DeleteObject(hBmpVShadeHover)
	DeleteObject(hBmpDShadeNormal)
	DeleteObject(hBmpDShadeHover)
	DeleteObject(hBmpHardBumpNormal)
	DeleteObject(hBmpHardBumpHover)
	DeleteObject(hBmpMetalNormal)
	DeleteObject(hBmpMetalHover)
End Sub
