The following code does not work with PureBasic.
(I'm using API calls and not PureBasic native code)
This code works fine using FreeBasic.
Please help.
Thanks
ly
Code: Select all
Declare SetWinColor(hWnd, clr)
Global wc.WNDCLASSEX, hInstance, msg.MSG
hInstance = GetModuleHandle_( null )
Enumeration
#Button_1
#Button_2
#Button_3
EndEnumeration
#Style = #WS_OVERLAPPEDWINDOW | #WS_VISIBLE
Procedure WindowCallback(hWnd, uMsg, wParam, lParam)
Select uMsg
Case #WM_CREATE
hBtn1 = CreateWindowEx_(0, "Button", "Exit", #WS_CHILD | #WS_VISIBLE, 520, 328, 60, 25, hWnd, #Button_1, hInstance, 0)
hBtn2 = CreateWindowEx_(0, "Button", "RED", #WS_CHILD | #WS_VISIBLE, 440, 328, 60, 25, hWnd, #Button_2,hInstance, 0)
hBtn2 = CreateWindowEx_(0, "Button", "BLUE", #WS_CHILD | #WS_VISIBLE, 360, 328, 60, 25, hWnd, #Button_3, hInstance, 0)
Case #WM_COMMAND
Select wParam
Case #Button_1
Debug "#Button_1"
PostQuitMessage_(0)
Case #Button_2
Debug "#Button_2"
SetWinColor(hWnd,RGB(233,95,85))
InvalidateRect_(hWnd,False,True)
UpdateWindow_(hWnd)
Case #Button_3
Debug "#Button_3"
SetWinColor(hWnd, RGB(85,95,233))
InvalidateRect_(hWnd,False,True)
UpdateWindow_(hWnd)
EndSelect
Case #WM_CLOSE
DestroyWindow_(Window)
Result = 0
Case #WM_DESTROY
PostQuitMessage_(0)
Result = 0
Default
Result = DefWindowProc_(hWnd, uMsg, wParam, lParam)
EndSelect
ProcedureReturn Result
EndProcedure
Define.s appName
appName = "Win32"
wc\style = #CS_HREDRAW | #CS_VREDRAW
wc\cbsize = SizeOf(WNDCLASSEX)
wc\lpfnWndProc = @WindowCallback()
wc\hInstance = hInstance
wc\hIcon = LoadIcon_(0, #IDI_APPLICATION )
wc\hCursor = LoadCursor_(0,#IDC_ARROW)
wc\hbrBackground = #COLOR_WINDOW + 1
wc\lpszMenuName = 0
wc\lpszClassName = @appName
; RegisterClassEx_(@wc)
If ( RegisterClassEx_( @wc ) = false )
MessageBox_( null, "Failed to register wc!", appName, #MB_ICONERROR )
End 1
EndIf
hWnd = CreateWindowEx_(0, appName, "Simple", #Style, 100, 100, 600, 450, 0, 0, hInstance, 0)
ShowWindow_(hWnd, #SW_SHOWDEFAULT)
UpdateWindow_(hWnd)
SetForegroundWindow_(hWnd)
While GetMessage_(msg, 0, 0, 0 )
TranslateMessage_(msg)
DispatchMessage_(msg)
Wend
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Procedure SetWinColor(hWnd, clr)
Static obj, hbr
hbr = CreateSolidBrush_(clr)
obj = SetClassLongPtr_(hWnd ,#GCL_HBRBACKGROUND ,hbr)
DeleteObject_(obj)
RedrawWindow_(hWnd, 0, 0, 0)
ProcedureReturn 0
EndProcedure