A tip for handling ignored selections in a combobox. Background: If a
combobox list is dropped in order to change a selection, but action is
cancelled by clicking beside the list, whatever, previous selection is
reinstated and a %CBN_SELENDOK notification message still is triggered.
Nothing has changed, but since a %CBN_SELENDOK is triggered, code there
also will be activated (like, repeated).
We can see this in for example PBedit's sub/function finder combo, where
this behaviour can cause some frustration, because an ignored selection
still triggers latest one and cursor jumps back to start of that one. Not
fun if we were doing work elsewhere and just wanted to have a look in the
sub/function finder list..
Not PBedit's fault - it's default Windows behaviour, but sometimes we want
to decide behaviour ourselves, and then following simple way can be used.
I looked at message order and found that a %CBN_SELENDCANCEL is sent before
%CBN_SELENDOK, so by using this, one can make sure the ignore is respected
all the way. Just set a static flag in %CBN_SELENDCANCEL and let this flag
decide action in %CBN_SELENDOK, like:
------------------
combobox list is dropped in order to change a selection, but action is
cancelled by clicking beside the list, whatever, previous selection is
reinstated and a %CBN_SELENDOK notification message still is triggered.
Nothing has changed, but since a %CBN_SELENDOK is triggered, code there
also will be activated (like, repeated).
We can see this in for example PBedit's sub/function finder combo, where
this behaviour can cause some frustration, because an ignored selection
still triggers latest one and cursor jumps back to start of that one. Not
fun if we were doing work elsewhere and just wanted to have a look in the
sub/function finder list..
Not PBedit's fault - it's default Windows behaviour, but sometimes we want
to decide behaviour ourselves, and then following simple way can be used.
I looked at message order and found that a %CBN_SELENDCANCEL is sent before
%CBN_SELENDOK, so by using this, one can make sure the ignore is respected
all the way. Just set a static flag in %CBN_SELENDCANCEL and let this flag
decide action in %CBN_SELENDOK, like:
Code:
CALLBACK FUNCTION DlgProc SELECT CASE CBMSG 'wMsg CASE %WM_INITDIALOG STATIC gCBflag AS BYTE CASE %WM_COMMAND SELECT CASE CBCTL 'LOWRD(wParam) CASE %IDCOMBO SELECT CASE CBCTLMSG 'HIWRD(wParam) CASE %CBN_SELENDCANCEL 'trap this one to enable proper ignore gCBflag = 1 CASE %CBN_SELENDOK IF gCBflag THEN 'if user cancels, really ignore gCBflag = 0 : EXIT FUNCTION END IF BEEP 'whatever.. END SELECT END SELECT END SELECT END FUNCTION
------------------
Comment