Simple GUI example ?

New to FreeBASIC? Post your questions here.
softfoot
Posts: 34
Joined: Aug 31, 2020 3:45

Simple GUI example ?

Post by softfoot »

I have used FB quite a lot for simple Windows 7 console apps one of them provides access to a serial port for downloading screen images from an oscilloscope but have never needed a GUI interface before.

I would like to write a GUI interface for controlling a switch matrix it would initialy require just ten buttons on a small window on the main Windows screen, but have'nt been able to find a simple example.

Can anyone point me at a simmilar example to get me started ??

Regards,
Dave
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Simple GUI example ?

Post by srvaldez »

hello softfoot :)
there are 2 popular GUI designers for FB
WinFBE at https://www.planetsquires.com/protect/f ... board=37.0
VisualFBEditor at viewtopic.php?t=27284

WinFBE is a full package that includes the latest official FB distribution, VisualFBEditor is also a good choice
but if you want to have some fun with dialogs then see viewtopic.php?t=5667
I will post MichaelW's Dialog.bas and one of his examples because I had to make some minor changes to Dialog.bas in Sub GenUstring

Dialog.bas by MichaelW see viewtopic.php?t=5667

Code: Select all

'====================================================================
'' Version 0.5
''
''  Small modification for compatibility with 32 and 64-bit code.
''  See comment starting on line 343.
''
'' Version 0.4
''
''  Removed option explicit.
''
''  In the Control procedure changed "class" to "_class".
''
''  Added a ByRef to "lpdt as LPDLGTEMPLATE" and to all string
''  parameters, and added the ByVal that was missing on some of
''  the parameters of other types.
''
''  Should now work for 0.15b, 0.16b, and 0.17b up through the
''  CVS build from February 21, 2007.
''
'' Version 0.3
''
''  First release.
''
'====================================================================

'====================================================================
'' This module contains procedures and definitions to support the
'' creation of a dialog box template in allocated memory, and the
'' creation of a modal or modeless dialog from the template.
''
'' The dialog box template consists of a DLGTEMPLATE structure
'' followed by three or four variable-length arrays, followed by
'' zero or more DLGITEMTEMPLATE structures each followed by three
'' variable-length arrays. The DLGTEMPLATE structure and the
'' associated arrays define the dialog window. The DLGITEMTEMPLATE
'' structures and the associated arrays define the controls in the
'' dialog.
''
'' The variable-length arrays consist of WORD (16-bit) elements.
'' The first three arrays following the DLGTEMPLATE structure
'' specify the menu, class, and title for the dialog. The three
'' arrays following each DLGITEMTEMPLATE structure specify the
'' class, title, and creation data for the control. Each of these
'' arrays will have at least one element, and the system will
'' interpret the contents of the array based on the value of the
'' first element. For the dialog menu, class, and title arrays,
'' and the control creation data array, if the first element is
'' zero, then the array is effectively empty and there are no
'' other elements. For the dialog menu and class arrays, and the
'' control class and title arrays, if the first element is FFFFh,
'' then the second element contains the ordinal value of a
'' resource or a predefined class, and the array contains no other
'' elements. For the dialog menu, class, and title arrays, and the
'' control class and title arrays, if the first element is any
'' value other than zero or FFFFh, then the array is assumed to be
'' a null-terminated Unicode string. Depending on the array, this
'' Unicode string can specify the name of a menu resource, a
'' registered class, the dialog title, or the initial text for a
'' control. For the control creation data array, if the first
'' element is non-zero, then it contains the length, in bytes, of
'' the creation data that follows. The fourth array following the
'' DLGTEMPLATE structure, which is present only when the dialog
'' style includes DS_SETFONT, specifies the font point size value
'' in the first element, followed by the name of the typeface as
'' a null-terminated Unicode string.
''
'' This implementation does not permit a menu or class specification
'' for the dialog, or creation data for the controls.
''
'' The DLGTEMPLATE and DLGITEMTEMPLATE structures must be aligned
'' on a DWORD boundary. The variable-length arrays that follow the
'' structures must start on a WORD boundary, but with WORD-size
'' elements and the structure sizes and alignment requirements,
'' this should be automatic.
''
'' Prior to creating a dialog template your source must declare,
'' for each dialog, a pointer to a DLGTEMPLATE structure:
''
'' dim as LPDLGTEMPLATE lpdt
''
'' This pointer is used to store the starting address of the
'' template memory.
'====================================================================

#include once "windows.bi"
#include once "win\richedit.bi"
#include once "win\commctrl.bi"

'' This shared integer is used to implement automatic horizontal
'' centering of a control in a dialog.
''
dim shared as integer g_dialog_width

'' This shared pointer to a WORD is used by the Dialog and
'' control definition procedures to store the current address
'' in the template memory, and by the CreateModalDialog and
'' CreateModelessDialog procedures to resize the memory block
'' before the dialog is created. It is shared as a convenience,
'' because doing so eliminates one parameter from each of the
'' procedures.
''
dim shared as LPWORD g_lpw

'' Because of these shared variables dialog definitions cannot
'' be interleaved.

'====================================================================

'' This procedure generates a Unicode string starting at the
'' address specified by g_lpw, and then adds the length, in
'' wide characters, of the string and null terminator to g_lpw.
'' For compatibility with 95/98/Me, the MuliByteToWideChar
'' function is used to generate the strings.
''
sub GenUstring( byval asciiString as zstring ptr )

  '' If asciiString is null, skip the first element of
  '' the array, leaving it set to zero (no string).
  ''
  if *asciiString = "" then
    g_lpw += 1
  else
    '' CP_ACP specifies that the function should use
    '' the current system ANSI code page to perform
    '' the conversion to Unicode.
    ''
    'declare function MultiByteToWideChar(byval CodePage as UINT, byval dwFlags as DWORD, byval lpMultiByteStr as LPCCH, byval cbMultiByte as long, byval lpWideCharStr as LPWSTR, byval cchWideChar as long) as long

    g_lpw += MultiByteToWideChar( CP_ACP, _
                                  MB_PRECOMPOSED, _
                                  asciistring, _
                                  -1, _
                                  cast(LPWSTR,g_lpw), _
                                  len(*asciiString) + 2 )
  end if

end sub

'====================================================================

'' This function creates a modal dialog from the dialog box
'' template pointed to by lpdt. Parameter hParent should be
'' zero if the dialog is the main window of the application.
'' Parameter dwInitParam specifies a value that is passed to
'' the dialog box procedure in the lParam parameter of the
'' WM_INITDIALOG message.
''
'' The DialogBoxIndirectParam function does not return until
'' the dialog box is destroyed with the EndDialog function.
'' After freeing the allocated memory, this function returns
'' whatever was specified in the nResult parameter of the
'' EndDialog function.
''
function CreateModalDialog( byval hParent as HWND, _
                            byval lpDialogProc as DLGPROC, _
                            byval dwInitParam as LPARAM, _
                            byval lpdt as LPDLGTEMPLATE ) as integer

  dim as integer rval

  '' Resize the memory block to fit the template.
  ''
  GlobalReAlloc( lpdt,cast(integer,g_lpw) - cast(integer,lpdt),0 )

  rval = DialogBoxIndirectParam( GetModuleHandle(null), _
                                 lpdt, _
                                 hParent, _
                                 lpDialogProc, _
                                 dwInitParam )
  GlobalFree( lpdt )

  return rval

end function


'====================================================================

'' This function creates a modeless dialog from the dialog box
'' template pointed to by lpdt. Parameter hParent should be
'' zero if the dialog is the main window of the application.
'' Parameter lParamInit specifies a value that is passed to
'' the dialog box procedure in the lParam parameter of the
'' WM_INITDIALOG message.
''
'' After freeing the allocated memory, this function returns
'' whatever the CreateDialogIndirectParam function returned,
'' which would normally be the handle to the dialog window.
''
'' Note that the WS_VISIBLE style is required for a modeless
'' dialog to be visible.
''
function CreateModelessDialog( byval hParent as HWND, _
                               byval lpDialogProc as DLGPROC, _
                               byval lParamInit as LPARAM, _
                               byval lpdt as LPDLGTEMPLATE ) as HWND

  dim as HWND rval

  '' Resize the memory block to fit the template.
  ''
  GlobalReAlloc( lpdt,cast(integer,g_lpw) - cast(integer,lpdt),0 )

  rval = CreateDialogIndirectParam( GetModuleHandle(null), _
                                    lpdt, _
                                    hParent, _
                                    lpDialogProc, _
                                    lParamInit )
  GlobalFree( lpdt )

  return rval

end function

'====================================================================

'' This procedure allocates memory for a dialog template and
'' initializes the essential members of the DLGTEMPLATE structure,
'' the menu, class, and title arrays, and optionally the font
'' point size and typeface array. Returns a pointer to the next
'' WORD following the title or typeface array in g_lpw, and a
'' pointer to the allocated memory in lpdt.
''
'' The initial allocation size, 10KB, should be sufficient even
'' for a large and complex dialog. In the unlikely event that
'' the allocation is not sufficient, the likely result will be a
'' memory access violation at run time. For troubleshooting this
'' problem, the number of bytes of template memory used, at any
'' point in the creation of the template, can be displayed with
'' a statement like this:
''
'' MessageBox( 0, str(cint(g_lpw) - cint(lpdt)), "Bytes Used", 0 )
''
'' The CreateModalDialog and CreateModelessDialog functions resize
'' the memory block to fit the template, freeing any excess.
''
'' Parameter cdit must match the number of controls defined.
'' If the value is too high then the function that creates the
'' dialog will fail. If the value is too low then one or more
'' of the controls will not be created.
''
sub Dialog( byval cdit as WORD, _
            byval x as short, _
            byval y as short, _
            byval cx as short, _
            byval cy as short, _
            byref title as string, _
            byref lpdt as LPDLGTEMPLATE, _
            byval style as DWORD, _
            byval pointSize as short = 0, _
            byref typeFace as string = "" )

  g_dialog_width = cx

  lpdt = GlobalAlloc( GMEM_FIXED or GMEM_ZEROINIT, 1024 * 10 )

  '' Memory allocated by GlobalAlloc is guaranteed to be
  '' aligned on an 8-byte boundary. Initialize the essential
  '' members of the structure.
  ''
  lpdt->style = style
  lpdt->cdit = cdit
  lpdt->x  = x
  lpdt->y  = y
  lpdt->cx = cx
  lpdt->cy = cy

  '' Set g_lpw to the menu array that follows the structure.
  ''
  g_lpw = cast(LPWORD,lpdt + 1)

  '' Skip the first element of the menu array, leaving it
  '' set to zero (no menu).
  ''
  g_lpw += 1

  '' Skip the first element of the class array, leaving it
  '' set to zero (no class), so the system will use the
  '' predefined dialog box class.
  ''
  g_lpw += 1

  '' Initialize the title array and set g_lpw to next WORD
  '' following the title array.
  ''
  GenUstring( title )

  '' If the DS_SETFONT style was specified, set the font
  '' point size, initialize the typeface array, and set
  '' g_lpw to next WORD following the typeface array.
  ''
  if style and DS_SETFONT then
    *g_lpw = pointSize
    g_lpw += 1
    GenUstring( typeFace )
  end if

end sub

'====================================================================

'' Starting at the address specified by g_lpw, this general-purpose
'' control definition procedure initializes the essential members
'' of a DLGITEMTEMPLATE structure and the class, title and creation
'' data arrays.
''
'' For the class array, for the six predefined system (User32)
'' classes, use the strings "BUTTON", "EDIT", "STATIC", "LISTBOX",
'' "SCROLLBAR", and "COMBOBOX". For common controls use the class
'' strings defined in commctrl.bi.
''
'' The title array can specify the caption or initial text for the
'' control, or the ordinal value of a resource in the executable
'' file. Specify a caption or initial text in the title parameter,
'' or an ordinal value in the rid (ResourceID) parameter. If the
'' rid parameter is non-zero then the title parameter is ignored.
''
'' There is no support for creation data.
''
'' * FOR WINDOWS 95/98/ME, ONLY THE LOW-ORDER BYTE OF THE CONTROL
'' ID (parameter cid) IS USED, SO THE MAXIMUM VALUE IS 255 *
''
'' The tab order of the controls in a dialog is determined by the
'' order in which the controls are created, and by which controls
'' have the WS_TABSTOP style.
''
'' To center the control in the dialog horizontally specify -1
'' for the x parameter. This feature will not work correctly for
'' an auto-sized control where the width is not specified.
''
sub Control( byval cid as WORD, _
             byval x as short, _
             byval y as short, _
             byval cx as short, _
             byval cy as short, _
             byref title as string, _
             byval rid as short, _
             byref _class as string, _
             byval style as DWORD = 0 )

  if x = -1 then x = (g_dialog_width - cx) / 2

  dim as LPDLGITEMTEMPLATE lpdit
  
  ''--------------------------------------------------------------
  '' Changed following two statements from the Windows data type
  '' ULONG to the FreeBASIC type UINTEGER so the size would match
  '' the size of a pointer, 32 bits for 32-bit code and 64 bits
  '' for 64-bit code.
  ''--------------------------------------------------------------
  
  dim as UINTEGER ul
  
  '' The DLGITEMTEMPLATE structure must be aligned on a
  '' DWORD boundary.
  ''
  ul = cast(UINTEGER,g_lpw) + 3  

  ul shr= 2
  ul shl= 2
  g_lpw = cast(LPWORD,ul)

  '' Initialize the essential members of the structure.
  ''
  '' The establishes the base style as WS_CHILD or WS_VISIBLE.
  ''
  lpdit = cast(LPDLGITEMTEMPLATE,g_lpw)
  lpdit->style = WS_CHILD or WS_VISIBLE or style
  lpdit->x  = x
  lpdit->y  = y
  lpdit->cx = cx
  lpdit->cy = cy
  lpdit->id = cid

  '' Set g_lpw to the class array that follows the structure.
  ''
  g_lpw = cast(LPWORD,lpdit + 1)

  '' Initialize the class array and set g_lpw to the next WORD
  '' following the class array.
  ''
  GenUstring( _class )


  '' Initialize the title array and set g_lpw to the next WORD
  '' following the title array.
  ''
  if rid then
    *g_lpw = &hffff
    g_lpw += 1
    *g_lpw = rid
    g_lpw += 1
  else
    GenUstring( title )
  end if

  '' Skip the first element of the creation data array, leaving
  '' it set to zero (no creation data).
  ''
  g_lpw += 1

end sub

'====================================================================
'' The following specialized control definition procedures are
'' simply wrappers for the general-purpose procedure.
'====================================================================

sub PushButton( byval cid as WORD, _
                byval x as short, _
                byval y as short, _
                byval cx as short, _
                byval cy as short, _
                byref caption as string, _
                byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, caption, 0, "BUTTON", _
           BS_PUSHBUTTON or style )
end sub

'====================================================================

sub DefPushButton( byval cid as WORD, _
                   byval x as short, _
                   byval y as short, _
                   byval cx as short, _
                   byval cy as short, _
                   byref caption as string, _
                   byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, caption, 0, "BUTTON", _
           BS_DEFPUSHBUTTON or style )
end sub

'====================================================================

sub AutoCheckBox( byval cid as WORD, _
                  byval x as short, _
                  byval y as short, _
                  byval cx as short, _
                  byval cy as short, _
                  byref caption as string, _
                  byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, caption, 0, "BUTTON", _
           BS_AUTOCHECKBOX or style )
end sub

'====================================================================

sub AutoRadioButton( byval cid as WORD, _
                     byval x as short, _
                     byval y as short, _
                     byval cx as short, _
                     byval cy as short, _
                     byref caption as string, _
                     byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, caption, 0, "BUTTON", _
           BS_AUTORADIOBUTTON or style )
end sub

'====================================================================

sub GroupBox( byval cid as WORD, _
              byval x as short, _
              byval y as short, _
              byval cx as short, _
              byval cy as short, _
              byref caption as string, _
              byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, caption, 0, "BUTTON", _
           BS_GROUPBOX or style )
end sub

'====================================================================

sub EditText( byval cid as WORD, _
              byval x as short, _
              byval y as short, _
              byval cx as short, _
              byval cy as short, _
              byref text as string, _
              byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, text, 0, "EDIT", _
           style )
end sub

'====================================================================

sub LText( byval cid as WORD, _
           byval x as short, _
           byval y as short, _
           byval cx as short, _
           byval cy as short, _
           byref text as string, _
           byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, text, 0, "STATIC", _
           SS_LEFT or style )
end sub

'====================================================================

sub RText( byval cid as WORD, _
           byval x as short, _
           byval y as short, _
           byval cx as short, _
           byval cy as short, _
           byref text as string, _
           byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, text, 0, "STATIC", _
           SS_RIGHT or style )
end sub

'====================================================================

sub CText( byval cid as WORD, _
           byval x as short, _
           byval y as short, _
           byval cx as short, _
           byval cy as short, _
           byref text as string, _
           byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, text, 0, "STATIC", _
           SS_CENTER or style )
end sub

'====================================================================

sub ListBox( byval cid as WORD, _
             byval x as short, _
             byval y as short, _
             byval cx as short, _
             byval cy as short, _
             byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, "", 0, "LISTBOX", _
           style )
end sub

'====================================================================

sub ComboBox( byval cid as WORD, _
              byval x as short, _
              byval y as short, _
              byval cx as short, _
              byval cy as short, _
              byval style as DWORD = 0 )

    Control( cid, x, y, cx, cy, "", 0, "COMBOBOX", _
             style )
end sub

'====================================================================

sub ScrollBar( byval cid as WORD, _
               byval x as short, _
               byval y as short, _
               byval cx as short, _
               byval cy as short, _
               byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, "", 0, "SCROLLBAR", _
           style )
end sub

'====================================================================
'' To use a Rich Edit control your app must first call LoadLibrary
'' to load the appropriate DLL - RICHED20.DLL for version 2 or 3,
'' or RICHED32.DLL for version 1.
'====================================================================

'' This procedure is coded for version 2 or 3.
''
sub RichEdit( byval cid as WORD, _
              byval x as short, _
              byval y as short, _
              byval cx as short, _
              byval cy as short, _
              byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, "", 0, RICHEDIT_CLASS, _
           style )
end sub

'' This procedure is coded for version 1.
''
sub RichEdit1( byval cid as WORD, _
               byval x as short, _
               byval y as short, _
               byval cx as short, _
               byval cy as short, _
               byval style as DWORD = 0 )

  Control( cid, x, y, cx, cy, "", 0, RICHEDIT_CLASS10A, _
           style )
end sub

'====================================================================

'' To use controls from the common control DLL, specific common
'' control classes must first be initialized. This procedure
'' initializes 14 of the commonly used common control classes
'' in a single call.
''
'' This procedure uses the InitCommonControlsEx function, which
'' should work for all recent versions of Windows, but it may
'' be necessary to substitute the older InitCommonControls
'' function for Windows 95 or NT.
''
sub InitializeCommonControls

  dim as INITCOMMONCONTROLSEX icce

  icce.dwSize = sizeof( INITCOMMONCONTROLSEX )
  icce.dwICC = ICC_ANIMATE_CLASS _
            or ICC_BAR_CLASSES _
            or ICC_COOL_CLASSES _
            or ICC_DATE_CLASSES _
            or ICC_HOTKEY_CLASS _
            or ICC_INTERNET_CLASSES _
            or ICC_LISTVIEW_CLASSES _
            or ICC_PAGESCROLLER_CLASS _
            or ICC_PROGRESS_CLASS _
            or ICC_TAB_CLASSES _
            or ICC_TREEVIEW_CLASSES _
            or ICC_UPDOWN_CLASS _
            or ICC_USEREX_CLASSES _
            or ICC_WIN95_CLASSES

  InitCommonControlsEx( @icce )

end sub

'====================================================================
Button grid demo.bas by MichaelW see viewtopic.php?t=5667

Code: Select all

'====================================================================
'' Button grid demo, modal dialog as main.
'====================================================================

#include "dialogs.bas"

'====================================================================

function DialogProc( byval hDlg as  HWND, _
                     byval uMsg as UINT, _
                     byval wParam as WPARAM, _
                     byval lParam as LPARAM ) as integer

  static state(100 to 200) as integer

  select case uMsg

    case WM_COMMAND

      if hiword(wParam) = BN_CLICKED then

        if state(loword(wParam)) then
          SetDlgItemText( hDlg, loword(wParam), "" )
          state(loword(wParam)) = 0
        else
          SetDlgItemText( hDlg, loword(wParam), "X" )
          state(loword(wParam)) = 1
        end if

      end if

    case WM_CLOSE

      EndDialog( hDlg, null )

  end select

  return 0

end function

'====================================================================

dim as LPDLGTEMPLATE lpdt

dim as short id, r, c

Dialog( 100, 0, 0, 122, 130, "Button Grid Demo", lpdt, _
        WS_OVERLAPPED or WS_SYSMENU or DS_CENTER )

id = 100
for c = 10 to 100 step 10
  for r = 10 to 100 step 10
    PushButton( id, r, c, 9, 9, "", WS_TABSTOP )
    id += 1
  next
next

CreateModalDialog( 0, @DialogProc, 0, lpdt )

'====================================================================
Last edited by srvaldez on Dec 19, 2022 19:52, edited 2 times in total.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Simple GUI example ?

Post by srvaldez »

btw, the GUI designers are very good and it makes designing your gui very easy, it's a lot like Visual Basic
softfoot
Posts: 34
Joined: Aug 31, 2020 3:45

Re: Simple GUI example ?

Post by softfoot »

Many thanks - it is exactly what I needed.
Looking at the original post there is some great stuff in there but sadly the link to the zip file is broken.
Regards,
Dave
softfoot
Posts: 34
Joined: Aug 31, 2020 3:45

Re: Simple GUI example ?

Post by softfoot »

Thank you I found the button matrix example very useful.

viewtopic.php?t=5667 contains some very
helpful stuff 😄

I have modified your example to suit my basic needs and it works well.
However, I would like to put some text beside each button on the main window
but when it comes to GUI work I am very much a newbie and I am struggling.

Do you have an example of putting text on the main window around the
buttons ??

Best regards,
Dave
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Simple GUI example ?

Post by srvaldez »

hello softfoot :)
I am not Windows SDK savvy so I can't help.
if you don't want to use a visual designer then I suggest that you have a look at the Windows9 library viewtopic.php?t=17058 there are many examples scattered about on that thread
the Sourceforge page for windows9 is https://sourceforge.net/projects/guiwindow9/
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Simple GUI example ?

Post by RNBW »

srvaldez wrote: Dec 30, 2022 13:27 hello softfoot :)
I am not Windows SDK savvy so I can't help.
if you don't want to use a visual designer then I suggest that you have a look at the Windows9 library viewtopic.php?t=17058 there are many examples scattered about on that thread
the Sourceforge page for windows9 is https://sourceforge.net/projects/guiwindow9/
The Window9 library is very easy to set up and use. I'm not quite sure what softfoot means by putting text beside a button, but if softfoot means
Text + Button
Text + Button
Text + Button
and so on, this is an absolute doddle using Window9 and uses far less code.

I wouldn't hesitate in recommending Window9.

Code: Select all

#Include "window9.bi"

Dim As integer hwnd,event

hwnd = OpenWindow("Buttons",100,10,250,200)

TextGadget(101,10,10,50,20,"Serial 1")
TextGadget(102,10,50,50,20,"Serial 2")
TextGadget(103,10,90,50,20,"Serial 3")

ButtonGadget(201,80,10,80,20,"button 1")
ButtonGadget(202,80,50,80,20,"button 2")
ButtonGadget(203,80,90,80,20,"button 3")

Do
   event = WaitEvent()
   If event = EventClose Then End
Loop
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Simple GUI example ?

Post by srvaldez »

hello RNBW
I think that softfoot means a label besides or on top of the button not the caption of the button
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Simple GUI example ?

Post by RNBW »

srvaldez wrote: Dec 30, 2022 20:51 hello RNBW
I think that softfoot means a label besides or on top of the button not the caption of the button
The code I produced shows 3 rows of a label alongside a button. I've annotated the buttons just to give the button a name (it could have been left blank). Labels could just as easily be put on top or to the right of the buttons.

I think we are both saying that it's much easier to use Windows9.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Simple GUI example ?

Post by srvaldez »

yes, Windows9 should serve the purpose
for a complex GUI I would use a GUI designer
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Simple GUI example ?

Post by RNBW »

srvaldez wrote: Dec 30, 2022 21:40 yes, Windows9 should serve the purpose
for a complex GUI I would use a GUI designer
I'm very old fashioned. I don't use a GUI designer much. I started off life 60-odd years ago as a draughtsman and I find it easier and quicker to draw the GUI on a sheet of paper and then enter the code using a bit of copying and pasting and adjustment of values. But then, everybody has their own way of working.

In saying that, Window9 would benefit from a GUI designer.
softfoot
Posts: 34
Joined: Aug 31, 2020 3:45

Re: Simple GUI example ?

Post by softfoot »

Many thanks all, I'll take a look at Win9
Dave
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Simple GUI example ?

Post by RNBW »

softfoot wrote: Dec 31, 2022 9:28 Many thanks all, I'll take a look at Win9
Dave
Have a look at the Help File. It is full of code examples and VANYA is very helpful.
softfoot
Posts: 34
Joined: Aug 31, 2020 3:45

Re: Simple GUI example ?

Post by softfoot »

I tried the example and it would not compile - I had to change
"Dim As integer hwnd,event" to "Dim As integer event" plus "Dim as HWND hwnd"

But then it wouldnt link it seems to be looking for "z.a".

Any ideas ??
Dave
RNBW wrote: Dec 30, 2022 19:45
srvaldez wrote: Dec 30, 2022 13:27 hello softfoot :)
I am not Windows SDK savvy so I can't help.
if you don't want to use a visual designer then I suggest that you have a look at the Windows9 library viewtopic.php?t=17058 there are many examples scattered about on that thread
the Sourceforge page for windows9 is https://sourceforge.net/projects/guiwindow9/
The Window9 library is very easy to set up and use. I'm not quite sure what softfoot means by putting text beside a button, but if softfoot means
Text + Button
Text + Button
Text + Button
and so on, this is an absolute doddle using Window9 and uses far less code.

I wouldn't hesitate in recommending Window9.

Code: Select all

#Include "window9.bi"

Dim As integer hwnd,event

hwnd = OpenWindow("Buttons",100,10,250,200)

TextGadget(101,10,10,50,20,"Serial 1")
TextGadget(102,10,50,50,20,"Serial 2")
TextGadget(103,10,90,50,20,"Serial 3")

ButtonGadget(201,80,10,80,20,"button 1")
ButtonGadget(202,80,50,80,20,"button 2")
ButtonGadget(203,80,90,80,20,"button 3")

Do
   event = WaitEvent()
   If event = EventClose Then End
Loop
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Simple GUI example ?

Post by RNBW »

You have to be sure that you follow the instructions exactly in the first posting for the library. It should then compile.
Page dedicated to the library with some examples and screenshots:

https://users.freebasic-portal.de/freeb ... start.html

The installation of the library:

Windows:

1) Put files libwindow9.a, libLinked_Lists.a in the folder: compilier\lib\win32 OR compilier\lib\win64

2) Put files extwstring.bi , Linked_Lists.bi , Window9.bi in the folder: compilier\inc

In the Windows maybe need a library zlib .
Post Reply