Page 1 of 1

Posted: Mon Apr 07, 2003 3:10 am
by BackupUser
Restored from previous forum. Originally posted by ricardo.

Hi,

I was thinking that maybe could be a good idea to code some easy examples for absolute newbies.
I code already 9 examples and upload it to Resources site (http://www.reelmediaproductions.com/pb) i hope more can code more examples and upload it.



Best Regards

Ricardo

Dont cry for me Argentina...

Posted: Mon Apr 07, 2003 9:47 pm
by BackupUser
Restored from previous forum. Originally posted by Nonproductive.

I just got a chance to look at some of these. Thank you Ricardo!
Simple, well commented examples for Newbies (PBies?) like me are tough to find :)

Posted: Tue Apr 08, 2003 12:36 am
by BackupUser
Restored from previous forum. Originally posted by ricardo.
Simple, well commented examples for Newbies (PBies?) like me are tough to find :)
With my very bad english:)
In fact i write SpanGlish as some other write FrenchGlish or DeustchGlish But we try to communicate!!

I hope that more people here can help making many simple examples for begginers.

Best Regards

Ricardo

Dont cry for me Argentina...

Posted: Fri Apr 11, 2003 11:47 pm
by BackupUser
Restored from previous forum. Originally posted by julianbury.

Hi fellows :)
I just bought PureBasic and joined up.
One absolutely minimal example would be wonderful to find.
What I would like is an example of a window with three virtically aligned string gadgets,
that I can move the focus between, using the up/down cursor keys.
Can anyone do such a thing?
I recently discovered that BlitzPlus cannot :-(

Yours in hope
Julian




^00^

Posted: Sat Apr 12, 2003 1:00 am
by BackupUser
Restored from previous forum. Originally posted by Paul.

Hi Julian,

Here is a quick example that does what you ask. Normally you move from gadget to gadget in Windows using Tab and Shift+Tab. This example converts Up/Down arrow keys to Tab/Shift+Tab.

Code: Select all

#Window_Main=0
#Gadget_Main_String1=1
#Gadget_Main_String2=2
#Gadget_Main_String3=3
 
If OpenWindow(#Window_Main,165,0,182,131,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Example")
  If CreateGadgetList(WindowID())
    StringGadget(#Gadget_Main_String1,10,20,160,20,"")
    StringGadget(#Gadget_Main_String2,10,45,160,20,"")
    StringGadget(#Gadget_Main_String3,10,70,160,20,"")
  EndIf
EndIf
 
 
ActivateGadget(#Gadget_Main_String1)
Repeat
  EventID=WaitWindowEvent()
  
  If GetAsyncKeyState_(#VK_DOWN)=-32767
    keybd_event_(#VK_DOWN,1,#KEYEVENTF_KEYUP,0)
    keybd_event_(#VK_TAB,1,0,0)
    keybd_event_(#VK_TAB,1,#KEYEVENTF_KEYUP,0)
  EndIf
  If GetAsyncKeyState_(#VK_UP)=-32767
    keybd_event_(#VK_UP,1,#KEYEVENTF_KEYUP,0)
    keybd_event_(#VK_SHIFT,1,0,0)
    keybd_event_(#VK_TAB,1,0,0)
    keybd_event_(#VK_TAB,1,#KEYEVENTF_KEYUP,0)
    keybd_event_(#VK_SHIFT,1,#KEYEVENTF_KEYUP,0)
  EndIf 
   
Until EventID=#PB_Event_CloseWindow
End

----------
Visit the PB Resources Site at http://www.reelmediaproductions.com/pb

Posted: Sat Apr 12, 2003 3:11 am
by BackupUser
Restored from previous forum. Originally posted by julianbury.

Thank you Paul, that works!

Am I right in thinking that your solution implies that there is not
much direct access to Keydown information while focussed in a text or
string gadget?

I really want to be able to manouver around like in a spreadsheet -
(up/down and left/right)
because I was hoping to make a weird calculator as my initial project.

As I understand it, Tab and Shift+tab just go backwards and forwards
thru the gadgets by number in a linear manner, so in a 3x16 group of
string gadgets, it might take some time to get to the string you
wanted to edit.

May I ask - what is the significance of the # in front of the #VK_names?
Does it mean the same thing always?

Embarrassed to be found out as a dimwit :-(

Julian

^00^

Posted: Sat Apr 12, 2003 3:32 am
by BackupUser
Restored from previous forum. Originally posted by pusztry.

The '#' Denotes a constant.

- Ryan
RJP Computing

WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra

Posted: Sat Apr 12, 2003 5:09 am
by BackupUser
Restored from previous forum. Originally posted by Paul.
Originally posted by julianbury


I really want to be able to manouver around like in a spreadsheet -
(up/down and left/right)
because I was hoping to make a weird calculator as my initial project.
Hi Julian,

Of course there are many ways to accomplish the same results. You asked for a solution to a very specific problem regarding the 3 vertical lined gadgets. Of course the quickest way to move in that situation is tabbing :)

Being able to move around like in a spreadsheet, that is quite different (with also many solutions). Here is an interesting way to accomplish what you ask...

Code: Select all

#Window_Main=0
#Up   =100
#Down =101
#Left =102
#Right=103
  
 
maxgrid=8
Dim pos(maxgrid,maxgrid)
 
If OpenWindow(#Window_Main,165,0,770,260,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Example2")
  If CreateGadgetList(WindowID())
   
    id=0
    xpos=10
    For x=1 To maxgrid
      ypos=15
      For y=1 To maxgrid
        id+1
        StringGadget(id,xpos,ypos,80,20,"")
        pos(x,y)=GadgetID(id)
        ypos+30
      Next
      xpos+95
    Next
 
    AddKeyboardShortcut(#Window_Main,#PB_Shortcut_Up,#Up)
    AddKeyboardShortcut(#Window_Main,#PB_Shortcut_Down,#Down)
    AddKeyboardShortcut(#Window_Main,#PB_Shortcut_Left,#Left)
    AddKeyboardShortcut(#Window_Main,#PB_Shortcut_Right,#Right)
  EndIf
EndIf
 
 
ActivateGadget(1)
 
Repeat
  EventID=WaitWindowEvent()
     
  If EventID=#PB_Event_Menu
    For x=1 To maxgrid
      For y=1 To maxgrid
        If GetFocus_()=pos(x,y)
          xpos=x
          ypos=y
        EndIf
      Next
    Next  
 
    Select EventMenuID()
      Case #Up
        ypos-1
        If yposmaxgrid:ypos=maxgrid:EndIf      
      Case #Left
        xpos-1
        If xposmaxgrid:xpos=maxgrid:EndIf            
    EndSelect
    SetFocus_(pos(xpos,ypos))
  EndIf  
Until EventID=#PB_Event_CloseWindow
End



----------
Visit the PB Resources Site at http://www.reelmediaproductions.com/pb

Posted: Sat Apr 12, 2003 1:13 pm
by BackupUser
Restored from previous forum. Originally posted by julianbury.

Paul, that's great!
You've cracked it for me and demonstrated some really useful code.
I hope other beginners have read this!
All the best
Julian


^00^

Posted: Sat Apr 12, 2003 2:28 pm
by BackupUser
Restored from previous forum. Originally posted by alan.

Hi - I've had PureBasic for a couple of days now and have came up with this half finished effort :)
I still need to do quite a bit with it - but the basics are there.I am looking into a better way of running the timer and the ability to add more than one timer - still I am happy for a first try :)

Lots to learn - but it's been fun upto now

As this is by a newbie I thought it might be ok to put up here (not sure of the forum rules yet...)

--------------------------------------------------------------

Code: Select all


; Program to create an icon in the task bar that will bring
; up a popup menu on right click and allow you to set a counter that will
; sound an alarm when the counter gets down to 0....

; set up the popup menu with several pre set times and an exit option..
 
CreatePopupMenu(0)
  MenuItem(1, "1 Minute")
  MenuItem(2, "2 Minutes")
  MenuItem(3, "3 Minutes")
  MenuItem(4, "4 Minutes")
  MenuItem(5, "5 Minutes")
  MenuItem(6, "10 Minutes")
  MenuItem(7, "20 Minutes")

  MenuItem(10, "Quit")

; now open a hiddeen windoe (I think I need this to set the taskbar icon)

OpenWindow(0, 10, 10, 10, 10, #PB_Window_Invisible, "Alarm Clock")

;assign a taskbar icon to the above hidden window.

  AddSysTrayIcon(1, WindowID(), LoadImage(0, "Data\Hour Glass.ico"))
  
; and add a tool tip...

  SysTrayIconToolTip(1, "Alarm Clock - Right click to set alarm delay")

Repeat


; wait for the user to do something....
  
  Event=WaitWindowEvent()

; is the "event" over the system tray ?
    
  If Event = #PB_Event_SysTray
    Select EventType()
      Case #PB_EventType_RightClick ; was it a right mouse click ?
      DisplayPopupMenu(0, WindowID()) ; then display the popup menu
      EndSelect
  EndIf

; is the event choosing from a menu ?
   
  If Event = #PB_EventMenu
    Select EventMenuID()
      Case 1 ; Set Timer to 1 Minute
        Delay=1
      Case 2 ; Set Timer to 2 Minutes
        Delay=2
      Case 3 ; Set Timer to 3 minutes (etc...)
        Delay=3
      Case 4
        Delay=4
      Case 5
        Delay=5
      Case 6
        Delay=10
      Case 7
        Delay=20
      Case 10 ; Quit
        Quit = 1
      EndSelect
  EndIf

; keep doing the above until user chooses a delay time or the quit option

Until Quit=1 Or Delay>0

If Quit=1
  End
  EndIf
  
; ok the user has choosen a delay time
; so now I need to set some way of alerting the user when the time is up....


; ok a bit basic maybe - just set a delay of user specified time times 60
; (60 seconds in a minute) times 1000 as the delay is in miliseconds
; (1000 miliseconds in 1 second)

; there is a problem with just doing this 
; the icon stays on show but the user can't do anything....

; so I guess the easiest thing is to change the icon to show it is "locked"

ChangeSysTrayIcon(1, LoadImage(0, "Data\locked.ico"))
SysTrayIconToolTip(1, "Alarm Clock - LOCKED")

Delay(Delay*1000*60)

; now tell the user that their time is up 
; using a message requester that prints up a message
; and waits for "OK" To be pressed

MessageRequester("Alarm Time", "Your Time is up :)", #PB_MessageRequester_Ok)


End


Posted: Sat Apr 12, 2003 4:14 pm
by BackupUser
Restored from previous forum. Originally posted by Kale.

its better to use a timer function instead of just a delay() command (which will halt program execution for specified time) see this windowsAPI command:

SetTimer_(WindowID(), TimerID, delay, address of procedure)

TimerID = number identifing timer (many can be used)
delay = milliseconds until procedure is called
the address of the prodcedure must used for the last parameter you use a '@' sign at the beginning of the procedure name to specify this (see PB manual about this)

example of code in action:

Code: Select all

; Program to create an icon in the task bar that will bring
; up a popup menu on right click and allow you to set a counter that will
; sound an alarm when the counter gets down to 0....

; set up the popup menu with several pre set times and an exit option..
 
CreatePopupMenu(0)
  MenuItem(1, "1 Minute")
  MenuItem(2, "2 Minutes")
  MenuItem(3, "3 Minutes")
  MenuItem(4, "4 Minutes")
  MenuItem(5, "5 Minutes")
  MenuItem(6, "10 Minutes")
  MenuItem(7, "20 Minutes")

  MenuItem(10, "Quit")

; now open a hiddeen windoe (I think I need this to set the taskbar icon)

OpenWindow(0, 10, 10, 10, 10, #PB_Window_Invisible, "Alarm Clock")

;assign a taskbar icon to the above hidden window.

  AddSysTrayIcon(1, WindowID(), LoadImage(0, "Data\Hour Glass.ico"))
  
; and add a tool tip...

  SysTrayIconToolTip(1, "Alarm Clock - Right click to set alarm delay")

Procedure quitIt()
    ; so I guess the easiest thing is to change the icon to show it is "locked"

    ChangeSysTrayIcon(1, LoadImage(0, "Data\locked.ico"))
    SysTrayIconToolTip(1, "Alarm Clock - LOCKED")

    ; now tell the user that their time is up 
    ; using a message requester that prints up a message
    ; and waits for "OK" To be pressed

    MessageRequester("Alarm Time", "Your Time is up :)", #PB_MessageRequester_Ok)
    End
EndProcedure

Repeat


; wait for the user to do something....
  
  Event=WaitWindowEvent()

; is the "event" over the system tray ?
    
    If Event = #PB_Event_SysTray
        Select EventType()
            Case #PB_EventType_RightClick ; was it a right mouse click ?
                DisplayPopupMenu(0, WindowID()) ; then display the popup menu
        EndSelect
    EndIf

; is the event choosing from a menu ?
   
  If Event = #PB_EventMenu
    Select EventMenuID()
      Case 1 ; Set Timer to 1 Minute
        Delay=1000 * 60
      Case 2 ; Set Timer to 2 Minutes
        Delay=2000 * 60
      Case 3 ; Set Timer to 3 minutes (etc...)
        Delay=3000 * 60
      Case 4
        Delay=4000 * 60
      Case 5
        Delay=5000 * 60
      Case 6
        Delay=10000 * 60
      Case 7
        Delay=20000 * 60
      Case 10 ; Quit
        Quit = 1
      EndSelect
  EndIf
  
    ; keep doing the above until user chooses a delay time or the quit option
    If Delay > 0
        SetTimer_(WindowID(), 1, Delay, @quitIt())
    EndIf

Until Event = #PB_EventCloseWindow Or Quit = 1

End
there also is a third party Timer user library distributed with PB coded by Danilo, see here:
viewtopic.php?t=4323
this library isn't supported by Fred.


--Kale

In love with PureBasic! :)

Posted: Sat Apr 12, 2003 7:21 pm
by BackupUser
Restored from previous forum. Originally posted by alan.

Thanks for that Kale - I knew there had to be a better way

I had heard of these API(?) things - just too frightened to try them.

Been playing with the code after your pointer, I thought I would repost - might help someone else ?

You will need to provide a suitable icon :)

This code adds an icon into the taskbar and allows you to set upto 3 timers - helps to stop your tea stewing.

Code: Select all

Global TimerID

CreatePopupMenu(0)
  OpenSubMenu("Timer 1")
    MenuItem(1, "1 Minute")
    MenuItem(2, "2 Minutes")
    MenuItem(3, "3 Minutes")
    MenuItem(4, "4 Minutes")
    MenuItem(5, "5 Minutes")
    MenuItem(6, "10 Minutes")
    MenuItem(7, "20 Minutes")
    CloseSubMenu()
  OpenSubMenu("Timer 2")
    MenuItem(11, "1 Minute")
    MenuItem(12, "2 Minutes")
    MenuItem(13, "3 Minutes")
    MenuItem(14, "4 Minutes")
    MenuItem(15, "5 Minutes")
    MenuItem(16, "10 Minutes")
    MenuItem(17, "20 Minutes")
    CloseSubMenu()
  OpenSubMenu("Timer 3")
    MenuItem(21, "1 Minute")
    MenuItem(22, "2 Minutes")
    MenuItem(23, "3 Minutes")
    MenuItem(24, "4 Minutes")
    MenuItem(25, "5 Minutes")
    MenuItem(26, "10 Minutes")
    MenuItem(27, "20 Minutes")
    CloseSubMenu()
  MenuBar()  

  MenuItem(10, "Quit")

; now open a hidden window (I think I need this to set the taskbar icon)

OpenWindow(0, 10, 10, 10, 10, #PB_Window_Invisible, "Alarm Clock")

;assign a taskbar icon to the above hidden window.

  AddSysTrayIcon(1, WindowID(), LoadImage(0, "Data\Hour Glass.ico"))
  
; and add a tool tip...

  SysTrayIconToolTip(1, "Alarm Clock - Right click to set alarm delay")
  
Procedure DisplayAlert1()
 MessageRequester("Alarm Time","Timer 1 is up :)" , #PB_MessageRequester_Ok)
 KillTimer_(WindowID(),1)   
EndProcedure

Procedure DisplayAlert2()
 MessageRequester("Alarm Time","Timer 2 is up :)" , #PB_MessageRequester_Ok)
 KillTimer_(WindowID(),2)   
EndProcedure

Procedure DisplayAlert3()
 MessageRequester("Alarm Time","Timer 3 is up :)" , #PB_MessageRequester_Ok)
 KillTimer_(WindowID(),3)   
EndProcedure

Repeat


; wait for the user to do something....
  
  Event=WaitWindowEvent()

; is the "event" over the system tray ?
    
    If Event = #PB_Event_SysTray
        Select EventType()
            Case #PB_EventType_RightClick ; was it a right mouse click ?
                DisplayPopupMenu(0, WindowID()) ; then display the popup menu
        EndSelect
    EndIf

; is the event choosing from a menu ?
   
  If Event = #PB_EventMenu
    Select EventMenuID()
      Case 1 ; Set Timer to 1 Minute
        Delay=1000 * 60
        TimerID=1
      Case 2 ; Set Timer to 2 Minutes
        Delay=2000 * 60
        TimerID=1
      Case 3 ; Set Timer to 3 minutes (etc...)
        Delay=3000 * 60
        TimerID=1
      Case 4
        Delay=4000 * 60
        TimerID=1
      Case 5
        Delay=5000 * 60
        TimerID=1
      Case 6
        Delay=10000 * 60
        TimerID=1
      Case 7
        Delay=20000 * 60
        TimerID=1
      Case 11 ; Set Timer to 1 Minute
        Delay=1000 * 60
        TimerID=2
      Case 12 ; Set Timer to 2 Minutes
        Delay=2000 * 60
        TimerID=2
      Case 13 ; Set Timer to 3 minutes (etc...)
        Delay=3000 * 60
        TimerID=2
      Case 14
        Delay=4000 * 60
        TimerID=2
      Case 15
        Delay=5000 * 60
        TimerID=2
      Case 16
        Delay=10000 * 60
        TimerID=2
      Case 17
        Delay=20000 * 60
        TimerID=2
      Case 21 ; Set Timer to 1 Minute
        Delay=1000 * 60
        TimerID=3
      Case 22 ; Set Timer to 2 Minutes
        Delay=2000 * 60
        TimerID=3
      Case 23 ; Set Timer to 3 minutes (etc...)
        Delay=3000 * 60
        TimerID=3
      Case 24
        Delay=4000 * 60
        TimerID=3
      Case 25
        Delay=5000 * 60
        TimerID=3
      Case 26
        Delay=10000 * 60
        TimerID=3
      Case 27
        Delay=20000 * 60
        TimerID=3
      Case 10 ; Quit
        Quit = 1
      EndSelect
  EndIf
  
    ; keep doing the above until user chooses a delay time or the quit option
    If Delay > 0
      Select TimerID
        Case 1
          SetTimer_(WindowID(), 1, Delay, @DisplayAlert1())
        Case 2
          SetTimer_(WindowID(), 2, Delay, @DisplayAlert2())
        Case 3
          SetTimer_(WindowID(), 3, Delay, @DisplayAlert3())
        EndSelect
      Delay=0  
    EndIf

Until  Quit = 1

End