It is currently Wed Aug 21, 2019 9:08 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Tip: Dingless StringGadget
PostPosted: Mon Sep 09, 2002 12:36 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Code updated For 5.20+
Restored from previous forum. Originally posted by PB.

Code:
; Dingless StringGadget example by PB and Timo -- do whatever you want with it.
; Shows how to avoid the "ding" sound when Esc/Enter is pressed on a StringGadget.

If OpenWindow(0,200,250,450,200,"Test",#PB_Window_SystemMenu)
  sg=StringGadget(1,20,20,100,21,"1234567890",#ES_MULTILINE|#ES_AUTOVSCROLL)
  SetActiveGadget(1)
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget
      a$=GetGadgetText(1)
      pos=FindString(a$,#CRLF$,1)
      If pos0 ; Was Enter pressed on the StringGadget?
        SetGadgetText(1,ReplaceString(a$,#CRLF$,"")) ; Yes, so remove CR+LF.
        SendMessage_(sg,#EM_SETSEL,pos-1,pos-1) ; Move cursor back to where Enter was pressed.
      EndIf
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf

Edit: Updated for PureBasic v4.00 on 12 Aug 2006.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Sep 09, 2002 2:17 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by freak.

Thanks, for the Tip, i needed that, too.

> Can somebody come up with a better way to restore the cursor position? Thanks!

Here we go...
Code:
; Dingless StringGadget example by PB -- do whatever you want with it.
; Shows how to avoid the "ding" sound when Esc/Enter is pressed on a StringGadget.
;
If OpenWindow(0,100,150,450,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  sg=StringGadget(1,20,20,100,21,"",#PB_String_Multiline|#ES_AUTOVSCROLL)
  ActivateGadget(1)
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_EventGadget
      a$=GetGadgetText(1) : pos=FindString(a$,Chr(13)+Chr(10),1)
      If pos0 ; Was Enter pressed on the StringGadget?
        SetGadgetText(1,ReplaceString(a$,Chr(13)+Chr(10),"")) ; Yes, so remove CR+LF.
        SendMessage_(GadgetID(1), #EM_SETSEL, pos, pos)  ; Set cursor Position
      EndIf
    EndIf
  Until ev=#PB_EventCloseWindow
EndIf



Timo


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2004 1:46 pm 
Offline
Enthusiast
Enthusiast

Joined: Sun Jul 25, 2004 4:21 pm
Posts: 442
Location: US
I tried to use this approach in my code and it didn't work. I had a plain StringGadget with no flags so I added them in accordance with the sample above and it worked.

#PB_String_Multiline|#ES_AUTOVSCROLL

Makes sense but wasn't obvious to me at first, just in case anyone else stumbles on this one.

_________________
- - - - - - - - - - - - - - - -
Randy
http://www.redrival.com/ethics IF (PureBasic > PowerBasic) AND (PowerBasic > Visual_Basic) THEN PureBasic > Visual_Basic


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2004 7:18 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
Yes, #PB_String_Multiline|#ES_AUTOVSCROLL is what stops the ding sound,
otherwise Windows thinks the gadget is a single line and won't allow Enter to
be pressed on it (which gives the sound).

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye