Hi,
When my current program starts up, it populates a listbox with dates, and automatically drops the selection down to the current day's date
How can I get the position of the selection in the listbox so that I can generate a mouse click?
I know I can get the item position in the listbox, but that is not the same as the selected line's position relative to the program window. The selected line needs a mouse click to activate other controls in the window
Thanks,
Brian
Brian,
Not sure exactly what you're asking but can't you start by using
SETSELECTED to set the selected list box item.
In the window handler you could use
Case MyListBox
IF GETSELECTED(win,MyListBox) = TheOneHighlighted '(i.e. position 4)
'Do what you would do as if the button had been clicked.
DoThis()
DoThat()
Etc()
ENDIF
or I missing the point?
Andy.
Andy
I will have to look at that way of doing it. I am currently in my favourite shop, M&S. Not!
Brian
This example simulates a drop-down click when the dialog is opened.
$INCLUDE "windowssdk.inc"
CONST COMBO_1 = 1
CONST STATIC_2 = 2
DIALOG d1
CREATEDIALOG d1,0,0,452,214,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@COMBOBOX,"ComboBox1",77,47,293,121,0x50800603,COMBO_1
CONTROL d1,@STATIC,"Static",80,167,150,20,0x5000010B,STATIC_2
DOMODAL d1
SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
ADDSTRING d1, COMBO_1, "yesterday"
ADDSTRING d1, COMBO_1, "today"
ADDSTRING d1, COMBO_1, "tomorrow"
SETSELECTED d1, COMBO_1, 1 ' index: zero-based index
SimulateDropDownClick(d1, COMBO_1, 1)
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE COMBO_1
SELECT @NOTIFYCODE
CASE @CBNSELCHANGE ' do something after a drop-down click
INT index = GETSELECTED (d1, COMBO_1)
string text = GETSTRING (d1, COMBO_1, index)
SETCONTROLTEXT d1, STATIC_2, "Selected: " + text
_ShowWindow(GetDlgItem(d1.hwnd, STATIC_2), SW_HIDE) ' crazy code to redraw the static after text change
_ShowWindow(GetDlgItem(d1.hwnd, STATIC_2), SW_SHOW)
ENDSELECT
ENDSELECT
ENDSELECT
RETURN
ENDSUB
SUB SimulateDropDownClick(window w, INT ctrlID, INT index) ' index: zero-based index
INT hwnd = GetDlgItem(w.hwnd, ctrlID)
word low = ctrlID
word high = CBN_SELCHANGE
_SendMessage(d1.hwnd, WM_COMMAND, MAKELPARAM(low, high), hwnd)
ENDSUB
Another way to see it is by encapsulating inside a function all you want to do when the click happens, so there is no need to simulate a click at all.
$INCLUDE "windowssdk.inc"
CONST COMBO_1 = 1
CONST STATIC_2 = 2
DIALOG d1
CREATEDIALOG d1,0,0,452,214,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@COMBOBOX,"ComboBox1",77,47,293,121,0x50800603,COMBO_1
CONTROL d1,@STATIC,"Static",80,167,150,20,0x5000010B,STATIC_2
DOMODAL d1
SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
ADDSTRING d1, COMBO_1, "yesterday"
ADDSTRING d1, COMBO_1, "today"
ADDSTRING d1, COMBO_1, "tomorrow"
SETSELECTED d1, COMBO_1, 1 ' index: zero-based index
OnDropDownClick(d1, COMBO_1, STATIC_2) ' simulate a drop-down click
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE COMBO_1
SELECT @NOTIFYCODE
CASE @CBNSELCHANGE ' do something after a drop-down click
OnDropDownClick(d1, COMBO_1, STATIC_2)
ENDSELECT
ENDSELECT
ENDSELECT
RETURN
ENDSUB
SUB OnDropDownClick(window w, INT comboID, INT staticID)
INT index = GETSELECTED (w, comboID)
string text = GETSTRING (w, comboID, index)
SETCONTROLTEXT w, staticID, text
_ShowWindow(GetDlgItem(w.hwnd, staticID), SW_HIDE) ' crazy code to redraw the static after text change
_ShowWindow(GetDlgItem(w.hwnd, staticID), SW_SHOW)
ENDSUB
Thank you for looking at my listbox woes. I will have a go at that tomorrow
Thanks again,
Brian