May 11, 2024, 07:08:28 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Edit Control Questions

Started by Rod, December 20, 2006, 07:52:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rod

I would greatly appreciate somebody pointing me in the right direction  :)

I'm trying to figure out how to capture keystrokes before an edit control responds to them, and make a choice in my code to (a) ignore the keystroke, (b) let the control act upon the keystroke normally, (c) let the control act upon a substituted keystroke (a capitalized letter, for example), or (d) act upon the keystroke within my code, altering the edit control's text under my control.

I'm thinking I need to start at the @ENUPDATE notification message, but don't know yet how to alter what the edit control will do with the keystoke.

The end result of all this will be specialized data entry controls: money (right-to-left, fixed decimal places), tax ID (numeric-only, with an overlay mask of "999-99-9999"), telephone (numeric only, different mask), postal code (mask "A9A 9A9" for Canadian), etc.

If there's a pre-coded library for this, I'll gladly use it. Otherwise, a bit of direction to get me started coding my own would be greatly appreciated.

Also, if there's some way to code this in a re-useable way, I'd love to do it and give to the community.

THANKS!!!!!

Jerry Muelver

December 20, 2006, 08:05:05 PM #1 Last Edit: December 20, 2006, 08:07:37 PM by Jerry Muelver
Here's how I do it in HyCard (IB Std):

SUB winINPUT(wind:window)
def winout:string
def dump,done:int
dump=getkeystate(0x0D)
dump=getkeystate(0x0D)
dump=getkeystate(0x0D)
done=0
winout=""
do
   key=""
   do
     waituntil key<>""
   until key<>""
   wait 1
   if getkeystate(0x0D)
     done=1
   else
     print wind,key
     winout=winout+key
     done=0
   endif
until done>0
dump=getkeystate(0x0D)
dump=getkeystate(0x0D)
dump=getkeystate(0x0D)
RETURN winout

Does that help? You can get the whole shebang at http://hytext.com/hycard.zip and poke around in it.

(Edit): Just reread your question. You were using an edit control, and I was grabbing keystrokes right off the window canvas. Still, it might help.  ::)

Barney

Someone on the old forums subclassed edit control so that he could use ENTER as a TAB key while entering data into multiple edit controls. I've added a little bit which stops use entering "q" or "Q" character. Perhaps it can be of use.


$include"windows.inc"

CONST EDIT_1 = 1
CONST EDIT_2 = 2
CONST EDIT_3 = 3
CONST EDIT_4 = 4
CONST EDIT_5 = 5
CONST EDIT_6 = 6
CONST EDIT_7 = 7
CONST EDIT_8 = 8
CONST EDIT_9 = 9
CONST EDIT_10 = 10
CONST BUTTON_11 = 11
CONST BUTTON_12 = 12

DIALOG d1
CREATEDIALOG d1,0,0,302,283,0x80CA0880,0,"enter tabbing",&d1_handler
CONTROL d1,@EDIT,"Edit1",19,14,265,20,0x50810080,EDIT_1
CONTROL d1,@EDIT,"Edit2",19,37,265,20,0x50810080,EDIT_2
CONTROL d1,@EDIT,"Edit3",19,60,265,20,0x50810080,EDIT_3
CONTROL d1,@EDIT,"Edit4",19,83,265,20,0x50810080,EDIT_4
CONTROL d1,@EDIT,"Edit5",19,106,265,20,0x50810080,EDIT_5
CONTROL d1,@EDIT,"Edit6",19,129,265,20,0x50810080,EDIT_6
CONTROL d1,@EDIT,"Edit7",19,152,265,20,0x50810080,EDIT_7
CONTROL d1,@EDIT,"Edit8",19,175,265,20,0x50810080,EDIT_8
CONTROL d1,@EDIT,"Edit9",19,198,265,20,0x50810080,EDIT_9
CONTROL d1,@EDIT,"Edit10",19,221,265,20,0x50810080,EDIT_10
CONTROL d1,@SYSBUTTON,"OK",216,252,70,23,0x50010000,BUTTON_11
CONTROL d1,@SYSBUTTON,"Cancel",142,252,70,23,0x50010000,BUTTON_12
openconsole
DOMODAL d1

SUB d1_handler
   settype @HITWINDOW,WINDOW

   SELECT @MESSAGE

      CASE @IDINITDIALOG
         doSubclass(*@HITWINDOW, EDIT_1, EDIT_10)

      CASE @IDCLOSEWINDOW
         CLOSEDIALOG *@HITWINDOW,@IDOK

   ENDSELECT
RETURN
ENDSUB


sub doSubclass(w:WINDOW, id_first:UINT, id_last:UINT)
   UINT id, hwnd
   for id = id_first to id_last
      hwnd = GetControlHandle(w, id)
      _SetWindowLong(hwnd, GWL_USERDATA, _SetWindowLong(hwnd, GWL_WNDPROC, &scEdit))
   next id
   return
endsub




sub scEdit(hWnd:UINT, uMsg:UINT, wParam:UINT, lParam:UINT),UINT
   UINT OriginalWndProc

   OriginalWndProc = _GetWindowLong(hwnd, GWL_USERDATA)

   select uMsg

      case WM_KEYUP
         if (wParam = VK_RETURN)
            _SetFocus(_GetWindow(hwnd, GW_HWNDNEXT))
            return 0
         endif

' Added by Barney
case WM_CHAR
if (wParam = 81 or wParam = 113)
return 0
endif

      case WM_DESTROY
         _SetWindowLong(hwnd, GWL_WNDPROC, OriginalWndProc)

   endselect

   return _CallWindowProc(OriginalWndProc, hWnd, uMsg, wParam, lParam)
endsub

mrainey

Paul added SETCONTROLNOTIFY to IBPro to handle the Enter and Tab keys, and it's in EBasic as well.
Software For Metalworking
http://closetolerancesoftware.com

Rod

I think perhaps the subclass is what I need. I will explore that route, unless subsequent suggestions look more promising.

Can somebody explain "settype @HITWINDOW,WINDOW"? Per the manual, it should be setting the automatic typecast of a pointer named "@HITWINDOW" to type WINDOW. What's confusing is that (1) "@HITWINDOW" doesn't look like a valid variable name, and (2) it hasn't been declared.

Ionic Wind Support Team

There are built in variables, listed in the users guide.  @HITWINDOW is a pointer to the window the message was sent to.  SETTYPE types a pointer so you don't have to do:

#<WINDOW>@HITWINDOW

Ionic Wind Support Team

LarryMc

I want to generate a popup context menu when right clicking inside a multi-line edit control.
Right now when I right click in the edit control I get a default menu of copy, cut, paste, etc.
I don't want that.

To generate my on right click menu do I :

put the rbuttonup message test inside the window handler where the edit control resides and do a PtInRect to see if I'm in the edit control;

Or, do I have to do it in a subclass of the edit control so the default popup menu doesn't appear?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

You will have to subclass.  Messages that occur when the edit control has focus are sent to the internal handler for the control (deep inside Windows somewhere).   By subclassing the control you get the chance to process those messages before they are sent to the internal handler, and decide whether or not to send them to that handler.

Ionic Wind Support Team

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library