Mysoft

Untitled

Jan 13th, 2021
901
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define fbc -s console
  2. 'default.rc
  3.  
  4. #include once "windows.bi"
  5. #include once "win\commctrl.bi"
  6. #include once "crt.bi"
  7.  
  8. '*************** Enumerating our control id's ***********
  9. enum WindowControls
  10.   wcMain
  11.   wcButton  
  12.   wcEdit
  13.   wcLast
  14. end enum
  15.  
  16. dim shared as hwnd CTL(wcLast)       'controls
  17. dim shared as hinstance APPINSTANCE  'instance
  18. dim shared as hfont MyFont           'fonts
  19. dim shared as string sAppName        'AppName (window title 'prefix')
  20.  
  21. declare sub WinMain()
  22.  
  23. sAppName = "GUI Example"
  24. InitCommonControls()
  25. APPINSTANCE = GetModuleHandle(null)
  26. WinMain() '<- main function
  27.  
  28. ' *************** Procedure Function ****************
  29. function WndProc ( hWnd as HWND, message as UINT, wParam as WPARAM, lParam as LPARAM ) as LRESULT
  30.  
  31.   select case( message )
  32.   case WM_CREATE 'Window was created
  33.     if CTL(wcMain) then return 0
  34.     CTL(wcMain) = hwnd
  35.  
  36.     'just a macro to help creating controls
  37.     #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)
  38.     #define UpDn UPDOWN_CLASS
  39.    
  40.     const cStyle = WS_CHILD or WS_VISIBLE 'Standard style for buttons class controls :)    
  41.     const cUpDnStyle = cStyle or UDS_AUTOBUDDY' or UDS_SETBUDDYINT  
  42.     const cButtonStyle = cStyle  
  43.     const cLabelStyle = cStyle
  44.    
  45.     const cTxtStyle =  cStyle or ES_AUTOVSCROLL or WS_VSCROLL or ES_MULTILINE
  46.     const RichStyle = cStyle or ES_READONLY or ES_AUTOVSCROLL or WS_VSCROLL or ES_MULTILINE
  47.    
  48.     const cBrd = WS_EX_CLIENTEDGE
  49.    
  50.     ' **** Creating a Control ****
  51.     CreateControl( wcButton , null , "button" , "Click"       , cStyle      , 10 , 10 , 80 , 24   )        
  52.     CreateControl( wcEdit   , cBrd , "edit"   , "Hello World " , cTxtStyle  , 10 , 44 , 320 , 240 )
  53.    
  54.     ' **** Creating a font ****
  55.     var hDC = GetDC(hWnd) 'can be used for other stuff that requires a temporary DC
  56.     var nHeight = -MulDiv(12, GetDeviceCaps(hDC, LOGPIXELSY), 72) 'calculate size matching DPI
  57.    
  58.     MyFont = CreateFont(nHeight,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,0,0,DRAFT_QUALITY or ANTIALIASED_QUALITY,0,"Verdana")
  59.     ' **** Setting this font for all controls ****
  60.     for CNT as integer = wcMain to wcLast-1
  61.       SendMessage(CTL(CNT),WM_SETFONT,cast(wparam,MyFont),true)      
  62.     next CNT
  63.     SendMessage(CTL(wcEdit),EM_SETLIMITTEXT,0,0)
  64.    
  65.     ReleaseDC(hWnd,hDC)    
  66.    
  67.     SetFocus(hwnd)
  68.    
  69.   case WM_COMMAND 'Event happened to a control (child window)
  70.    
  71.     select case hiword(wparam)        
  72.     case EN_CHANGE
  73.       print SendMessage(CTL(wcEdit),WM_GETTEXTLENGTH,0,0)
  74.     case BN_CLICKED 'button click
  75.       select case lparam
  76.       case CTL(wcButton)      
  77.         Messagebox( hwnd , "Bye" , "Bye" , MB_ICONINFORMATION )
  78.         PostQuitMessage(0)
  79.       end select
  80.     end select
  81.  
  82.   case WM_DESTROY 'Windows was closed/destroyed
  83.     PostQuitMessage(0) ' to quit
  84.     return 0
  85.   end select
  86.  
  87.   ' *** if program reach here default predefined action will happen ***
  88.   return DefWindowProc( hWnd, message, wParam, lParam )
  89.    
  90. end function
  91.  
  92. ' *********************************************************************
  93. ' *********************** SETUP MAIN WINDOW ***************************
  94. ' ******************* This code can be ignored ************************
  95. ' *********************************************************************
  96.  
  97. sub WinMain ()
  98.  
  99.   dim wMsg as MSG
  100.   dim wcls as WNDCLASS
  101.   dim as HWND hWnd  
  102.    
  103.   '' Setup window class  
  104.    
  105.   with wcls
  106.     .style         = CS_HREDRAW or CS_VREDRAW
  107.     .lpfnWndProc   = @WndProc
  108.     .cbClsExtra    = 0
  109.     .cbWndExtra    = 0
  110.     .hInstance     = APPINSTANCE
  111.     .hIcon         = LoadIcon( APPINSTANCE, "FB_PROGRAM_ICON" )
  112.     .hCursor       = LoadCursor( NULL, IDC_ARROW )    
  113.     .hbrBackground = GetSysColorBrush( COLOR_BTNFACE )
  114.     .lpszMenuName  = NULL
  115.     .lpszClassName = strptr( sAppName )
  116.   end with
  117.    
  118.   '' Register the window class    
  119.   if( RegisterClass( @wcls ) = FALSE ) then
  120.     MessageBox( null, "Failed to register wcls!", sAppName, MB_ICONINFORMATION )
  121.     exit sub
  122.   end if
  123.    
  124.   '' Create the window and show it  
  125.   const cStyleEx = 0 'WS_EX_COMPOSITED or WS_EX_LAYERED
  126.   const cStyle   = WS_VISIBLE or WS_TILEDWINDOW or WS_CLIPCHILDREN
  127.   dim as RECT tWndRc = (0,0,640,480)
  128.   AdjustWindowRectEx( @tWndRc , cStyle , FALSE , cStyleEx )  
  129.   hWnd = CreateWindowEx(cStyleEx,sAppName,sAppName,cStyle, _
  130.   200,200,tWndRc.right-tWndRc.left,tWndRc.bottom-tWndRc.top,null,null,APPINSTANCE,0)
  131.  
  132.   '' Process windows messages
  133.   ' *** all messages(events) will be read converted/dispatched here ***
  134.   UpdateWindow( hWnd )
  135.  
  136.   while( GetMessage( @wMsg, NULL, 0, 0 ) <> FALSE )    
  137.     'if IsDialogMessage( hWnd ,@wMsg ) then continue while
  138.     TranslateMessage( @wMsg )
  139.     DispatchMessage( @wMsg )    
  140.   wend    
  141.  
  142. end sub
  143.  
  144.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×