Windows GUI

New to FreeBASIC? Post your questions here.
Post Reply
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Windows GUI

Post by Provoni »

Hey all,

So far I've been writing my programs using a self coded GUI using mouse and draw functions. Now I would like to create a program with a - preferably modern - Windows UI look but I don't have the slightest clue where to start. There are some dead links in the FAQ and info from searches seem to be outdated. Using FbEdit and Windows 7.

The program will be somewhat graphical and it would be great if I could still use the FreeBASIC draw functions. The top of the program should have menu buttons like File and Edit (ability to open files through the Windows Open file menu) . Then one row with various shortcut pictograms and under that a program window (workspace) where everything is drawn etc.

Thanks
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Windows GUI

Post by MrSwiss »

Try below for starters ...
WinGUI by Lothar Schirm
Lothar Schirm
Posts: 436
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Windows GUI

Post by Lothar Schirm »

Hi Provoni,

my WinGUI does not support graphics or pictograms/icons, but you can use it in parallel with a FreeBasic graphics screen where you can draw something or run an animation etc., also probably your self coded GUI (if there is no conflict with variable names between your GUI and WinGUI).

There is also a very comfortable Windows GUI designer which works in a similiar way as Visual Basic: FireFly http://www.freebasic.net/forum/viewtopi ... it=firefly, but it generates rather complex code with several files in a user definable project folder, so it is more suitable for larger projects.
JohnK
Posts: 279
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: Windows GUI

Post by JohnK »

I also like fltk (see libs section). Demos run no problem. I find that once you start gui, you will invest a lot of time learning it. So pick a good powerful one if you are going to make more programs
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Thanks allot for the updates people. I'll take a look at them.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

FireFly is up and running.

I have used the menu editor to create a menu called File with under it Open file.

- How to attach code to such objects?
- Do I need to write code in FbEdit or in FireFly?

Thanks
PaulSquires
Posts: 999
Joined: Jul 14, 2005 23:41

Re: Windows GUI

Post by PaulSquires »

Check out the support forum at http://www.planetsquires.com/protect/forum/index.php

There are thousands and thousands of lines of code that explain how to do just about anything Windows programming using Firefly. The code is Win32 API based so it will require some learning and research if you are new to programming.
Lothar Schirm
Posts: 436
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Windows GUI

Post by Lothar Schirm »

Hi Provoni,

please have a look at the FireFly help file (FireFly.chm), chapter "User Reference Guide - Menu Editor". You must write your code into the WM_COMMAND function of your form. For writing code using Windows API functions, you can use the FireFly Functions library in most cases.

A question to Paul Squires: In the first releases were several examples which I did not find in my release (3.77, I did not update to the latest, I believe). Are these still available? I think they would be helpful for beginners.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Okay thanks all, that will do.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Lothar, I'm going ahead with your WinGUI. I like the incredible simplicity of it.
Lothar Schirm
Posts: 436
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Windows GUI

Post by Lothar Schirm »

Good luck!
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Lothar,

What is the keyword to close a window? I've not been able to find it going through the code examples. My program needs multiple windows for various functions.

This is what I have for the main window.

Code: Select all

loop until window_event_close(window_main,msg)
And want something like this for a secondary window. (close_window does not work, just an example of what I thought the keyword could be)

Code: Select all

if window_event_close(window_replace,msg) then
	close_window(window_replace,msg)
end if
Thanks

Edit: is it also possible to keep the windows from being resized?
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Lothar,

There seems to be a problem with the listbox. I modified the code listbox.bas to show it. Run it and click Erase list, only the even entries are removed. My program needs all entries to be removed.

Also replacing an item in the list with an empty string crashes the program.

Thanks

Code: Select all

'modified by Provoni

'===============================================================================
' Listbox.bas
' Test Listbox
' Created on January 26, 2016
' Last changes on July 14, 2016
'===============================================================================

#Include "WinGUI.bi"

Dim As MSG msg
Dim As HWND WinMain, List, Edit_Index, Edit_SelText, Edit_Text, Button_Add, _
						Button_Delete, Button_Insert, Button_Replace,button_eraselist
Dim As Integer i, index

'Create window:
WinMain = Window_New					(100, 100, 400, 400, "Test Listbox")
List = ListBox_New						(20, 20, 150, 300, WinMain)
Var Label_Index = Label_New		(200, 50, 150, 20, "Selected index:",, WinMain)
Edit_Index = EditBox_New			(200, 70, 150, 20, "", ES_CENTER Or ES_READONLY, WinMain)
Var Label_SelText = Label_New	(200, 100, 150, 20, "Selected text:",, WinMain)
Edit_SelText = EditBox_New		(200, 120, 150, 20, "", ES_READONLY, WinMain)
Button_Delete = Button_New		(200, 150, 150, 20, "Delete selected item", WinMain)
Edit_Text = EditBox_New				(200, 200, 150, 20, "Type text here",, WinMain)
Button_Add = Button_New				(200, 230, 150, 20, "Add to list", WinMain)
Button_Insert = Button_New		(200, 260, 150, 20, "Insert", WinMain)
Button_Replace = Button_New		(200, 290, 150, 20, "Replace", WinMain)
button_eraselist=button_new(200,320,150,20,"Erase list",winmain)


For i = 0 To 20
	ListBox_AddString(List, "Item number " + Str(i))
Next
ListBox_SetCurSel(List, 0)

Do
	WaitEvent(msg)
	If msg.message = WM_LBUTTONDOWN Then
		Select Case msg.hwnd
			case List
				index = ListBox_GetCurSel(List)
				EditBox_SetText(Edit_Index, Str(index))
				EditBox_SetText(Edit_SelText, ListBox_GetText(List, index))
			Case Button_Add
				ListBox_AddString(List, EditBox_GetText(Edit_Text))
			Case Button_Delete
				ListBox_DeleteString(List, index)
			Case Button_Insert
				ListBox_InsertString(List, index, EditBox_GetText(Edit_Text))
			Case Button_Replace
				ListBox_ReplaceString(List, index, EditBox_GetText(Edit_Text)) 
			case button_eraselist
				for i=0 to 100
					listbox_deletestring(list,i)
				next i
		End Select
	End If
Loop Until Window_Event_Close(WinMain, msg)

End
Lothar Schirm
Posts: 436
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Windows GUI

Post by Lothar Schirm »

Provoni wrote:Lothar,

What is the keyword to close a window? I've not been able to find it going through the code examples. My program needs multiple windows for various functions.

This is what I have for the main window.

Code: Select all

loop until window_event_close(window_main,msg)
And want something like this for a secondary window. (close_window does not work, just an example of what I thought the keyword could be)

Code: Select all

if window_event_close(window_replace,msg) then
	close_window(window_replace,msg)
end if
Thanks

Edit: is it also possible to keep the windows from being resized?
You can close a window with the Windows API function "DestroyWindow":

Code: Select all

if window_event_close(window_replace,msg) then
	DestroyWindow(window_replace)
end if
See function InputBox in WinGUI.bi

What do you mean by "is it also possible to keep the windows from being resized?" Do you want to create a window without a maximize/minimize box? Then you would have to change the code of the function Window_New in WinGUI.bi. If you look into the help file win32_fb.chm, you will find the window styles in the index "CreateWindow". WS_OVERLAPPEDWINDOW should then be replaced by WS_OVERLAPPED Or WS_SYSMENU Or WS_CAPTION. My proposal for you would be to add a parameter "Style" in the Window_New parameter list so that you can vary the style as you need, with a predefined style.

And now I will look at your problem with the listbox.
Last edited by Lothar Schirm on Oct 09, 2016 14:41, edited 1 time in total.
Lothar Schirm
Posts: 436
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Windows GUI

Post by Lothar Schirm »

Provoni wrote:Lothar,

There seems to be a problem with the listbox. I modified the code listbox.bas to show it. Run it and click Erase list, only the even entries are removed. My program needs all entries to be removed.

Also replacing an item in the list with an empty string crashes the program.
In order to erase all items in a listbox, use "Listbox_ResetContent".

Code: Select all

case button_eraselist
	Listbox_ResetContent(list)
Replacing an item in the listbox with an empty string will cause an eror in the Sub ListBox_InsertString, because StrPtr(text) = 0. So I will correct this in the next days, but I would like to wait if you find more errors.
Post Reply