Windows GUI

New to FreeBASIC? Post your questions here.
Post Reply
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Windows GUI

Post by MrSwiss »

Kamui_Kazuma wrote:i've been using MSPaint for creating icons as bitmaps with a pixel depth of 4.
Maybe I'm on the right track now.
You can't just use a bitmap file (.bmp), you've first to convert it to .ico FORMAT.
(It can hold multiple *resolutions* of the same *design* [multiple .bmp's / .png's etc.])
There are plenty converters out there (the Internet).

I usually make .png files and convert from there ... (to .ico format).
Kamui_Kazuma
Posts: 14
Joined: Oct 23, 2016 1:22

Re: Windows GUI

Post by Kamui_Kazuma »

MrSwiss wrote: You can't just use a bitmap file (.bmp), you've first to convert it to .ico FORMAT...
I usually make .png files and convert from there ... (to .ico format).
Sorry, I feel very stupid right now.
  1. Here's what I've been doing from the top:("verbose mode engaged!")
  2. Open MS Paint
  3. Resize to 64 x 64
  4. Draw the image
  5. Save As
  6. Select .bmp from the list
  7. Replace the file extention with .ico
  8. Save the image as icon.ico
  9. Write an .rc file with this

    Code: Select all

     FB_PROGRAM_ICON ICON "icon.ico"
    called "icon.rc"
  10. Compile using:

    Code: Select all

    \fbc.exe <[i]put filename here[/i]>.bas icon.rc -g
This worked fine during a recent test on WinXP Professional in which I copied the files & the FB directory onto a flash drive and compiled on that computer.

Also, Thanks for helping me with this, really.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Windows GUI

Post by MrSwiss »

Kamui_Kazuma wrote:Also, Thanks for helping me with this, really.
You're welcome.

I'd actually (falsely) assumed, that you're using a *real* icon.ico - file, from a internet source,
at least for *first* tests (that would be my first approach, to something entirely *new*).

Step by step approach:
  • using a properly displaying *.ico
  • writing the necessary *.rc
  • first compile/test
  • if (and only if) all OK
  • make first own ICON
  • ...
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Windows GUI

Post by St_W »

Kamui_Kazuma wrote:
This link apparently has some relation to some sort of malware, please look into this.
Also where is this icon from?
Malware? I am pretty sure the site is perfectly fine. I just chose a random one from the site iconarchive.com: http://www.iconarchive.com/show/ids-3d- ... -icon.html
Kamui_Kazuma
Posts: 14
Joined: Oct 23, 2016 1:22

Re: Windows GUI

Post by Kamui_Kazuma »

St_W wrote:Malware? I am pretty sure the site is perfectly fine. I just chose a random one from the site iconarchive.com: http://www.iconarchive.com/show/ids-3d- ... -icon.html
In that case I think AVG's being overly sensitive, as per usual.
Kamui_Kazuma
Posts: 14
Joined: Oct 23, 2016 1:22

Re: Windows GUI

Post by Kamui_Kazuma »

To all of you who've helped me, Thanks a great deal. I've gotten it working now. (^^)
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Hey all,

I'm trying to set up a button which text can be changed to another string by clicking it. Here's what I have so far and is not working correctly. There's no function within Lothar's Simple GUI library that accomodates.

Thanks

Code: Select all

#include "wingui.bi"

dim as hwnd window_main,editor_txt,button_ok(10)
dim as msg msg
dim as integer i

window_main=window_new(100,100,400,400,"window")
button_ok(7)=button_new(50,50,280,260,"change button text by clicking it",,window_main)

do
	waitevent(window_main, msg)
	for i=1 to 10
		if msg.message=wm_lbuttondown and button_ok(i)=0 then
			'attempt to change button text
			button_ok(7)=button_new(50,50,280,260,"doesn't stay",,window_main)
		end if
	next i
loop until window_event_close(window_main, msg)

end
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: Windows GUI

Post by sancho2 »

You can use Label_SetText to change the text since the button is simply a window as is a label:

Code: Select all

#include "c:\freebasic stuff\wingui\wingui(11)\wingui.bi"

dim as hwnd window_main,editor_txt,button_ok(10)
dim as msg msg
dim as integer i

window_main=window_new(100,100,400,400,"window")
button_ok(7)=button_new(50,50,280,260,"change button text by clicking it",,window_main)

do
   waitevent(window_main, msg)
   'for i=1 to 10
      if msg.message=wm_lbuttondown and button_ok(i)=0 then
         'attempt to change button text
         Label_SetText(button_ok(7), "does stay")
      end if
   'next i
loop until window_event_close(window_main, msg)

end
Note that I dismissed the for/next loop here.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Thank you very much sancho2.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Would anyone happen to know how to change the color of a label/button/window?

Thanks
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: Windows GUI

Post by sancho2 »

Changing the color of a button is routine in higher level languages but it is convoluted in windows api (WinGUI is a set of wrappers for the api).
Coloring a button requires responding to the windows api message WM_CTLCOLORBTN. Essentially, every time the control is drawn/re-drawn, the message is sent and in the loop where windows events are processed, you will have to create a BRUSH of the color and return it. You will also have to destroy it at some point to avoid memory leak.
Since this is more involved you might want to start a new thread in the Windows forum.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Ok thank you.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Hello,

The following editor/code supports the use of CTRL-X,C,V to copy text around but CTRL-A to select all does not work. Does anyone know how to add CTRL-A support?

Thanks

Code: Select all

'===============================================================================
' Editor.bas
' Simple Text Editor
' Created on September 09, 2014
' Latest change on October 20, 2016
'===============================================================================

#Include "WinGUI.bi"
#Include "WinDialogs.bi"

Dim Shared As HWND Window_Main, Edit_Text
Dim As MSG msg
Dim Shared As String file, filter, text
Dim As Long x0, y0, x1, y1

Declare Sub FileSave()


'Filter for LoadSaveDialog:
filter = "Basic Files (*.bas)" + Chr(0) + "*.bas" + Chr(0) _
					+ "Text Files (*.txt)" + Chr(0) + "*.txt" + Chr(0)_
					+ "All Files (*.*)" + Chr(0) + "*.*" + Chr(0, 0)

Sub FileNew()
	'New file
	
	If Len(EditBox_GetText(Edit_Text)) > 0 Then
		If MessageBox(0, "Save text?", "Save", MB_YESNO Or MB_ICONQUESTION) = IDYES Then FileSave()
		EditBox_SetText(Edit_Text, "")
	End If
	file = ""
	SetWindowText(Window_Main, "New File")	
	
End Sub


Sub FileOpen()
	'Open a file
	
	Dim As String Buffer
	
	If Len(EditBox_GetText(Edit_Text)) > 0 Then
		If MessageBox(0, "Save text?", "Save", MB_YESNO Or MB_ICONQUESTION) = IDYES Then FileSave()
	End If
	EditBox_SetText(Edit_Text, "")
	file = LoadSaveDialog(, filter)
	If file <> "" Then
		Open file For Binary As #1
		Buffer = Space(LOF(1))
		Get #1,, Buffer
		Close #1
		EditBox_SetText(Edit_Text, Buffer)
		SetWindowText(Window_Main, file)
	End If
		
End Sub


Sub FileSave()
	'Save file
	
	file = LoadSaveDialog(1, filter) 
	If file <> "" Then
		Open file For Binary As #1
		Put #1,, EditBox_GetText(Edit_Text)
		Close #1
		SetWindowText(Window_Main, file)
	End If
		
End Sub


Sub FileExit()
	'End
	
	If Len(EditBox_GetText(Edit_Text)) > 0 Then
		If MessageBox(0, "Save text?", "Save", MB_YESNO Or MB_ICONQUESTION) = IDYES Then FileSave()
	End If
	
	End

End Sub


Sub Info()
'Info anzeigen

	MessageBox(0, "Simple text editor, created in FreeBasic", "Info", MB_OK Or MB_ICONINFORMATION)
								
End Sub



Sub CreateWindow_Main()
	'Main Window with menu and text editor
	
	Dim As HMENU hMenu, hFile, hEdit, hHelp
	
	Window_Main = Window_New(100, 100, 800, 500, "Text Editor")
	
	hMenu = CreateMenu()
	hEdit = CreateMenu()
	hFile = CreateMenu()
	hHelp = CreateMenu()

	MenuTitle(hMenu, hFile, "File")
	MenuTitle(hMenu, hEdit, "Edit")
	MenuTitle(hMenu, hHelp, "Help")

	MenuItem(hFile, 1, "New")
	MenuItem(hFile, 2, "Open")
	MenuItem(hFile, 3, "Save")
	MenuItem(hFile, 4, "Exit")
	MenuItem(hEdit, 5, "Undo")
	MenuItem(hEdit, 6, "Cut")
	MenuItem(hEdit, 7, "Copy")
	MenuItem(hEdit, 8, "Paste")
	MenuItem(hEdit, 9, "Delete")
	MenuItem(hHelp, 10, "Info")
	
	SetMenu(Window_Main, hMenu )
	
	Edit_Text = Editor_New(10, 10, 780, 480, "",, Window_Main)
	Control_SetFont(Edit_Text, "Courier New")
	
End Sub


'Main:

CreateWindow_Main()

Do
	WaitEvent(Window_Main, msg)

	Select Case msg.hwnd
	
    Case Window_Main
      Select Case msg.message
				Case WM_COMMAND	'Menu commands
					Select Case msg.wParam
            Case 1
						  FileNew()
            Case 2
              FileOpen()
            Case 3
              FileSave()
            Case 4
              FileExit()
            Case 5
							EditBox_Undo(Edit_Text)
						Case 6
							EditBox_Cut(Edit_Text)
						Case 7
							EditBox_Copy(Edit_Text)
						Case 8
							EditBox_Paste(Edit_Text)
						Case 9
							EditBox_Clear(Edit_Text)
						Case 10
							Info()
          End Select
        Case Else
					'Resize editor if window size is changed
	        Window_GetSize(Window_Main, x0, y0, x1, y1)
	        Control_Resize(Edit_Text, 20, 20, x1 - 30, y1 - 30)  
      End Select
      
  End Select
  
Loop Until Window_Event_Close(Window_Main, msg)

End
SARG
Posts: 1756
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Windows GUI

Post by SARG »

Hi,

Try that, see below at the end of the loop.

Code: Select all

Do
   WaitEvent(Window_Main, msg)

   Select Case msg.hwnd
   
    Case Window_Main
      Select Case msg.message
            Case WM_COMMAND   'Menu commands
               Select Case msg.wParam
            Case 1
                    FileNew()
            Case 2
              FileOpen()
            Case 3
              FileSave()
            Case 4
              FileExit()
            Case 5
                     EditBox_Undo(Edit_Text)
                  Case 6
                     EditBox_Cut(Edit_Text)
                  Case 7
                     EditBox_Copy(Edit_Text)
                  Case 8
                     EditBox_Paste(Edit_Text)
                  Case 9
                     EditBox_Clear(Edit_Text)
                  Case 10
                     Info()
          End Select
        Case Else
               'Resize editor if window size is changed
           Window_GetSize(Window_Main, x0, y0, x1, y1)
           Control_Resize(Edit_Text, 20, 20, x1 - 30, y1 - 30) 
   
      End Select
   
   ''================================== lines added============================
   Case edit_text
      If msg.message=WM_KEYUP Then
         If msg.wparam=VK_A Then
            If (getketstate(VK_CONTROL) And &h8000) Then SendMessage(edit_text,EM_SETSEL,0,-1)
         EndIf
      EndIf
   ''===== end of added lines ==========
  End Select
  
Loop Until Window_Event_Close(Window_Main, msg)

End
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows GUI

Post by Provoni »

Thanks SARG,

It works but a windows sound is heard when using the CTRL-A shortcut, like the command is not supported. This sound is also heard without your added code and with other CTRL shortcuts which have no function. Anything to do about that?
Post Reply