GUI library for Windows \ Linux (window9)

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
applepi
Posts: 19
Joined: Oct 27, 2008 15:50

Post by applepi »

thank you VANYA,
the examples works greatly.
pmilano
Posts: 22
Joined: Jul 03, 2011 16:25
Location: Illinois

Post by pmilano »

I am new to freebasic and fbgui. The following code seems to work. Are there problems with it? such as the event close?

Code: Select all

'The Calculator Code
'--------------------------------------------------------------------------------
'FreeBasic Calculator - Patrick J. Milano
'Copyright 2011
'------------------------------------------------------------------------
'This source release As free-software.  It is Not in the public domain,
'however you may use it, change it, sell it, Or re-release it 
'without obtaining permission from the author.  You may Not transfer these
'rights.  This notice must be somewhere in you code And/Or documenation.
'Please credit the original author in derived works.
'------------------------------------------------------------------------
'This code is based on the calculator code for Liberty Basic developed as
'LB Calculator - by Brad Moore
'Copyright 2004
'--------------------------------------------------------------------------
#Include "window9.bi"

Enum e
  WMAIN
  MENU_MAIN
  DISPLAY1  
  BTN_9
  BTN_8
  BTN_7
  BTN_6
  BTN_5
  BTN_4
  BTN_3
  BTN_2
  BTN_1
  BTN_0
  BTN_DECIMAL
  BTN_QUIT
  BTN_CLEAR
  BTN_PLUS
  BTN_MINUS
  BTN_MULTIPLY
  BTN_DIVIDE
  BTN_EQUALS
  BTN_CLEAR_ENTRY
  KEYPAD_9
  KEYPAD_8
  KEYPAD_7
  KEYPAD_6
  KEYPAD_5
  KEYPAD_4
  KEYPAD_3
  KEYPAD_2
  KEYPAD_1
  KEYPAD_0
  KEYPAD_DECIMAL
  KEY_Q_QUIT
  KEY_C_CLEAR
  KEYPAD_PLUS
  KEYPAD_MINUS
  KEYPAD_MULTIPLY
  KEYPAD_DIVIDE
  KEYPAD_ENTER_EQUALS
  KEY_E_CLEAR_ENTRY
End Enum  
  
Dim As HWND hwnd  
Dim Shared As String buffer
Dim Shared As String currentop
Dim Shared As String lastop
Dim Shared As Double eval = 0
Dim As Integer Position, event, quit = 0
Dim As String Text
Dim As Long Result
Dim As Integer W_Width = 415
Dim As Integer W_Height = 330

'-----Declarations
Declare Sub Operation()

'-----End of Declarations

'-----Begin code For main Window
hwnd = OpenWindow("Calculator", 0, 0, W_Width, W_Height)
	CenterWindow(hwnd)
	WindowColor(hwnd,BGR(200,200,200))

'-----Begin Gadget List for window
	StringGadget(DISPLAY1, 20, 15, 365, 25, "", SS_RIGHT,WS_EX_CLIENTEDGE)
	LoadFont("Courier New",16)
	SetGadgetFont(DISPLAY1)
  	ButtonGadget(BTN_9,170,87,65,40,"9")
  	ButtonGadget(BTN_8,95,87,65,40,"8")
  	ButtonGadget(BTN_7,20,87,65,40,"7")
  	ButtonGadget(BTN_6,170,137,65,40,"6")
  	ButtonGadget(BTN_5,95,137,65,40,"5")
  	ButtonGadget(BTN_4,20,137,65,40,"4")
  	ButtonGadget(BTN_3,170,187,65,40,"3")
  	ButtonGadget(BTN_2,95,187,65,40,"2")
  	ButtonGadget(BTN_1,20,187,65,40,"1")
  	ButtonGadget(BTN_0,20,237,140,40,"0")
  	ButtonGadget(BTN_DECIMAL,170,237,65,40,".")
  	ButtonGadget(BTN_QUIT,20,52,65,25,"&Quit")
  	ButtonGadget(BTN_CLEAR,95,52,140,25,"&C")
  	ButtonGadget(BTN_PLUS,245,87,65,40,"+")
  	ButtonGadget(BTN_MINUS,245,137,65,40,"-")
  	ButtonGadget(BTN_MULTIPLY,245,187,65,40,"*")
  	ButtonGadget(BTN_DIVIDE,245,237,65,40,"/")
  	ButtonGadget(BTN_EQUALS,320,87,65,190,"=")
  	ButtonGadget(BTN_CLEAR_ENTRY,245,52,140,25,"C&E")
  
  	'-----End Gadget List  
  
'-----Begin Keyboard Shortcuts for Window  
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD9,KEYPAD_9)  
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD8,KEYPAD_8) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD7,KEYPAD_7) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD6,KEYPAD_6) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD5,KEYPAD_5) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD4,KEYPAD_4)  
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD3,KEYPAD_3) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD2,KEYPAD_2) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD1,KEYPAD_1) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD0,KEYPAD_0) 
  AddKeyboardShortcut(hwnd,0,VK_DECIMAL,KEYPAD_DECIMAL)  
  AddKeyboardShortcut(hwnd,0,VK_Q,KEY_Q_QUIT) 
  AddKeyboardShortcut(hwnd,0,VK_C,KEY_C_CLEAR) 
  AddKeyboardShortcut(hwnd,0,VK_ADD,KEYPAD_PLUS) 
  AddKeyboardShortcut(hwnd,0,VK_SUBTRACT,KEYPAD_MINUS) 
  AddKeyboardShortcut(hwnd,0,VK_MULTIPLY,KEYPAD_MULTIPLY) 
  AddKeyboardShortcut(hwnd,0,VK_DIVIDE,KEYPAD_DIVIDE) 
  AddKeyboardShortcut(hwnd,0,VK_RETURN,KEYPAD_ENTER_EQUALS) 
  AddKeyboardShortcut(hwnd,0,VK_E,KEY_E_CLEAR_ENTRY)
  
'-----End Keyboard Shortcuts  

'-----Main operating code--------------------------------
'--------------------------------------------------------
'-----Loop to get keystokes and operate the calculator
Do
  Event = WindowEvent()
  If Event = EventGadget Then
  	 Select Case eventnumber
        Case BTN_0
          buffer = buffer + "0"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_1
          buffer = buffer + "1"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_2
          buffer = buffer + "2"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_3
          buffer = buffer + "3"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_4
          buffer = buffer + "4"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_5
          buffer = buffer + "5"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_6
          buffer = buffer + "6"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_7
          buffer = buffer + "7"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_8
          buffer = buffer + "8"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_9
          buffer = buffer + "9"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_DECIMAL
          'if buffer already has a decimal, ignore this keypress
          Position = instr(buffer,".")
          If Position = 0 Then
            buffer = buffer + "."
            SetGadgetText(DISPLAY1,buffer)
          EndIf
        Case BTN_QUIT   '----Quit the program  
          'Event = End
          End 
        Case BTN_CLEAR
          '----C clears everything and starts at the beginning
          buffer=""
          lastop= ""
          currentop=""
          eval=0
          SetGadgetText(DISPLAY1,"0")
        Case BTN_PLUS
          '---Add buffer to eval
          currentop = "+"
          Operation()
        Case BTN_MINUS
          currentop = "-"
          Operation()
        Case BTN_MULTIPLY
          currentop = "*"
          Operation()
        Case BTN_DIVIDE
          currentop = "/"
          Operation()
        Case BTN_EQUALS
          currentop = "="
          Operation()
        Case BTN_CLEAR_ENTRY
          buffer = RTrim(Str(eval),"0")
          If Val(buffer) = 0 Then
            buffer = ""
            SetGadgetText(DISPLAY1,"")
          Else
            SetGadgetText(DISPLAY1,buffer)
            buffer=""
          EndIf          
      End Select
   EndIf
   If Event = EventMenu Then
      Select Case EventNumber
      	Case KEYPAD_0
          buffer = buffer + "0"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_1
          buffer = buffer + "1"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_2
          buffer = buffer + "2"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_3
          buffer = buffer + "3"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_4
          buffer = buffer + "4"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_5
          buffer = buffer + "5"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_6
          buffer = buffer + "6"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_7
          buffer = buffer + "7"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_8
          buffer = buffer + "8"
          SetGadgetText(DISPLAY1,buffer)
        Case KEYPAD_9
          buffer = buffer + "9"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_DECIMAL
          'if buffer already has a decimal, ignore this keypress
          Position = instr(buffer,".")
          If Position = 0 Then
            buffer = buffer + "."
            SetGadgetText(DISPLAY1,buffer)
          EndIf
        Case KEY_Q_QUIT   '----Quit the program  
          End
		  Case KEY_C_CLEAR
          '----C clears everything and starts at the beginning
          buffer=""
          lastop= ""
          currentop=""
          eval=0
          SetGadgetText(DISPLAY1,"0")
        Case KEYPAD_PLUS
          '---Add buffer to eval
          currentop = "+"
          Operation()
        Case KEYPAD_MINUS
          currentop = "-"
          Operation()
        Case KEYPAD_MULTIPLY
          currentop = "*"
          Operation()
        Case KEYPAD_DIVIDE
          currentop = "/"
          Operation()
        Case  KEYPAD_ENTER_EQUALS
          currentop = "="
          Operation()
        Case KEY_E_CLEAR_ENTRY
          buffer = RTrim(Str(eval),"0")
          If Val(buffer) = 0 THEN
            buffer = ""
            SetGadgetText(DISPLAY1,"")
          Else
           SetGadgetText(DISPLAY1,buffer)
            buffer=""
          EndIf          
      End Select      
  EndIf    
             
  Loop Until Event = EventClose
  End
  
'------------Begin Procedures For Calculator
'-----------------------------------------------------------
  
'-----Handle the math and display operators
Sub Operation()
  '--This routine will execute any buffered operation
  If lastop = "" Then
    lastop = currentop
    'Sometimes people press an operation when a value is displayed after
    'the equals key - buffer is null then - check for a value displayed
    If buffer = "" Then
      buffer = GetGadgetText(DISPLAY1)
    EndIf
    eval = Val(buffer)
    buffer= ""
  Else
    If lastop = "-" Then
      eval = eval - Val(buffer)
    EndIf
    If lastop = "+" Then
      eval = eval + Val(buffer)
    EndIf
    If lastop = "/" Then
      '--Protect against divide by zero
      If Val(buffer) = 0 Then 
        'Return     'do nothing
      Else
      	eval = eval / Val(buffer)
      EndIf	
    EndIf  
    If lastop = "*" Then
      eval = eval * Val(buffer)
    EndIf
  EndIf  
  
  If currentop = "=" Then
    lastop = ""
    currentop = ""
    buffer = ""
    SetGadgetText(DISPLAY1,RTrim(Str(eval),"0"))
    eval = 0
  Else
    lastop = currentop
    buffer = ""
    SetGadgetText(DISPLAY1,RTrim(Str(eval),"0"))
  EndIf  
End Sub

[/code]
VANYA
Posts: 1859
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Post by VANYA »

pmilano wrote:I am new to freebasic and fbgui. The following code seems to work. Are there problems with it? such as the event close?

Code: Select all

'The Calculator Code
'--------------------------------------------------------------------------------
'FreeBasic Calculator - Patrick J. Milano
'Copyright 2011
'------------------------------------------------------------------------
'This source release As free-software.  It is Not in the public domain,
'however you may use it, change it, sell it, Or re-release it 
'without obtaining permission from the author.  You may Not transfer these
'rights.  This notice must be somewhere in you code And/Or documenation.
'Please credit the original author in derived works.
'------------------------------------------------------------------------
'This code is based on the calculator code for Liberty Basic developed as
'LB Calculator - by Brad Moore
'Copyright 2004
'--------------------------------------------------------------------------
#Include "window9.bi"

Enum e
  WMAIN
  MENU_MAIN
  DISPLAY1  
  BTN_9
  BTN_8
  BTN_7
  BTN_6
  BTN_5
  BTN_4
  BTN_3
  BTN_2
  BTN_1
  BTN_0
  BTN_DECIMAL
  BTN_QUIT
  BTN_CLEAR
  BTN_PLUS
  BTN_MINUS
  BTN_MULTIPLY
  BTN_DIVIDE
  BTN_EQUALS
  BTN_CLEAR_ENTRY
  KEYPAD_9
  KEYPAD_8
  KEYPAD_7
  KEYPAD_6
  KEYPAD_5
  KEYPAD_4
  KEYPAD_3
  KEYPAD_2
  KEYPAD_1
  KEYPAD_0
  KEYPAD_DECIMAL
  KEY_Q_QUIT
  KEY_C_CLEAR
  KEYPAD_PLUS
  KEYPAD_MINUS
  KEYPAD_MULTIPLY
  KEYPAD_DIVIDE
  KEYPAD_ENTER_EQUALS
  KEY_E_CLEAR_ENTRY
End Enum  
  
Dim As HWND hwnd  
Dim Shared As String buffer
Dim Shared As String currentop
Dim Shared As String lastop
Dim Shared As Double eval = 0
Dim As Integer Position, event, quit = 0
Dim As String Text
Dim As Long Result
Dim As Integer W_Width = 415
Dim As Integer W_Height = 330

'-----Declarations
Declare Sub Operation()

'-----End of Declarations

'-----Begin code For main Window
hwnd = OpenWindow("Calculator", 0, 0, W_Width, W_Height)
	CenterWindow(hwnd)
	WindowColor(hwnd,BGR(200,200,200))

'-----Begin Gadget List for window
	StringGadget(DISPLAY1, 20, 15, 365, 25, "", SS_RIGHT,WS_EX_CLIENTEDGE)
	LoadFont("Courier New",16)
	SetGadgetFont(DISPLAY1)
  	ButtonGadget(BTN_9,170,87,65,40,"9")
  	ButtonGadget(BTN_8,95,87,65,40,"8")
  	ButtonGadget(BTN_7,20,87,65,40,"7")
  	ButtonGadget(BTN_6,170,137,65,40,"6")
  	ButtonGadget(BTN_5,95,137,65,40,"5")
  	ButtonGadget(BTN_4,20,137,65,40,"4")
  	ButtonGadget(BTN_3,170,187,65,40,"3")
  	ButtonGadget(BTN_2,95,187,65,40,"2")
  	ButtonGadget(BTN_1,20,187,65,40,"1")
  	ButtonGadget(BTN_0,20,237,140,40,"0")
  	ButtonGadget(BTN_DECIMAL,170,237,65,40,".")
  	ButtonGadget(BTN_QUIT,20,52,65,25,"&Quit")
  	ButtonGadget(BTN_CLEAR,95,52,140,25,"&C")
  	ButtonGadget(BTN_PLUS,245,87,65,40,"+")
  	ButtonGadget(BTN_MINUS,245,137,65,40,"-")
  	ButtonGadget(BTN_MULTIPLY,245,187,65,40,"*")
  	ButtonGadget(BTN_DIVIDE,245,237,65,40,"/")
  	ButtonGadget(BTN_EQUALS,320,87,65,190,"=")
  	ButtonGadget(BTN_CLEAR_ENTRY,245,52,140,25,"C&E")
  
  	'-----End Gadget List  
  
'-----Begin Keyboard Shortcuts for Window  
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD9,KEYPAD_9)  
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD8,KEYPAD_8) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD7,KEYPAD_7) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD6,KEYPAD_6) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD5,KEYPAD_5) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD4,KEYPAD_4)  
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD3,KEYPAD_3) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD2,KEYPAD_2) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD1,KEYPAD_1) 
  AddKeyboardShortcut(hwnd,0,VK_NUMPAD0,KEYPAD_0) 
  AddKeyboardShortcut(hwnd,0,VK_DECIMAL,KEYPAD_DECIMAL)  
  AddKeyboardShortcut(hwnd,0,VK_Q,KEY_Q_QUIT) 
  AddKeyboardShortcut(hwnd,0,VK_C,KEY_C_CLEAR) 
  AddKeyboardShortcut(hwnd,0,VK_ADD,KEYPAD_PLUS) 
  AddKeyboardShortcut(hwnd,0,VK_SUBTRACT,KEYPAD_MINUS) 
  AddKeyboardShortcut(hwnd,0,VK_MULTIPLY,KEYPAD_MULTIPLY) 
  AddKeyboardShortcut(hwnd,0,VK_DIVIDE,KEYPAD_DIVIDE) 
  AddKeyboardShortcut(hwnd,0,VK_RETURN,KEYPAD_ENTER_EQUALS) 
  AddKeyboardShortcut(hwnd,0,VK_E,KEY_E_CLEAR_ENTRY)
  
'-----End Keyboard Shortcuts  

'-----Main operating code--------------------------------
'--------------------------------------------------------
'-----Loop to get keystokes and operate the calculator
Do
  Event = WindowEvent()
  If Event = EventGadget Then
  	 Select Case eventnumber
        Case BTN_0
          buffer = buffer + "0"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_1
          buffer = buffer + "1"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_2
          buffer = buffer + "2"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_3
          buffer = buffer + "3"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_4
          buffer = buffer + "4"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_5
          buffer = buffer + "5"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_6
          buffer = buffer + "6"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_7
          buffer = buffer + "7"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_8
          buffer = buffer + "8"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_9
          buffer = buffer + "9"
          SetGadgetText(DISPLAY1,buffer)
        Case BTN_DECIMAL
          'if buffer already has a decimal, ignore this keypress
          Position = instr(buffer,".")
          If Position = 0 Then
            buffer = buffer + "."
            SetGadgetText(DISPLAY1,buffer)
          EndIf
        Case BTN_QUIT   '----Quit the program  
          'Event = End
          End 
        Case BTN_CLEAR
          '----C clears everything and starts at the beginning
          buffer=""
          lastop= ""
          currentop=""
          eval=0
          SetGadgetText(DISPLAY1,"0")
        Case BTN_PLUS
          '---Add buffer to eval
          currentop = "+"
          Operation()
        Case BTN_MINUS
          currentop = "-"
          Operation()
        Case BTN_MULTIPLY
          currentop = "*"
          Operation()
        Case BTN_DIVIDE
          currentop = "/"
          Operation()
        Case BTN_EQUALS
          currentop = "="
          Operation()
        Case BTN_CLEAR_ENTRY
          buffer = RTrim(Str(eval),"0")
          If Val(buffer) = 0 Then
            buffer = ""
            SetGadgetText(DISPLAY1,"")
          Else
            SetGadgetText(DISPLAY1,buffer)
            buffer=""
          EndIf          
      End Select
   EndIf
   If Event = EventMenu Then
      Select Case EventNumber
      	Case KEYPAD_0
          buffer = buffer + "0"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_1
          buffer = buffer + "1"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_2
          buffer = buffer + "2"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_3
          buffer = buffer + "3"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_4
          buffer = buffer + "4"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_5
          buffer = buffer + "5"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_6
          buffer = buffer + "6"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_7
          buffer = buffer + "7"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_8
          buffer = buffer + "8"
          SetGadgetText(DISPLAY1,buffer)
        Case KEYPAD_9
          buffer = buffer + "9"
          SetGadgetText(DISPLAY1,buffer)
      	Case KEYPAD_DECIMAL
          'if buffer already has a decimal, ignore this keypress
          Position = instr(buffer,".")
          If Position = 0 Then
            buffer = buffer + "."
            SetGadgetText(DISPLAY1,buffer)
          EndIf
        Case KEY_Q_QUIT   '----Quit the program  
          End
		  Case KEY_C_CLEAR
          '----C clears everything and starts at the beginning
          buffer=""
          lastop= ""
          currentop=""
          eval=0
          SetGadgetText(DISPLAY1,"0")
        Case KEYPAD_PLUS
          '---Add buffer to eval
          currentop = "+"
          Operation()
        Case KEYPAD_MINUS
          currentop = "-"
          Operation()
        Case KEYPAD_MULTIPLY
          currentop = "*"
          Operation()
        Case KEYPAD_DIVIDE
          currentop = "/"
          Operation()
        Case  KEYPAD_ENTER_EQUALS
          currentop = "="
          Operation()
        Case KEY_E_CLEAR_ENTRY
          buffer = RTrim(Str(eval),"0")
          If Val(buffer) = 0 THEN
            buffer = ""
            SetGadgetText(DISPLAY1,"")
          Else
           SetGadgetText(DISPLAY1,buffer)
            buffer=""
          EndIf          
      End Select      
  EndIf    
             
  Loop Until Event = EventClose
  End
  
'------------Begin Procedures For Calculator
'-----------------------------------------------------------
  
'-----Handle the math and display operators
Sub Operation()
  '--This routine will execute any buffered operation
  If lastop = "" Then
    lastop = currentop
    'Sometimes people press an operation when a value is displayed after
    'the equals key - buffer is null then - check for a value displayed
    If buffer = "" Then
      buffer = GetGadgetText(DISPLAY1)
    EndIf
    eval = Val(buffer)
    buffer= ""
  Else
    If lastop = "-" Then
      eval = eval - Val(buffer)
    EndIf
    If lastop = "+" Then
      eval = eval + Val(buffer)
    EndIf
    If lastop = "/" Then
      '--Protect against divide by zero
      If Val(buffer) = 0 Then 
        'Return     'do nothing
      Else
      	eval = eval / Val(buffer)
      EndIf	
    EndIf  
    If lastop = "*" Then
      eval = eval * Val(buffer)
    EndIf
  EndIf  
  
  If currentop = "=" Then
    lastop = ""
    currentop = ""
    buffer = ""
    SetGadgetText(DISPLAY1,RTrim(Str(eval),"0"))
    eval = 0
  Else
    lastop = currentop
    buffer = ""
    SetGadgetText(DISPLAY1,RTrim(Str(eval),"0"))
  EndIf  
End Sub

[/code]
Hi pmilano !

I found two weaknesses:

1) 2 parameter function AddKeyboardShortcut must be FVIRTKEY (or 1)

2) It is better to use a function WaitEvent instead of WindowEvent. The CPU usage depends on it. Besides feature WindowEvent does not work very well.
pmilano
Posts: 22
Joined: Jul 03, 2011 16:25
Location: Illinois

second parameter of AddKeyboardShortcut

Post by pmilano »

Thanks Vanya,

I did know about the waitevent but I don't see any difference in the 0 or 1 in the second parameter of AddKeyboardShortcut. It appears to work either way.

Pat
VANYA
Posts: 1859
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: second parameter of AddKeyboardShortcut

Post by VANYA »

pmilano wrote:Thanks Vanya,

I did know about the waitevent but I don't see any difference in the 0 or 1 in the second parameter of AddKeyboardShortcut. It appears to work either way.

Pat
You're right. I forgot that already shipped a function AddKeyboardShortcut

Initially, she did not work
pmilano
Posts: 22
Joined: Jul 03, 2011 16:25
Location: Illinois

Keystroke filtering in gui

Post by pmilano »

Using fbgui lib how can I discard unwanted keystrokes and send a different
keystroke in my app?
VANYA
Posts: 1859
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Keystroke filtering in gui

Post by VANYA »

pmilano wrote:Using fbgui lib how can I discard unwanted keystrokes and send a different
keystroke in my app?
I do not understand the question.
pmilano
Posts: 22
Joined: Jul 03, 2011 16:25
Location: Illinois

Keyboard

Post by pmilano »

I want to be able to control which keypress reaches an edit control. For example, I want to only allow keypad numbers to the edit control.
Thanks for any info.
VANYA
Posts: 1859
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Keyboard

Post by VANYA »

pmilano wrote:I want to be able to control which keypress reaches an edit control. For example, I want to only allow keypad numbers to the edit control.
Thanks for any info.
Is it necessary?

Code: Select all

#Include "window9.bi"
Dim As Integer event
Dim shared as HWND hwnd,edit
Dim Shared As WNDPROC OldWndproc
Function editproc(hedit As hwnd,umsg As uint,wparam As WPARAM,lparam As LPARAM)As Integer
	Select Case umsg
		Case WM_KEYDOWN
			Print wparam
	End Select
	Return CallWindowProc(OldWndproc,hedit,umsg,wparam,lparam)
End Function
hwnd=OpenWindow("",10,10,300,300) : CenterWindow(hwnd)
edit=EditorGadget(1,10,10,200,200)
ButtonGadget(2,220,10,20,20)
OldWndproc=Cast(wndproc,SetWindowLong(edit,GWL_WNDPROC,Cast(long,@editproc)))
Do
	event=WaitEvent()
	Select case Event
		Case EventClose
			End
	End Select
Loop
pmilano
Posts: 22
Joined: Jul 03, 2011 16:25
Location: Illinois

Keypress

Post by pmilano »

I don't know if it is necessary. Rapidq has a 'killmessage' so I was looking around for a way to do it in freebasic.
Thanks for the info.
VANYA
Posts: 1859
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Keypress

Post by VANYA »

pmilano wrote:I don't know if it is necessary. Rapidq has a 'killmessage' so I was looking around for a way to do it in freebasic.
Thanks for the info.
I can not understand the question. I advise you to ask a question in general forum.
pmilano
Posts: 22
Joined: Jul 03, 2011 16:25
Location: Illinois

Re: Keyboard

Post by pmilano »

VANYA wrote:
pmilano wrote:I want to be able to control which keypress reaches an edit control. For example, I want to only allow keypad numbers to the edit control.
Thanks for any info.
Is it necessary?

Code: Select all

#Include "window9.bi"
Dim As Integer event
Dim shared as HWND hwnd,edit
Dim Shared As WNDPROC OldWndproc
Function editproc(hedit As hwnd,umsg As uint,wparam As WPARAM,lparam As LPARAM)As Integer
	Select Case umsg
		Case WM_KEYDOWN
			Print wparam
	End Select
	Return CallWindowProc(OldWndproc,hedit,umsg,wparam,lparam)
End Function
hwnd=OpenWindow("",10,10,300,300) : CenterWindow(hwnd)
edit=EditorGadget(1,10,10,200,200)
ButtonGadget(2,220,10,20,20)
OldWndproc=Cast(wndproc,SetWindowLong(edit,GWL_WNDPROC,Cast(long,@editproc)))
Do
	event=WaitEvent()
	Select case Event
		Case EventClose
			End
	End Select
Loop
I compiled the code. nothing prints.
VANYA
Posts: 1859
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Keyboard

Post by VANYA »

pmilano wrote:I compiled the code. nothing prints.
Must compile as a console application
pmilano
Posts: 22
Joined: Jul 03, 2011 16:25
Location: Illinois

Re: Keyboard

Post by pmilano »

VANYA wrote:
pmilano wrote:I compiled the code. nothing prints.
Must compile as a console application
Thanks. I am still trying to learn how this wingui works.
VANYA
Posts: 1859
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Post by VANYA »

Errors were found both in the functions of the library and in the certificate.
And that update was not very young, has added several features.
Fixed:

Help File:

1) does not display ASCII table
2) sample writedata
3) minor errors in Chapter FileSystem

Library:

function AddListViewItem (shows the last uploads the picture when there was a need to download the free pattern)
function AddListBoxItem (program crash when loading a function of the empty string "")
function TreeViewGadget (added compatibility for compilation with GCC)
function Shellfolder (added parameter that enhances the dialogue)
function StopDraw (was bug with transparent drawing)
function Read_Data (because of added functionality and Read_DataA Read_DataS)
function CreateCopyImageDesktop (not released the handle)
function CreateCopyImageRect (not released the handle)
function CreateCopyImageWindow (not released the handle)
function CreateCopyImageWindowClient (not released the handle)
function LoadMovie (not allocated memory freed)

Added:
CompressMem
DeCompressMem
CompressFile
DeCompressFile
Read_DataA
Read_DataS
WebGadgetGetBody
WebGadgetSetBody
Post Reply