gui_chung an easy way to make gui windows

User projects written in or related to FreeBASIC.
chung
Posts: 610
Joined: Jan 16, 2010 20:52
Location: France
Contact:

gui_chung an easy way to make gui windows

Postby chung » Sep 30, 2010 19:20

gui_chung is a compact freeware to program easy gui windows in freebasic .

click there => http://chungswebsite.blogspot.com/search/label/gui

example of windows programmed with gui_chung :
Image
Last edited by chung on Jan 22, 2012 11:19, edited 3 times in total.
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

Postby D.J.Peters » Sep 30, 2010 20:36

to mutch global vars but not bad at all.

Joshy
chung
Posts: 610
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Postby chung » Oct 02, 2010 22:21

(02/10/2010) colors and fonts control added

example of windows programmed :
Image

Image[/img]

example of sample program :
Image
Last edited by chung on Oct 03, 2010 15:39, edited 2 times in total.
Richard
Posts: 2964
Joined: Jan 15, 2007 20:44
Location: Australia

Postby Richard » Oct 03, 2010 0:22

When I compile with “fbc.exe -exx -w pedantic”, I get the following warnings...

gui_chung.bi(138) warning 16(0): No explicit BYREF or BYVAL, at parameter 8 (userflags) of button()
gui_chung.bi(426) warning 1(1): Passing scalar as pointer, at parameter 1 of SELECTOBJECT()
gui_chung.bi(431) warning 1(1): Passing scalar as pointer, at parameter 1 of SELECTOBJECT()
gui_chung.bi(432) warning 1(1): Passing scalar as pointer, at parameter 1 of SETTEXTCOLOR()
gui_chung.bi(433) warning 1(1): Passing scalar as pointer, at parameter 1 of SETBKCOLOR()
gui_chung.bi(434) warning 5(0): Implicit conversion
gui_chung.bi(435) warning 5(0): Implicit conversion
gui_chung.bi(438) warning 1(1): Passing scalar as pointer, at parameter 1 of SELECTOBJECT()
gui_chung.bi(440) warning 1(1): Passing scalar as pointer, at parameter 1 of SETTEXTCOLOR()
gui_chung.bi(441) warning 1(1): Passing scalar as pointer, at parameter 1 of SETBKMODE()
gui_chung.bi(442) warning 5(0): Implicit conversion
gui_chung.bi(443) warning 5(0): Implicit conversion
gui_chung.bi(449) warning 1(1): Passing scalar as pointer, at parameter 1 of SELECTOBJECT()
gui_chung.bi(450) warning 1(1): Passing scalar as pointer, at parameter 1 of SETTEXTCOLOR()
gui_chung.bi(451) warning 1(1): Passing scalar as pointer, at parameter 1 of SETBKCOLOR()
gui_chung.bi(452) warning 5(0): Implicit conversion
gui_chung.bi(512) warning 16(0): No explicit BYREF or BYVAL, at parameter 1 (r) of guibackgroundcolor()
gui_chung.bi(512) warning 16(0): No explicit BYREF or BYVAL, at parameter 2 (g) of guibackgroundcolor()
gui_chung.bi(512) warning 16(0): No explicit BYREF or BYVAL, at parameter 3 (b) of guibackgroundcolor()
gui_chung.bi(515) warning 16(0): No explicit BYREF or BYVAL, at parameter 1 (r) of guiedittextbackcolor()
gui_chung.bi(515) warning 16(0): No explicit BYREF or BYVAL, at parameter 2 (g) of guiedittextbackcolor()
gui_chung.bi(515) warning 16(0): No explicit BYREF or BYVAL, at parameter 3 (b) of guiedittextbackcolor()
gui_chung.bi(521) warning 16(0): No explicit BYREF or BYVAL, at parameter 1 (r) of guilistboxbackcolor()
gui_chung.bi(521) warning 16(0): No explicit BYREF or BYVAL, at parameter 2 (g) of guilistboxbackcolor()
gui_chung.bi(521) warning 16(0): No explicit BYREF or BYVAL, at parameter 3 (b) of guilistboxbackcolor()
gui_chung.bi(529) warning 16(0): No explicit BYREF or BYVAL, at parameter 1 (r) of guiedittextinkcolor()
gui_chung.bi(529) warning 16(0): No explicit BYREF or BYVAL, at parameter 2 (g) of guiedittextinkcolor()
gui_chung.bi(529) warning 16(0): No explicit BYREF or BYVAL, at parameter 3 (b) of guiedittextinkcolor()
gui_chung.bi(533) warning 16(0): No explicit BYREF or BYVAL, at parameter 1 (r) of guilistboxinkcolor()
gui_chung.bi(533) warning 16(0): No explicit BYREF or BYVAL, at parameter 2 (g) of guilistboxinkcolor()
gui_chung.bi(533) warning 16(0): No explicit BYREF or BYVAL, at parameter 3 (b) of guilistboxinkcolor()
gui_chung.bi(537) warning 16(0): No explicit BYREF or BYVAL, at parameter 1 (r) of guistatictextinkcolor()
gui_chung.bi(537) warning 16(0): No explicit BYREF or BYVAL, at parameter 2 (g) of guistatictextinkcolor()
gui_chung.bi(537) warning 16(0): No explicit BYREF or BYVAL, at parameter 3 (b) of guistatictextinkcolor()
gui_chung.bi(601) warning 34(0): 'BYVAL AS STRING' actually behaves like 'BYREF AS ZSTRING' (this is hoped to change in future releases), at parameter 1 (windowname) of openwindow()
gui_chung.bi(601) warning 34(0): 'BYVAL AS STRING' actually behaves like 'BYREF AS ZSTRING' (this is hoped to change in future releases), at parameter 2 (windowtext) of openwindow()
gui_chung.bi(641) warning 34(0): 'BYVAL AS STRING' actually behaves like 'BYREF AS ZSTRING' (this is hoped to change in future releases), at parameter 1 (opt) of guiclose()
gui_chung.bi(784) warning 16(0): No explicit BYREF or BYVAL, at parameter 7 (userflags) of statictext()
gui_chung.bi(792) warning 16(0): No explicit BYREF or BYVAL, at parameter 8 (userflags) of edittext()
gui_chung.bi(891) warning 16(0): No explicit BYREF or BYVAL, at parameter 7 (userflags) of listbox()
gui_chung.bi(997) warning 16(0): No explicit BYREF or BYVAL, at parameter 2 (usersub) of addusersub()
gui_chung.bi(1012) warning 16(0): No explicit BYREF or BYVAL, at parameter 2 (usersub) of changeusersub()
chung
Posts: 610
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Postby chung » Oct 03, 2010 10:16

i dont know what pedantic is but i compile with
D:\FreeBASIC\fbc -s gui "gui_chung_test.bas" "icon.rc"

("windows GUI" option of fbEdit)
Last edited by chung on Oct 03, 2010 13:06, edited 2 times in total.
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Postby rolliebollocks » Oct 03, 2010 13:04

@chung

I would be concerned over the "passing scalar as pointer" and "implicit conversion".

byval/byref is an optimization. Everything is passed by reference in FB unless otherwise specified. Forving BYVAL will break compatibility with earlier BASICS, but it should give yyou a bit of a boost in speed.
chung
Posts: 610
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Postby chung » Oct 03, 2010 13:06

(03/10/2010) i have added some missing byval/byref/cast to gui_chung.bi

there should be less warnings now, but "windows GUI" didnt send these warning though...
chung
Posts: 610
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Postby chung » Oct 03, 2010 21:02

(03/10/2010) guiloadbmp, bmpbutton added
(04/10/2010) staticbmp added


Image
TJF
Posts: 3486
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Oct 04, 2010 5:54

rolliebollocks wrote:... Everything is passed by reference in FB unless otherwise specified...


FB docu wrote:Dialect Differences


In the -lang fb dialect, ByVal is the default parameter passing convention for all built-in types except String; String and user-defined Types are passed ByRef by default.

In -lang qb and -lang fblite dialects, ByRef is the default parameter passing convention.
chung
Posts: 610
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Postby chung » Oct 04, 2010 11:09

(04/10/2010) setcheckmenu, uncheckmenu, enablemenu, disablemenu, setmenutext added
(04/10/2010) fonts size & italic added
(04/10/2010) graphicbox , openGL test added
BasicScience
Posts: 475
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Postby BasicScience » Oct 05, 2010 22:46

Here's an example of how to draw on the window, using LineTo.

The Gui_Chung.BI file takes away a lot of the gory details, but this approach still requires more knowledge of Win API than I care to master. I'll stick with a retro-engineered GUI constructed from native FB commands via FB_GUI.

BasicScience

Code: Select all

'sample test program for gui_chung , an easy way to make windows
#Include Once "windows.bi"
#Include Once "gui_chung.bi"

Declare sub MyDraw

SUB End_GUI
    guiclose
    guiquit
end sub

' Program start
guibackgroundcolor(240,240,240)

button("Win_Main.button1","Exit",@End_GUI,10,10,60,20)
button("Win_Main.button2","Draw",@MyDraw,10,40,60,20)
openwindow("Win_Main","Test Window",100,400,600,400,WS_OVERLAPPEDwindow)

dim shared as hWnd hWin_Draw
hWin_Draw = guihwindow(1)   'default set to first window = Win_Main


DO while NOT guitestKey(vk_escape)
    guiwait  'wait for msg
loop

End_GUI
END


SUB MyDraw
    Dim As Integer xleft, ytop, wd, ht
    xleft = 50
    ytop = 80
    wd = 400
    ht = 200
    Dim hDC As HDC
                           
   hDC = GetDC( hWin_Draw )

   
   Rectangle hDC, xleft, ytop, xleft+wd, ytop+ht
   Dim As HPEN greenPen=CreatePen(PS_solid, 3, &h0000ff00)
   Dim As HPEN BluePen=CreatePen(PS_solid, 3, &h00ff0000)
   SelectObject (hDC, greenPen)
   
   MoveToEx hDC, xleft, ytop+ht/2, Null
   For i As Integer = 0 To wd-1
   
        If i = wd/2 Then   SelectObject (hDC, BluePen)
         LineTo hDC, xleft+i, ytop + (ht/2)*(1+ Sin(6.28*i/20)*Exp(-i/70))

   Next i
   
   ReleaseDC hWin_Draw, hDC     

    DeleteObject(GreenPen)
    DeleteObject(BluePen)
end sub
chung
Posts: 610
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Postby chung » Oct 06, 2010 10:41

(06/10/2010) jpg ,gif ,ico image loader added (jpeg.dll by Alyce Watson). included in bmpbutton,staticbmp,guiloadbmp (guiloadimage)
chung
Posts: 610
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Postby chung » Oct 07, 2010 8:04

(07/10/2010) graphicbox : gfx freebasic support added

graphicbox created with graphtype="gfx" (default) generate a buffer compatible with native freebasic gfx commands + support multi graphicbox windows.

(07/10/2010) trapleftmouse, traprightmouse added.works with statictext,staticbmp,graphicbox (trap mouse clicks)

(08/10/2010) guistartopenGL, guicloseopenGL, guirefreshopenGL added

sample program :

Code: Select all

#Include Once "windows.bi"
#Include Once "gui_chung.bi"

Declare Sub subdraw
Declare Sub subquit
Dim Shared As Integer quit=0
Dim Shared As Any Ptr buffer,buffer2
   
graphicbox("win4.graph",10,10,200,200)
graphicbox("win4.graph2",220,10,200,200)
button("win4.button","Draw",@subdraw,10,220,70,27)
openwindow("win4","my window4",600,330,450,280)

trapclose("win4",@subquit)
buffer=getguigfxbuffer("win4.graph")
buffer2=getguigfxbuffer("win4.graph2")

While quit=0 And guitestkey(vk_escape)=0
   guirefreshwindow("win4")
   guiwait
Wend
guiclose
guiquit
End

Sub subdraw
   Paint buffer,(1,1),0,999
   Line buffer,(100+Rnd*50,50+Rnd*50)-(100+Rnd*50,50+Rnd*50),RGB(Rnd*255,Rnd*255,Rnd*255),bf 
   Color RGB(0,255,0)
   Circle buffer,(150,100),100
   Circle buffer,(100,100),100
   Circle buffer,(200,100),100
   Line buffer2,(50+Rnd*50,50+Rnd*50)-(100+Rnd*50,50+Rnd*50),RGB(Rnd*255,Rnd*255,Rnd*255),bf 
   Color RGB(250,0,0)
   Circle buffer2,(100,100),100   
End Sub
Sub subquit
   quit=1
End Sub

sample openGL program :

Code: Select all

'sample test openGL program for gui_chung , an easy way to make windows
#Include Once "windows.bi"
#Include Once "gui_chung.bi"
#include Once "GL/gl.bi"
#include Once "GL/glu.bi"


Sub notice(ByRef msg As string,ByRef title As String ="notice")
   messagebox(0,msg,title,0)
End Sub
Sub confirm(ByRef msg As string,ByRef title As string,ByRef resp As String)
   Dim i As Integer
   i=messagebox(0,msg,title,1)
   If i=1 Then resp="yes" Else resp="no"
End Sub

Dim Shared As Integer itime,quit=0,restart=0
Dim Shared As Single rottri,rotquad
Sub mysubquit
   quit=1
End Sub
Sub mysubrestart
   quit=1
   restart=1
End Sub
Declare Sub initgl
Declare Sub drawgl
'
' Program start
guibackgroundcolor(0,240,240)
debut:
quit=0
button("win.button1","click here",NULL,10,10,100,40)
button("win.button2","restart",@mysubrestart,120,10,100,40)
statictext("win.text1","",240,10,80,30)
graphicbox("win.graph",10,60,640,480,"opengl")
openwindow("win","my window",100,100,700,600)

trapclose("win",@mysubquit)
Dim As hwnd wintext1h=getguih("win.text1")

guistartOpenGL("win.graph")
initgl
While quit=0 And Not guitestKey(vk_escape)
   itime+=1
   guiscan  'scan for input and continue
   'guiwait  'wait for msg
   drawgl
   guirefreshopenGL
   Sleep 20 
   printgui("win.button1",Str(itime))
   printguih(wintext1h,Str(guitestKey(vk_k))+"   ")'faster with guih than with name
Wend
guicloseOpenGL
guiclose'("msg")
If restart=1 Then
   restart=0:itime=0
   'notice("restart")
   guibackgroundcolor(Rnd*255,Rnd*255,Rnd*255)
   guireset:GoTo debut
EndIf
guiquit
End
Sub initgl
   glMatrixMode GL_PROJECTION
   glLoadIdentity
   gluPerspective 45.0, 640.0/480.0, 0.1, 100.0
   glMatrixMode GL_MODELVIEW
   glLoadIdentity
   
   glShadeModel GL_SMOOTH
   glClearColor 0.0, 0.0, 0.0, 1.0
   glClearDepth 1.0
   glEnable GL_DEPTH_TEST
   glDepthFunc GL_LEQUAL
   glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
End Sub
Sub drawgl
      glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
      glLoadIdentity
      glTranslatef -1.5, 0.0, -6.0
      glRotatef rottri, 0, 1, 0
      glBegin GL_TRIANGLES
         glColor3f 1.0, 0.0, 0.0
         glVertex3f 0.0, 1.0, 0.0
         glColor3f 0.0, 1.0, 0.0
         glVertex3f -1.0, -1.0, 0.0
         glColor3f 0.0, 0.0, 1.0
         glVertex3f 1.0, -1.0, 0.0
      glEnd
      
      glLoadIdentity
      glTranslatef 1.5, 0.0, -6.0
      glColor3f 0.5, 0.5, 1.0
      glRotatef rotquad, 1, 0, 0
      glBegin GL_QUADS
         glVertex3f -1.0, 1.0, 0.0
         glVertex3f 1.0, 1.0, 0.0
         glVertex3f 1.0, -1.0, 0.0
         glVertex3f -1.0, -1.0, 0.0
      glEnd
      rottri += 0.5
      rotquad += 0.5
End Sub
S.ean
Posts: 6
Joined: Feb 20, 2009 8:31

Looks easy

Postby S.ean » Oct 08, 2010 17:36

This looks easy by far. Kind of like BCX.
BasicScience
Posts: 475
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Postby BasicScience » Oct 08, 2010 20:33

@ Chung,

Nice implementation of the GFX buffer.

In your example, shouldn't you move the

guirefreshwindow("win4")

statement out of the main WEND loop and instead place it at the end of the Draw subroutine? The GUI refresh doesn't need to be done with each cycle through the WEND... but only if the image buffers have changed in Draw.

Return to “Projects”

Who is online

Users browsing this forum: Google [Bot] and 2 guests