Simple GUI example ?

New to FreeBASIC? Post your questions here.
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Simple GUI example ?

Post by RNBW »

This is another example with Edit Boxes in a grid. It sets up 2 grids and the user enters text into the first grid. Clicking the Button "Click Me!" transfers the text from the first grid to the second grid.

Code: Select all

'=============================================================================
'GridTransfer
'Author: RNBW
'1 August 2017

'Includes Row AND Column Headings
'Transfers values from one grid to another
'==========================================
'
' INSTRUCTIONS:
' -------------------
' ENTER DATA INTO THE TOP GRID. WHEN YOU CLICK IN NEXT CELL
' OR CLICK <Click me!> Button, DATA WILL BE TRANSFERRED
' FROM TOP GRID TO BOTTOM GRID
'==========================================

#INCLUDE "window9.bi"

DIM AS LONG NumOfRows=3, NumOfCols=3, id1, id2
DIM AS STRING sRows, sCols, stRow, stCol, stID1, stID2

DIM SHARED AS HWND Window_Main, Button_Click
DIM SHARED AS MSG msg
DIM AS STRING text, text2, result
DIM AS HWND event
DIM AS LONG vPos, hPos, wide, rHt, row, col

'---------------------
' MAIN WINDOW
'---------------------

OpenWindow("Multi-Column Grid",100,100,550,300)
ButtonGadget(1,10,10,100,20, "Click me!")

'-------------------------------
'  SET UP THE FIRST GRID
'-------------------------------
vPos = 40: rHt = 20
FOR row = 1 TO NumOfRows
   FOR col = 1 TO 3
      SELECT CASE col
         CASE 1
            hPos = 10: wide = 65
         CASE 2
            hPos = 75: wide = 380
			Case 3
            hPos = col*65+(455-65*3) : wide = 65
      END SELECT
      stRow = STR(row): stCol = STR(col)
      stID1 = "1" + stRow+stCol
      id1 = VALint(stID1)
      StringGadget(id1, hPos, vPos+rHt*(row-1), wide+1, rHt+1, "", WS_BORDER)
   NEXT
NEXT

'----------------------------------
'  SET UP THE SECOND GRID
'----------------------------------
rHt = 20
vPos = 40 + rHt * (NumOfRows + 3)
FOR row = 1 TO NumOfRows
   FOR col = 1 TO 3
      SELECT CASE col
         CASE 1
            hPos = 10: wide = 65
         CASE 2
            hPos = 75: wide = 380
			Case 3
            hPos = col*65+(455-65*3) : wide = 65
      END SELECT
      stRow = STR(row): stCol = STR(col)
      stID2 = "2" + stRow+stCol
      id2 = VALint(stID2)
      StringGadget(id2, hPos, vPos+rHt*(row-1), wide+1, rHt+1,"", WS_BORDER)
   NEXT
NEXT

'-----------------------------------
' SET UP HEADINGS IN ROW 1
' IN BOTH GRIDS
'-----------------------------------
row = 1
FOR row = 1 TO 1
   FOR col = 2 TO NumOfCols
      stRow = STR(row): stCol = STR(col)
      stID1 = "1" + stRow+stCol
      id1 = VALint(stID1)
      SetGadgetText(id1,"Col"+STR(col-1))
      
      stID2 = "2" + stRow+stCol
      id2 = VALint(stID2)
      SetGadgetText(id2,"Col"+STR(col-1))
   NEXT
NEXT

'----------------------------------
' SET UP HEADINGS IN COL 1
' IN BOTH GRIDS
'----------------------------------

col = 1
FOR row = 2 TO NumOfRows
   FOR col = 1 TO 1
      stRow = STR(row): stCol = STR(col)
      stID1 = "1" + stRow+stCol
      id1 = VALint(stID1)
      SetGadgetText(id1,"Row"+STR(row-1))
      
      stID2 = "2" + stRow+stCol
      id2 = VALint(stID2)
      SetGadgetText(id2,"Row"+STR(row-1))
   NEXT
NEXT

'-----------------------------------------
'TRANSFER DATA ENTERED IN THE FIRST GRID
'INTO THE SECOND GRID.
'-----------------------------------------
DO
   var EVENT =  WaitEvent()
   IF event=WM_LBUTTONDOWN THEN
      '-----------------------------------------
      ' GET VALUES FROM FIRST GRID
      ' AND TRANSFER TO SECOND GRID
      '-----------------------------------------
      FOR row AS INTEGER = 2 TO NumOfRows
         FOR col AS INTEGER = 2 TO 3

            stRow = STR(row): stCol = STR(col)
            stID1 = "1" + stRow+stCol
            id1 = VALInt(stID1)
            stID2 = "2" + stRow+stCol
            id2 = VALint(stID2)
            SetGadgetText(id2,GetGadgetText(id1))
         NEXT col
      NEXT row
   END IF
   IF event=EventClose THEN END
LOOP

END
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Simple GUI example ?

Post by VANYA »

RNBW wrote: Dec 31, 2022 21:36 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 .
I forgot to update the instructions. Now the files libLinked_Lists.a , Linked_Lists.bi are not needed!
Instruction updated: viewtopic.php?t=17058
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Simple GUI example ?

Post by RNBW »

VANYA
Thank you.
Post Reply