Windows GUI

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

Re: Windows GUI

Post by Provoni »

Lothar,

Thanks allot for looking into it.
What do you mean by "is it also possible to keep the windows from being resized?"
With resizing I mean that the user can change the window size by click-dragging from one of the window corners. It's a minor issue on my end.
In order to erase all items in a listbox, use "Listbox_ResetContent".
Thanks, that will do.
So I will correct this in the next days, but I would like to wait if you find more errors.
----------------------------------------------------------
There may be a few more minor issues:

Code: Select all

if msg.message=wm_lbuttonup then ...
- Normally a click is registered after the button is released and the mouse is still over the button. Here I can click-not-release on the button, hover to somewhere else, and release and the click is registered for that button anyway.

- The left and top shading of buttons is very light, and seems to blend in too much with the background (that may be personal or a screen issue).

- Listboxes do not have a horizontal scroller if the text of its items > the box size.
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

I hope to share a preview of my program with you in the next week or so.

It is somewhat of a rewrite of http://www.freebasic.net/forum/viewtopi ... pt#p203927 but will have much more functionality. It will be a program for analysis, manipulation and solving of ciphers as well as general information. It will be used to attempt to solve the unsolved Zodiac 340 cipher and other unsolved classical ciphers. The current iteration of the program has a small userbase.
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Lothar,

In my program there are a couple of editboxes.

Code: Select all

EditBox_SetText(Edit_Text,"hello world")
I was wondering if it's possible to easily detect any change to an editbox. For example copy paste, or just plainly editing the text. One way would be to compare it to the previous string but that seems redundant.

Thanks
Lothar Schirm
Posts: 437
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Windows GUI

Post by Lothar Schirm »

Hi Provoni,

that's a lot. I try to answer.

1. You can prevent the resizing of the window if you change the window style in the function Window_New. I tried "WS_OVERLAPPED Or WS_SYSMENU Or WS_VISIBLE".

2. WM_LBUTTONUP, releasing the mouse outside of the button: No idea how to solve that problem.

3. Left and top shading of buttons is very light etc.: I use Windows 8.1, no problem on my computer.

4. Listbox: I use the WS_HSCROLL style (see function ListBox_New), I do not know why there is no horizontal scrollbar. I would be happy if it would work. Windows' mystery.

5. Detect a change in an editbox: There is an edit control notification message EN_CHANGE. I tried to use it, but it seems to work only if you use the RegisterClass function together with a WindowProc function, so that you have the usual complicated Windows API code for your window and all controls.
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Thanks Lothar,

It's working out just fine.
Kwabbernoot
Posts: 79
Joined: Apr 19, 2010 18:23
Location: NL

Re: Windows GUI

Post by Kwabbernoot »

Provoni,
There is a tutorial for Windows API. The examples are written in C. But even if you don't know C, the examples are not difficult to understand.
http://zetcode.com/gui/winapi/

Also a lot of examples on this forum and examples in the FreeBasic directory:
C:\Program Files (x86)\FreeBASIC\examples\GUI\win32
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Windows GUI

Post by fxm »

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

Re: Windows GUI

Post by Lothar Schirm »

There is also a tutorial "Erste Schritte in der WinAPI mit FBEdit" (First Steps in WinAPI with FBEdit), but only in german (https://www.freebasic-portal.de/tutoria ... t-104.html.
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Thanks Lothar.

Do you know how to track the x and y coordinates of a window after it has been moved by the user?

To further illustrate:

Code: Select all

window_main=window_new(100,100,1024,768,program_name)
So it starts at x: 100, y: 100. Suppose the user moves the window. At what coordinates is the window now?
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Windows GUI

Post by RNBW »

Provoni
Lothar Schirm wrote:There is also a tutorial "Erste Schritte in der WinAPI mit FBEdit" (First Steps in WinAPI with FBEdit), but only in german (https://www.freebasic-portal.de/tutoria ... t-104.html.
It's a good tutorial. It's well worthwhile using Google Translate to translate into your own language. There are lots of useful tutorials on this portal.

Ray
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Windows GUI

Post by dodicat »

Provoni wrote:Thanks Lothar.

Do you know how to track the x and y coordinates of a window after it has been moved by the user?

To further illustrate:

Code: Select all

window_main=window_new(100,100,1024,768,program_name)
So it starts at x: 100, y: 100. Suppose the user moves the window. At what coordinates is the window now?
I think you'll need to use getwindowrect somewhere in your code.

This example is independent of Lothar's Gui, I just threw it together to use the getwindowrect function.

Code: Select all

#Include "windows.bi"

Dim  As MSG msg
Dim  As HWND Main_Win,ClickWin
Main_Win=CreateWindowEx(0,"#32770","Move or re-size window and Click",WS_OVERLAPPEDWINDOW Or WS_VISIBLE,200,200,600,300,0,0,0,0)
ClickWin=CreateWindowEx(0,"Button","Click", WS_VISIBLE Or WS_CHILD,0,0,60,30,Main_win,0,0,0)

var z1=CreateWindowEx( 0,"STATIC","", ws_border Or WS_VISIBLE Or WS_CHILD ,150,50,100,20,  Main_win,0,0,0)
var z2=CreateWindowEx( 0,"STATIC","", ws_border Or WS_VISIBLE Or WS_CHILD ,150,100,100,20, Main_win,0,0,0)
var z3=CreateWindowEx( 0,"STATIC","", ws_border Or WS_VISIBLE Or WS_CHILD ,150,150,100,20, Main_win,0,0,0)
var z4=CreateWindowEx( 0,"STATIC","", ws_border Or WS_VISIBLE Or WS_CHILD ,150,200,100,20, Main_win,0,0,0)

var w1=createwindowex(0,"STATIC","Left edge ="   , WS_VISIBLE Or WS_CHILD,50,50,100,20,    Main_win,0,0,0)
var w2=createwindowex(0,"STATIC","Top edge = "   , WS_VISIBLE Or WS_CHILD,50,100,100,20,   Main_win,0,0,0)
var w3=createwindowex(0,"STATIC","    Width ="   , WS_VISIBLE Or WS_CHILD,50,150,100,20,   Main_win,0,0,0)
var w4=createwindowex(0,"STATIC","    Height ="  , WS_VISIBLE Or WS_CHILD,50,200,100,20,   Main_win,0,0,0)

freeconsole 'dont show the console box
While GetMessage( @msg,Main_Win,0,0)
    TranslateMessage(@msg)
    DispatchMessage(@msg)
    Select Case msg.hwnd
    Case Main_Win
        Select Case msg.message
        Case 273  'close by clicking X
            End
        End Select
    '-----------------------------     
    Case ClickWin
        Select Case msg.message  
        Case WM_LBUTTONDOWN
            dim as rect r
            getwindowrect(Main_win,@r)'<---- HERE
            var g=string(5," ")
            setWindowText(z1,g+str(r.left)) 
            setWindowText(z2,g+str(r.top)) 
            setWindowText(z3,g+str(r.right-r.left)) 
            setWindowText(z4,g+str(r.bottom-r.top)) 
            
        End Select
    '------------------------------ 
    End Select'(case main_win)
Wend
 
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Thanks allot dodicat. I should be able to work it out using your code. :)
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Lothar,

Another small issue. It seems not possible to use the TAB key to switch the cursor between other editboxes in the same window, is that something that could be added? It could follow the order in which the editboxes are created.

Code: Select all

label=label_new(20,420,50,25,"F1:",,window_textfunctions)
textfunctions1_text=editbox_new(50,420,310,25,"",,window_textfunctions)
label=label_new(20,460,50,25,"F2:",,window_textfunctions)
textfunctions2_text=editbox_new(50,460,310,25,"",,window_textfunctions)
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

More code that shows one of the side windows of the main program that can be opened. Note that you cannot use the TAB key to switch between editbox F1 and F2.

Code: Select all

'includes
#include "wingui.bi"
#include "windialogs.bi"

'window_main
dim shared as msg msg
dim shared as hwnd label

'window_textfunctions
dim shared as hwnd window_textfunctions
dim shared as hwnd list_textfunctions
dim shared as hwnd textfunctions1_text
dim shared as hwnd textfunctions2_text
dim shared as hwnd button_textfunctions_process

declare sub create_window_textfunctions

create_window_textfunctions

do
	
	waitevent(msg)

loop until window_event_close(window_textfunctions,msg)

sub create_window_textfunctions
	
	destroywindow(window_textfunctions)
	window_textfunctions=window_new(100,100,400,590,"Text functions")
	list_textfunctions=listbox_new(20,20,340,400,window_textfunctions)
	
	listbox_addstring(list_textfunctions,"Ceasar letter shift (F1)")
	listbox_addstring(list_textfunctions,"Convert diacritics to letters")
	listbox_addstring(list_textfunctions,"Convert letters to lowercase")
	listbox_addstring(list_textfunctions,"Convert letters to uppercase")
	listbox_addstring(list_textfunctions,"Expand characters (F1)")
	listbox_addstring(list_textfunctions,"Invert lowercase and uppercase")
	listbox_addstring(list_textfunctions,"Reduce length to (F1)")
	listbox_addstring(list_textfunctions,"Remove characters frequency > (F1)")
	listbox_addstring(list_textfunctions,"Remove characters frequency < (F1)")
	listbox_addstring(list_textfunctions,"Remove chars freq > (F1) and < (F2)")
	listbox_addstring(list_textfunctions,"Remove consonants")
	listbox_addstring(list_textfunctions,"Remove characters (F1)")
	listbox_addstring(list_textfunctions,"Remove diacritics")
	listbox_addstring(list_textfunctions,"Remove letters")
	listbox_addstring(list_textfunctions,"Remove lowercase")
	listbox_addstring(list_textfunctions,"Remove line breaks")
 	listbox_addstring(list_textfunctions,"Remove numbers")
	listbox_addstring(list_textfunctions,"Remove spaces")
	listbox_addstring(list_textfunctions,"Remove symbols")
	listbox_addstring(list_textfunctions,"Remove tabs")
	listbox_addstring(list_textfunctions,"Remove uppercase")
	listbox_addstring(list_textfunctions,"Remove vowels")
	listbox_addstring(list_textfunctions,"Replace characters (F1 with F2)")
	listbox_addstring(list_textfunctions,"Replace string (F1 with F2)")
	
	listbox_setcursel(list_textfunctions,0)
	label=label_new(20,420,50,25,"F1:",,window_textfunctions)
	textfunctions1_text=editbox_new(50,420,310,25,"",,window_textfunctions)
	label=label_new(20,460,50,25,"F2:",,window_textfunctions)
	textfunctions2_text=editbox_new(50,460,310,25,"",,window_textfunctions)
	button_textfunctions_process=button_new(20,500,340,30,"Process",window_textfunctions)

end sub
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Windows GUI

Post by Josep Roca »

Another small issue. It seems not possible to use the TAB key to switch the cursor between other editboxes in the same window, is that something that could be added?
To use the TAB key, instead of

Code: Select all

do
   waitevent(msg)
loop until window_event_close(window_textfunctions,msg)
you need to use a message pump like this:

Code: Select all

WHILE (GetMessage(@msg, NULL, 0, 0) <> FALSE)
   IF IsDialogMessage(hWndMain, @msg) = 0 THEN
      TranslateMessage(@msg)
      DispatchMessage(@msg)
   END IF
WEND
Last edited by Josep Roca on Oct 16, 2016 1:23, edited 1 time in total.
Post Reply