Re: Trapping return and excape in a ComboBox
- Posted by Martin Stachon <martin.stachon at worldonline.cz> Sep 01, 2002
- 391 views
I guess you need to get handle to EditText of ComboBox: sequence kids integer name_subedit name_subedit = 0 kids = findChildren(name) for i = 1 to length(kids) do if kids[i][2] = EditText then name_subedit = kids[i][1] exit end if end for and then add pComboBoxEdit to setHandler : setHandler({name, name_subedit}, w32HKeyDown, routine_id("onkeydownintext") --Martin > Below is some code which works as expected when name is an EditText, > but the onKeyDown routine is not invoked if I change it to a ComboBox. > > I think I may be expecting cr & esc to behave differently when the > drop down part is, erm, dropped down, than when not. Can it be done? > > Pete > === code follows === > include win32lib.ew > > constant MAIN = create( Window, "Test", 0, 100, 50, 370, 160, { > WS_DLGFRAME, WS_SYSMENU} ) > constant lab1 = create( LText, "&Name", MAIN, 8, 15, 60, 24, 0 ) > --constant name = create( EditText, "", MAIN, 70, 10, 200, 24, 0 ) > constant name = create( ComboBox, "", MAIN, 70, 10, 200, 24, 0 ) > constant lab2 = create( LText, "&Address", MAIN, 8, 45, 60, 24, 0 ) > constant addr = create( EditText, "", MAIN, 70, 40, 200, 24, 0 ) > constant DONE = create( PushButton, "&Done", MAIN, 275, 10, 80, 25, 0 > ) > > -- > -- Shift focus from labels to EditText they refer to when needed. > -- > procedure ongotfocuslab1() > setFocus(name) > end procedure > onGotFocus[lab1] = routine_id("ongotfocusllab1") > > procedure ongotfocusllab2() > setFocus(addr) > end procedure > onGotFocus[lab2] = routine_id("ongotfocusllab2") > > procedure OK(sequence text) > integer void > void = message_box(text,text,MB_OK) > end procedure > > procedure closeMAIN() > OK("Close") > closeWindow(MAIN) > end procedure > onClose[MAIN] = routine_id("closeMAIN") > > procedure onclick_DONE() > OK("CR") > end procedure > onClick[DONE] = routine_id("onclick_DONE") > > global procedure EscapeKeyed() > OK("Escape keyed") > closeWindow(MAIN) > end procedure > onClose[MAIN] = routine_id("closeMAIN") > > global procedure onkeydownintext(integer keycode, integer shift) > if keycode = VK_ENTER then > onclick_DONE() > end if > if keycode = VK_ESCAPE then > EscapeKeyed() > return > end if > if shift then end if -- prevents spurious warning > end procedure > onKeyDown[name] = routine_id("onkeydownintext") > onKeyDown[addr] = routine_id("onkeydownintext") > onKeyDown[DONE] = routine_id("onkeydownintext") > > -- > WinMain( MAIN, Normal ) > > >