Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
freeBASIC (a 32-bit QB-syntax compatible compiler) preview..
#38
Check this out, simple gui program with freebasic. It took us a long time to get it to work becuase we both suck at gui coding and v1ctor thought it was the compiler that was messing up. Turns out it wasn't. Sure, looks messy. Windows guis are messy. But look at the same code in C, it's even worse. Anyways, if you really look at it carefully it's not that bad. http://freebasic.bad-logic.com/downloads/winhello.zip

Code:
''
'' winhello.bas - Windows Gui example with freebasic
''
''
defint a-z
option explicit
option private

'$include:'kernel32.bi'
'$include:'user32.bi'
'$include:'gdi32.bi'


const null              = 0
const true              = -1
const false             = 0


declare function        WinMain     ( byval hInstance as long, _
                                      byval hPrevInstance as long, _
                                      szCmdLine as string, _
                                      byval iCmdShow as integer ) as integer

dim res as integer


                                  
                                  
    ''
    '' Entry point    
    ''
    res = WinMain( GetModuleHandle( null ), null, command$, SW_NORMAL )
    end res
    
    
    


'' ::::::::
'' name: WndProc
'' desc: Processes windows messages
''
'' ::::::::
defint a-z
function WndProc ( byval hWnd as long, _
                   byval message as long, _
                   byval wParam as long, _
                   byval lParam as long ) as integer
    dim rct as RECT
    dim pnt as PAINTSTRUCT
    dim hDC as long
    
    WndProc = 0
    
    ''
    '' Process message
    ''
    select case ( message )  
        
        case WM_CREATE            
            exit function
        
        ''
        '' Windows is being repainted
        ''
        case WM_PAINT
          
            hDC = BeginPaint( hWnd, pnt )
            GetClientRect hWnd, rct
            
            DrawText hDC,"Hello Windows from FreeBasic!", -1, _
                     rct, DT_SINGLELINE or DT_CENTER or DT_VCENTER
            
            EndPaint hWnd, pnt
            
            exit function            
        
        ''
        '' Window was closed
        ''
        case WM_DESTROY
            PostQuitMessage 0            
            exit function
    end select
    
    ''
    '' Message doesn't concern us, send it to the default handler
    '' and get result
    ''
    WndProc = DefWindowProc( hWnd, message, wParam, lParam )    
    
end function




'' ::::::::
'' name: WinMain
'' desc: A win2 gui program entry point
''
'' ::::::::
defint a-z
function WinMain ( byval hInstance as long, _
                   byval hPrevInstance as long, _
                   szCmdLine as string, _
                   byval iCmdShow as integer ) as integer    
    
     dim wMsg as MSG
     dim wcls as WNDCLASS    
     dim szAppName as string
     dim hWnd as long

    
     WinMain = 0
    
     ''
     '' Setup window class
     ''
     szAppName = "HelloWin"
    
     wcls.style         = CS_HREDRAW or CS_VREDRAW
     wcls.lpfnWndProc   = procptr( WndProc() )
     wcls.cbClsExtra    = 0
     wcls.cbWndExtra    = 0
     wcls.hInstance     = hInstance
     wcls.hIcon         = LoadIcon( null, IDI_APPLICATION )
     wcls.hCursor       = LoadCursor( null, IDC_ARROW )
     wcls.hbrBackground = GetStockObject( WHITE_BRUSH )
     wcls.lpszMenuName  = null
     wcls.lpszClassName = sadd( szAppName )
    
    
     ''
     '' Register the window class    
     ''    
     if ( RegisterClass( wcls ) = false ) then
        MessageBox null, "This program requires Windows NT!", szAppName, MB_ICONERROR              
        exit function
    end if
    
    

    ''
    '' Create the window and show it
    ''
    hWnd = CreateWindowEx( 0, _
                 szAppName, _
                         "The Hello Program", _
                          WS_OVERLAPPEDWINDOW, _
                          CW_USEDEFAULT, _
                          CW_USEDEFAULT, _
                          CW_USEDEFAULT, _
                          CW_USEDEFAULT, _
                          null, _
                          null, _
                          hInstance, _
                          null )
                          

    ShowWindow   hWnd, iCmdShow
    UpdateWindow hWnd
    

    ''
    '' Process windows messages
    ''
    while ( GetMessage( wMsg, null, 0, 0 ) <> false )    
        TranslateMessage wMsg
        DispatchMessage  wMsg
    wend
    
    
    ''
    '' Program has ended
    ''
    WinMain = wMsg.wParam

end function
oship me and i will give you lots of guurrls and beeea
Reply


Messages In This Thread
Excelent work! - by Ravyne - 10-28-2004, 11:43 AM
freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - by Blitz - 10-30-2004, 06:07 AM
First impression... - by ToohTooh - 11-01-2004, 03:30 PM
Random naive questions - by dilettante - 11-14-2004, 10:39 AM

Forum Jump:


Users browsing this thread: 6 Guest(s)