Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define fbc -s console
- #include once "windows.bi"
- #include once "win\commctrl.bi"
- '*************** Enumerating our control id's ***********
- enum WindowControls
- wcMain
- wcStaticA
- wcStaticB
- wcStaticC
- wcLast
- end enum
- dim shared as hwnd CTL(wcLast) 'controls
- dim shared as hinstance APPINSTANCE 'instance
- dim shared as hfont MyFont,MyFont2 'fonts
- dim shared as string sAppName 'AppName (window title 'prefix')
- declare sub WinMain()
- sAppName = "GUI Test"
- InitCommonControls()
- APPINSTANCE = GetModuleHandle(null)
- WinMain() '<- main function
- dim shared as any ptr ButProc
- ' *************** Procedure Function ****************
- ' *********** ALL EVENTS WILL HAPPEN HERE ***********
- function WndProc ( hWnd as HWND, message as UINT, wParam as WPARAM, lParam as LPARAM ) as LRESULT
- select case( message )
- case WM_CREATE 'Window was created
- 'just a macro to help creating controls
- #define CreateControl( mID , mExStyle , mClass , mCaption , mStyle , mX , mY , mWid , mHei ) CTL(mID) = CreateWindowEx(mExStyle,mClass,mCaption,mStyle,mX,mY,mWid,mHei,hwnd,cast(hmenu,mID),APPINSTANCE,null)
- const cStyle = WS_CHILD or WS_VISIBLE
- const cButtonStyle = cStyle
- const cEditStyle = cStyle or ES_NUMBER or ES_RIGHT
- const cStaticLabel = cStyle or SS_RIGHT
- const cStaticFrame = cStyle or WS_DLGFRAME
- const cExBorder = WS_EX_CLIENTEDGE
- const TRACKBAR = TRACKBAR_CLASS
- CreateControl( wcStaticA , WS_EX_STATICEDGE , "static" , "WS_EX_STATICEDGE" , cStaticLabel , 16 , 16 , 100 , 128 )
- CreateControl( wcStaticB , WS_EX_CLIENTEDGE , "static" , " WS_EX_CLIENTEDGE" , cStaticLabel , 132 , 16 , 100 , 128 )
- CreateControl( wcStaticC , 0 , "static" , "WS_DLGFRAME" , cStaticFrame , 248 , 16 , 100 , 128 )
- ' **** Creating a font ****
- MyFont = CreateFont(-8,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,0,0,0,0,"MS Shell Dlg")
- MyFont2 = CreateFont(-8,0,-900,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,0,0,0,0,"MS Shell Dlg")
- ' **** Setting this font for all controls ****
- for CNT as integer = wcMain to wcLast-1
- SendMessage(CTL(CNT),WM_SETFONT,cast(wparam,MyFont),true)
- next CNT
- SendMessage(CTL(wcStaticB),WM_SETFONT,cast(wparam,MyFont2),true)
- case WM_CLOSE,WM_DESTROY 'Windows was closed/destroyed
- PostQuitMessage(0) ' to quit
- return 0
- end select
- ' *** if program reach here default predefined action will happen ***
- return DefWindowProc( hWnd, message, wParam, lParam )
- end function
- ' *********************************************************************
- ' *********************** SETUP MAIN WINDOW ***************************
- ' ******************* This code can be ignored ************************
- ' *********************************************************************
- sub WinMain ()
- dim wMsg as MSG
- dim wcls as WNDCLASS
- dim as HWND hWnd
- '' Setup window class
- with wcls
- .style = 0 'CS_HREDRAW or CS_VREDRAW or CS_SAVEBITS
- .lpfnWndProc = @WndProc
- .cbClsExtra = 0
- .cbWndExtra = 0
- .hInstance = APPINSTANCE
- .hIcon = LoadIcon( APPINSTANCE, "FB_PROGRAM_ICON" )
- .hCursor = LoadCursor( NULL, IDC_ARROW )
- .hbrBackground = cast(hBrush, COLOR_BTNFACE + 1) 'official hack!
- .lpszMenuName = NULL
- .lpszClassName = @" " 'strptr( sAppName )
- end with
- '' Register the window class
- var wATOM = cast(dword,RegisterClass( @wcls ))
- if( wATOM = FALSE ) then
- MessageBox( null, "Failed to register wcls!", sAppName, MB_ICONERROR )
- exit sub
- end if
- '' Create the window and show it
- hWnd = CreateWindowEx(null,cast(zstring ptr,wATOM),null,WS_VISIBLE or WS_TILEDWINDOW, _
- CW_USEDEFAULT,CW_USEDEFAULT,400,240,null,null,APPINSTANCE,NULL)
- SetforegroundWindow(hWnd)
- '' Process windows messages
- ' *** all messages(events) will be read converted/dispatched here ***
- UpdateWindow( hWnd )
- while( GetMessage( @wMsg, NULL, 0, 0 ) <> FALSE )
- 'TranslateMessage( @wMsg )
- DispatchMessage( @wMsg )
- wend
- end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement