Simple GUI
-
- Posts: 491
- Joined: Sep 28, 2013 15:08
- Location: Germany
Re: Simple GUI
After some discussions with BasicCoder2 in "Another Simple Textbox", I have done further work on my GUI project. New release available, see first post!
-
- Posts: 3954
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Simple GUI
@Lothar Schirm,
What I like most about your code is how easy I find it to read :)
In practice I have found lists (or groups) of buttons and/or text boxes useful.
In the case of a textbox list hitting ENTER or TAB should move the focus to the next textbox.
At the moment I am playing with some multiline text box code with word wrap and it is coming along nicely.
What I like most about your code is how easy I find it to read :)
In practice I have found lists (or groups) of buttons and/or text boxes useful.
In the case of a textbox list hitting ENTER or TAB should move the focus to the next textbox.
At the moment I am playing with some multiline text box code with word wrap and it is coming along nicely.
-
- Posts: 143
- Joined: May 28, 2009 20:07
Re: Simple GUI
nice work, i like it.:)
small bug in Listbox: i've reduced the height to check the box scrolling... when clicking directly under the last visible entry, (if exists) the next unvisible entry appears.
btw: after changing my machine and OS, i have rework my own project a little bit, now it "looks" like yours :D
Mutton
small bug in Listbox: i've reduced the height to check the box scrolling... when clicking directly under the last visible entry, (if exists) the next unvisible entry appears.
btw: after changing my machine and OS, i have rework my own project a little bit, now it "looks" like yours :D
Mutton
-
- Posts: 3954
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Simple GUI
@Muttonhead,
Your controls look very professional.
http://www.freebasic.net/forum/viewtopi ... &hilit=gui
I tried to run your multiLineEditBox to compare it with my effort but unfortunately my version of FreeBasic must be too old as I just get compiler errors.
Compiler output:
C:\FreeBasic\sGUI\sGUI_v0.8.3.8\sGUI_v0.8.3.8\sGUI\MultiLineEditBox_Basis.bas(1) error 55: Illegal specification, at parameter 1 (event) of AddMLEBGadget() in 'declare function AddMLEBGadget (event as EventHandle ptr,x as integer,y as integer,w as integer,lines as integer,mode as integer=1) as Gadget ptr'
And so on ...
Your controls look very professional.
http://www.freebasic.net/forum/viewtopi ... &hilit=gui
I tried to run your multiLineEditBox to compare it with my effort but unfortunately my version of FreeBasic must be too old as I just get compiler errors.
Compiler output:
C:\FreeBasic\sGUI\sGUI_v0.8.3.8\sGUI_v0.8.3.8\sGUI\MultiLineEditBox_Basis.bas(1) error 55: Illegal specification, at parameter 1 (event) of AddMLEBGadget() in 'declare function AddMLEBGadget (event as EventHandle ptr,x as integer,y as integer,w as integer,lines as integer,mode as integer=1) as Gadget ptr'
And so on ...
-
- Posts: 143
- Joined: May 28, 2009 20:07
Re: Simple GUI
@BasicCoder2:
Hmmm,there are no problems with this combination sGUI_v0.8.3.8 + fbc 0.9. With fbc 1.0 i get errors too.
But your sGUI version is not the latest.
Mutton
Hmmm,there are no problems with this combination sGUI_v0.8.3.8 + fbc 0.9. With fbc 1.0 i get errors too.
But your sGUI version is not the latest.
Mutton
-
- Posts: 491
- Joined: Sep 28, 2013 15:08
- Location: Germany
Re: Simple GUI
Thank you both for your comments!
@Muttonhead, I do not want to re-invent such a complex GUI as your sGUI, which is very mighty and sophisticated. Thank you that you want to adopt my design. It is more or less the same as BasicCoder2 used for his new textbox (http://www.freebasic.net/forum/viewtopi ... =7&t=23281). - I know that the scrolling behaviour of the listbox is still a little bit buggy, I will work on it the next days.
@BasicCoder2, your proposal of control arrays with the use of ENTER and TAB keys is fine, but for the moment I do not need it for myself, so I will not implement it now.
@Muttonhead, I do not want to re-invent such a complex GUI as your sGUI, which is very mighty and sophisticated. Thank you that you want to adopt my design. It is more or less the same as BasicCoder2 used for his new textbox (http://www.freebasic.net/forum/viewtopi ... =7&t=23281). - I know that the scrolling behaviour of the listbox is still a little bit buggy, I will work on it the next days.
@BasicCoder2, your proposal of control arrays with the use of ENTER and TAB keys is fine, but for the moment I do not need it for myself, so I will not implement it now.
-
- Posts: 3954
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Simple GUI
Yes if you are rolling your own you only implement what you need as opposed learning to use a complete package which has to have everything someone might need as they would otherwise have to modify the package to suit. Over time more and more bells and whistles are added to commercial products such as Visual Basic controls for programmers or options in programs like Excel or Word.@BasicCoder2, your proposal of control arrays with the use of ENTER and TAB keys is fine, but for the moment I do not need it for myself, so I will not implement it now.
I found in your adding numbers demo having to click the text box before entering a number annoying and it would be even more so if I had to enter a lot of data in say an array of text boxes (spreadsheet). Also numbers are right aligned. Another feature would be to give a text box a data type so that invalid data would be rejected. If you ever write a program that others might actually use such things are important.
-
- Posts: 491
- Joined: Sep 28, 2013 15:08
- Location: Germany
Re: Simple GUI
I understand. I have uploaded a new release, see first post:
- Bug in the listbox described by Muttonhead and another one that I have discovered myself is fixed
- You can write directly into the textbox or a cell of the data grid when clicking it with the mouse.
My intention was not to deliver a full-featured GUI, but just to give my first "Simple GUI" a better style and performance. So I am not sure whether I will do further improvements, as you suggest.
- Bug in the listbox described by Muttonhead and another one that I have discovered myself is fixed
- You can write directly into the textbox or a cell of the data grid when clicking it with the mouse.
My intention was not to deliver a full-featured GUI, but just to give my first "Simple GUI" a better style and performance. So I am not sure whether I will do further improvements, as you suggest.
-
- Posts: 491
- Joined: Sep 28, 2013 15:08
- Location: Germany
Re: Simple GUI
I am working further on my WinGUI library. I wonder about some strange constants (Const MainWindow ="#32770") and msg.message = 273 to end the program. Can anybody explain me where these constants are documented?dodicat wrote:For your perusal (optional of course), here is a simplified Win Api of my previous code.
Code: Select all
#include "windows.bi" freeconsole Declare Sub OPERATE(flag As Integer) Dim Shared As hwnd B1,B2,answer 'used in sub Const MainWindow ="#32770" Dim As MSG msg 'The window and boxes Var hWnd= CreateWindowEx( 0,MainWindow, "CALCULATE", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, 200, 200, 400, 600, 0, 0, 0, 0 ) B1 = CreateWindowEx( 0, "EDIT", "", ws_border Or WS_VISIBLE Or WS_CHILD Or WS_HSCROLL Or ES_AUTOHSCROLL , 50, 80, 200, 45, hWnd, 0, 0, 0 ) B2 = CreateWindowEx( 0, "EDIT", "", ws_border Or WS_VISIBLE Or WS_CHILD Or WS_HSCROLL Or ES_AUTOHSCROLL , 50, 280, 200, 45, hWnd, 0, 0, 0 ) answer = CreateWindowEx( 0, "EDIT", "", ws_border Or WS_VISIBLE Or WS_CHILD Or WS_HSCROLL Or ES_AUTOHSCROLL Or ES_READONLY, 50, 480, 200, 45, hWnd, 0, 0, 0 ) Var label =CreateWindowEx( 0, "STATIC", "ANSWER:",WS_VISIBLE Or WS_CHILD , 20, 450, 70, 30, hWnd, 0, 0, 0 ) Var ADDBUTTON= CreateWindowEx( 0,"BUTTON", "A+B", WS_VISIBLE Or WS_CHILD, 50,380 , 50, 30, hWnd, 0, 0, 0 ) Var minus = CreateWindowEx( 0,"BUTTON", "A-B", WS_VISIBLE Or WS_CHILD, 110,380 , 50, 30, hWnd, 0, 0, 0 ) Var prod = CreateWindowEx( 0,"BUTTON", "A*B", WS_VISIBLE Or WS_CHILD, 170,380 , 50, 30, hWnd, 0, 0, 0 ) Var divide = CreateWindowEx( 0,"BUTTON", "A/B", WS_VISIBLE Or WS_CHILD, 230,380 , 50, 30, hWnd, 0, 0, 0 ) Var lblA =CreateWindowEx( 0, "STATIC", "A = ",WS_VISIBLE Or WS_CHILD , 15, 85, 30, 30, hWnd, 0, 0, 0 ) Var lblB =CreateWindowEx( 0, "STATIC", "B = ",WS_VISIBLE Or WS_CHILD , 15, 285, 30, 30, hWnd, 0, 0, 0 ) 'loop While GetMessage( @msg, 0, 0, 0 ) TranslateMessage( @msg ) DispatchMessage( @msg ) Select Case msg.hwnd Case hWnd Select Case msg.message Case 273 End End Select '__________________ Case AddButton Select Case msg.message Case WM_LBUTTONDOWN OPERATE(1)'ADDUP End Select '____________________ Case minus Select Case msg.message Case WM_LBUTTONDOWN OPERATE(2)'SUBTRACT End Select '______________________ Case prod Select Case msg.message Case WM_LBUTTONDOWN OPERATE(3)' MULTIPLY End Select '_______________________ Case divide Select Case msg.message Case WM_LBUTTONDOWN OPERATE(4)'DIVIDE End Select End Select Wend Sub OPERATE(flag As Integer) Dim As String outtext1,outtext2,result Dim As Integer charcount1,charcount2 charcount1 = GetWindowTextLength(B1) charcount2 = GetWindowTextLength(B2) outtext1 = String(charcount1," ") outtext2 = String(charcount2," ") GetWindowText(B1,outtext1,charcount1+1) GetWindowText(B2,outtext2,charcount2+1) Select Case As Const flag Case 1:result= Str(Val(outtext1)+Val(outtext2)) Case 2:result= Str(Val(outtext1)-Val(outtext2)) Case 3:result= Str(Val(outtext1)*Val(outtext2)) Case 4:result= Str(Val(outtext1)/Val(outtext2)) End Select setWindowText(answer,result) End Sub
Re: Simple GUI
hi,
#32770 is the windows class number for dialog box. see the link below
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
273 is the code for WM_COMMAND. Normally there should be other tests before doing an action here it's a shortcut....
Information could be found on msdn.
There also an old file : win32.hlp a bit outdated however with precious information.
A best way is looking inside programs to understand how things are done. By example try with fbdebugger ;-)
#32770 is the windows class number for dialog box. see the link below
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
273 is the code for WM_COMMAND. Normally there should be other tests before doing an action here it's a shortcut....
Information could be found on msdn.
There also an old file : win32.hlp a bit outdated however with precious information.
A best way is looking inside programs to understand how things are done. By example try with fbdebugger ;-)
-
- Posts: 491
- Joined: Sep 28, 2013 15:08
- Location: Germany
Re: Simple GUI
Additionally to my "Simple GUI" project, I have written a TUI (for console or graphics window) and a small WinAPI library, see first post.
-
- Posts: 491
- Joined: Sep 28, 2013 15:08
- Location: Germany
Re: Simple GUI
WinAPI library updated on 01 July, 2015: Easier coding for menus (see first post)
Re: Simple GUI
The problem with using the #32770 style is that it's a system-defined class that, among other potential problems, specifies a system-defined window procedure. The normal way of working around this, processing messages in your message loop, does not provide the same capabilities as processing them in a window procedure that you control.
This code was tested only with Version 1.02.0 (03-23-2015), built for win64 (64bit), under Windows 8.1-64:
This code was tested only with Version 1.02.0 (03-23-2015), built for win64 (64bit), under Windows 8.1-64:
Code: Select all
#include "windows.bi"
function WindowClassStyleBits( style as UINT ) as string
dim as string rval, crlf = chr(13) & chr(10)
if style and CS_BYTEALIGNCLIENT then rval &= "CS_BYTEALIGNCLIENT" & crlf
if style and CS_BYTEALIGNWINDOW then rval &= "CS_BYTEALIGNWINDOW" & crlf
if style and CS_CLASSDC then rval &= "CS_CLASSDC" & crlf
if style and CS_DBLCLKS then rval &= "CS_DBLCLKS" & crlf
if style and CS_DROPSHADOW then rval &= "CS_DROPSHADOW" & crlf
if style and CS_GLOBALCLASS then rval &= "CS_GLOBALCLASS" & crlf
if style and CS_HREDRAW then rval &= "CS_HREDRAW" & crlf
if style and CS_NOCLOSE then rval &= "CS_NOCLOSE" & crlf
if style and CS_OWNDC then rval &= "CS_OWNDC" & crlf
if style and CS_PARENTDC then rval &= "CS_PARENTDC" & crlf
if style and CS_SAVEBITS then rval &= "CS_SAVEBITS" & crlf
if style and CS_VREDRAW then rval &= "CS_VREDRAW" & crlf
return rval
end function
dim as WNDCLASSEX wcx
'' Return value is non-zero for success, zero for failure:
print GetClassInfoEx( NULL, "#32770", @wcx )
print
with wcx
print "style = ";hex(.style,sizeof(.style)*2)
print "lpfnWndProc = ";hex(.lpfnWndProc,sizeof(.lpfnWndProc)*2)
print "cbClsExtra = ";.cbClsExtra
print "cbWndExtra = ";.cbWndExtra
print "hInstance = ";hex(.hInstance,sizeof(.hInstance)*2)
print "hIcon = ";hex(.hIcon,sizeof(.hIcon)*2)
print "hCursor = ";hex(.hCursor,sizeof(.hCursor)*2)
print "hbrBackground = ";hex(.hbrBackground,sizeof(.hCursor)*2)
print "lpszMenuName = ";hex(.lpszMenuName,sizeof(.lpszMenuName)*2)
print "lpszClassName = ";hex(.lpszClassName,sizeof(.lpszClassName)*2)
print "hIconSm = ";hex(.hIconSm,sizeof(.hIconSm)*2)
print
print WindowClassStyleBits(.style)
end with
sleep
Code: Select all
32770
style = 00000808
lpfnWndProc = 00007FFA5EB30F80
cbClsExtra = 0
cbWndExtra = 30
hInstance = 0000000000000000
hIcon = 0000000000000000
hCursor = 0000000000010003
hbrBackground = 0000000000000000
lpszMenuName = 0000000000000000
lpszClassName = 000000000040809E
hIconSm = 0000000000000000
CS_DBLCLKS
CS_SAVEBITS
-
- Posts: 491
- Joined: Sep 28, 2013 15:08
- Location: Germany
Re: Simple GUI
Thank you for your advice! May be useful, but ...
Well, I am not a WinAPI expert, so I do not really understand what you mean. I just studied the examples here http://freebasic.net/forum/viewtopic.php?f=7&t=13451 and some other simple WinAPI code by dodicat, and then I tried to hide all the cryptical WinAPI stuff with a lot of zeros and strange parameters into some easy to use subs and functions. My first attempt was to create a GUI for myself based on FBGFX, but then I saw that it would be lot of work to add other elements and features like a multiline textbox with scrollbars, pulldown menus, textboxes (numeric, password, right aligned or centered text) etc. I did not want to re-event the wheel (e.g. Muttonhead's sGUI). So I decided to build a simple WinAPI library for myself. It has all the functions I need, I do not intend to invest more time and work. If somebody can use it, it's fine. If he wants to modify it: no problem. The community seems not to be very interested in this WinAPI library. It has been downloaded nearly 50 times up to now, while my FBGFX based GUI has been downloaded more than 200 times.
Well, I am not a WinAPI expert, so I do not really understand what you mean. I just studied the examples here http://freebasic.net/forum/viewtopic.php?f=7&t=13451 and some other simple WinAPI code by dodicat, and then I tried to hide all the cryptical WinAPI stuff with a lot of zeros and strange parameters into some easy to use subs and functions. My first attempt was to create a GUI for myself based on FBGFX, but then I saw that it would be lot of work to add other elements and features like a multiline textbox with scrollbars, pulldown menus, textboxes (numeric, password, right aligned or centered text) etc. I did not want to re-event the wheel (e.g. Muttonhead's sGUI). So I decided to build a simple WinAPI library for myself. It has all the functions I need, I do not intend to invest more time and work. If somebody can use it, it's fine. If he wants to modify it: no problem. The community seems not to be very interested in this WinAPI library. It has been downloaded nearly 50 times up to now, while my FBGFX based GUI has been downloaded more than 200 times.
-
- Posts: 3954
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Simple GUI
Perhaps because the WinAPI doesn't work with Linux?Lothar Schirm wrote:The community seems not to be very interested in this WinAPI library. It has been downloaded nearly 50 times up to now, while my FBGFX based GUI has been downloaded more than 200 times.
I read some winAPI programming tutorials back in my Assembler and C days but essentially you have no control. It was all wrote learning without really being taught how to find what is required for your project from the winAPI documentation. If the tutorial didn't cover it you couldn't do it. With FreeBASIC I can make the GUI however I like including all that stuff you wrote you couldn't be bothered with.