April 25, 2024, 03:56:08 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


setcontrolnotify with a combo box?

Started by AdrianFox, December 16, 2009, 06:44:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

December 16, 2009, 06:44:23 AM Last Edit: December 19, 2009, 04:17:24 AM by AdrianFox
UPDATE:  In the end, found this was the best way of using the Enter key, with many thanks to those who advised me..
                       IF GETKEYSTATE(0x0D) Then   'check virtual code for enter key
IF (GetForegroundWindow() = shopping.hwnd) AND  GETKEYSTATE(0x0D) AND getcontroltext (shopping,0x101)<>"" Then 
                                rem Check foreground window is the one used in this program, and that enter key pressed, and that combobox edit field is blank
Gosub updatecombo    'addstring to the combobox
DO
WAIT(1)
UNTIL (GETKEYSTATE(0x0D) = 0)
ENDIF
ENDIF


Requires DECLARE import, GetForegroundWindow(),INT

19th December 2009


In the manual, Paul says that 'setcontrolnotify' is designed for edit boxes but should work with other controls.

Although I found someone asking about this in the forums, I couldn't find the answer.  Should SETCONTROLNOTIFY work with user input in a combo box, as I'd like to get the user to press ENTER rather than click a button?

If it doesn't work, I will find another solution.

:)

FOUND ANOTHER WAY OF DOING THIS...
if GETKEYSTATE(0x0D)then

gosub updatecombo


This simply captures the virtual keycode 0D for the return key.

So I've now at least two ways of doing the same thing.
Adrian Fox

Ficko

Hi Adrian!

I don't know you did try it but I assume you did and dosn't work. :)

A combo box combines an edit box or static text and a list.
Therefore you have to address the (sub) controls if something can't be accomplish addressing the combo.

You have to get the ID of the edit box using "GetComboBoxInfo" + "GETCONTROLHANDLE" that's my gues. ;)



AdrianFox

Thanks for the suggestions, Ficko. 

Yes, I did try it but SETCONTROLNOTIFIY doesn't seem to work with a combobox, at least you can't code it in the same simple way as with an edit box.  I've worked round it temporarily by allowing the user to enter a # key after the entry which then results in ADDSTRING.

I've looked at the command GETCONTROLHANDLE, but not sure how to go about 'GetComboBoxInfo' as can't find that in the manual.  Sorry if I'm being stupid!

Adrian Fox

Ficko

I don't know my suggestion would work may with subclassing but this "hack" seems to work: ;)


SELECT @CONTROLID
CASE COMBO
IF (@NOTIFYCODE = 0) THEN
  MESSAGEBOX MainD,"HELLO","Enter Pressed!"
ENDIF
ENDSELECT

AdrianFox

Hi Ficko,

Sorry to be a pain, but although that works fine in a dialog, as soon as I change the dialog to a window it stops working. (which explains why I couldn't get this to work in the main program.)

'Test program to use Enter in a combobox. 
'This works when d1 is a dialog, but not when it is a window as below

CONST COMBO_1 = 1
window d1
openwindow d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@COMBOBOX,"ComboBox1",69,12,165,178,@CTCOMBOSIMPLE|@ctcombosort,COMBO_1
setcontrolnotify d1,1,1,1
centerwindow d1
waituntil d1=0

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
'setcontrolnotify d1,1,1,1  'used in dialog           
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEwindow d1:end
CASE @IDCONTROL

SELECT @CONTROLID


CASE COMBO_1
/* respond to combobox notifications here */
IF (@NOTIFYCODE = 0) THEN
  MESSAGEBOX d1,"HELLO","Enter Pressed!"   'works when d1 is a dialog
  ENDIF




ENDSELECT
ENDSELECT
RETURN
ENDSUB




I know from what Paul says, many features are designed to operate only with dialogs.  I guess I will have to stick with my original '#' key command, unless you have any further thoughts and can understand what creates this limitation.

Thanks for your help, very much appreciated

Adrian
Adrian Fox

Ficko

Change 0 to 9

"IF @NOTIFYCODE = 9"

And you don't need the "setcontrolnotify" stuff.

AdrianFox

 :D :D :D :D :D :D :D :D :D!!!!!

Brilliant!  It works!

Merci infiniment!

I think that's probably an incredibly useful solution as I noticed several posts where people were trying to overcome this problem.

Can you explain WHY it works, to non-programming old duffers like me?

Have a great Christmas!

Adrian Fox

sapero

$define CBN_ERRSPACE        (-1)
$define CBN_SELCHANGE       1
$define CBN_DBLCLK          2
$define CBN_SETFOCUS        3
$define CBN_KILLFOCUS       4
$define CBN_EDITCHANGE      5
$define CBN_EDITUPDATE      6
$define CBN_DROPDOWN        7
$define CBN_CLOSEUP         8
$define CBN_SELENDOK        9
$define CBN_SELENDCANCEL    10

CBN_SELENDOK is working for you probably because enter key is detected when you use keyboard to select an item.

AdrianFox

 :)  Thanks Sapero.  That's helpful.  It's important to understand why things work, not just that they do.  Will keep a record of those codes.

Seasons greetings,
;)
Adrian Fox