>I have code that will programmatically move to a control
SetFocus() is pretty handy, huh?
FWIW, SetCaretIndex() + SetFocus() should 'work'... except that SetCursor does not change the keyboard focus, meaning the cursor is in one place but the focus in another. That's gotta be a lot of fun.
Announcement
Collapse
No announcement yet.
Set Cursor on listbox item
Collapse
X
-
Gerhard,
Does it involve the mouse pointer moving to the item?
I have code that will programmatically move to a control, but do not think I can make it move to a list item, nor a certain menu item (just yet), so I would be interested in what the solution (or semi-solution) may be.
Leave a comment:
-
I tried %LB_SetCaretindex before without success. In the meantime I got a "private message" by this forum, and the problem is solved.
I changed the line
MapWindowPoints hList, hPrnt, rc, 2
by
MapWindowPoints hList, %HWND_DESKTOP, rc, 2,
and now it works. Thanks for your help!
Leave a comment:
-
Gerhard, I think %LB_SetCaretIndex is what you want. I set up a little demo below to illustrate. The dotted rectangle is not drawn until you press a keyboard arrow key, however. Maybe somone has a fix for this.
Code:#COMPILE EXE #DIM ALL #INCLUDE "win32api.inc" %IDC_Listbox1 = 101 %IDC_SetCursor = 102 GLOBAL hDialog1 AS LONG DECLARE CALLBACK FUNCTION Dialog1Proc() DECLARE SUB Dialog1() FUNCTION PBMAIN() 'Program statements Dialog1 END FUNCTION SUB Dialog1() DIALOG NEW PIXELS, 0, "", , , 300, 220, %WS_SYSMENU OR %WS_MINIMIZEBOX TO hDialog1 CONTROL ADD LISTBOX, hDialog1, %IDC_Listbox1, , 20, 10, 250, 150, %WS_VSCROLL _ OR %LBS_MULTIPLESEL, %WS_EX_CLIENTEDGE CONTROL ADD BUTTON, hDialog1, %IDC_SetCursor, "Set Cursor", 50, 180, 90, 30 DIALOG SHOW MODAL hDialog1 CALL Dialog1Proc END SUB CALLBACK FUNCTION Dialog1Proc() LOCAL i, n AS LONG, s AS STRING SELECT CASE CBMSG CASE %WM_INITDIALOG FOR i = 1 TO 50 s = "This is line number " + STR$(i) LISTBOX ADD CBHNDL, %IDC_Listbox1, s NEXT i CASE %WM_PAINT CASE %WM_COMMAND SELECT CASE CBCTL CASE %IDC_SetCursor n = 25 CONTROL SEND CBHNDL, %IDC_Listbox1, %LB_SetCaretIndex, n - 1, 1 END SELECT CASE %WM_SYSCOMMAND CASE %WM_DESTROY END SELECT END FUNCTION
Leave a comment:
-
Originally posted by Michael Mattias View PostThe documentation to the rescue once again....
You don't want to move the cursor manually, you just want to set the selection and let Windows handle the cursor.
Leave a comment:
-
The documentation to the rescue once again....
LB_SETSEL Message
--------------------------------------------------------------------------------
An application sends an LB_SETSEL message to select a string in a multiple-selection list box.
Leave a comment:
-
Set Cursor on listbox item
I want to position the cursor on a selected item in a multiple-selection listbox. The following code does not work. What am I doing wrong?
Code:SUB CursorToLBItem(BYVAL hPrnt AS LONG,_ BYVAL idlist AS LONG) LOCAL hList,cnt AS LONG LOCAL rc AS rect LOCAL pt AS POINTAPI hList = GetDlgItem(hPrnt,idlist) cnt = Sendmessage(hList,%LB_GETCOUNT,0,0) IF cnt THEN DIM selitems(cnt - 1) AS LONG CALL Sendmessage(hList,%LB_GETSELITEMS,cnt,VARPTR(selitems(0))) CALL SendMessage(hList, %LB_GETITEMRECT,selitems(0), VARPTR(rc)) MapWindowPoints hList, hPrnt, rc, 2 pt.x = (rc.nRight - rc.nLeft) / 2 pt.y = rc.nTop + (rc.nBottom - rc.nTop) / 2 SetCursorPos pt.x,pt.y END IF END SUB
Tags: None
Leave a comment: