Hi,
I'm a total VC++.NET newbie and I'm stuck with a couple of
stupid problems.
- I have a filled ListView. I'd like to select(or focus)
an Item from code, but I can't find a way to do it. I
can't find an Index property (or something like that)
which allows to be set.
- In a TextBox, when the event KeyDown is triggered, is
there a way to set the returned KeyCode. For example, when
the key 'K' is pressed, I'd like to put the 'H' char in
the TextBox.
I know these questions are quite stupid, but I've spent
all morning browsing the MSDN without finding anything !!!
Thanks in advance for your help !
Nishant Sivakumar - 23 Mar 2005 13:52 GMT
To select an item :- SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
Index property :- See GetFirstSelectedItemPosition/GetNextSelectedItem in
MSDN
Handling character entry in TextBox :- Override PreTranslateMessage and
handle WM_CHAR in your CEdit derived class

Signature
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
> Hi,
> I'm a total VC++.NET newbie and I'm stuck with a couple of
[quoted text clipped - 12 lines]
> all morning browsing the MSDN without finding anything !!!
> Thanks in advance for your help !
On The Corner - 23 Mar 2005 16:15 GMT
Thank you for your help but I'm not using MFC but the .NET
framework.
>-----Original Message-----
>To select an item :- SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
[quoted text clipped - 4 lines]
>Handling character entry in TextBox :- Override PreTranslateMessage and
>handle WM_CHAR in your CEdit derived class
Fred Hebert - 23 Mar 2005 20:01 GMT
Take a look at the KeyPress event of the edit control. In the help it is
listed as "Control.KeyPress Event".
Micus - 23 Mar 2005 23:55 GMT
> Hi,
> I'm a total VC++.NET newbie and I'm stuck with a couple of
[quoted text clipped - 8 lines]
> the key 'K' is pressed, I'd like to put the 'H' char in
> the TextBox.
I have not done this in a while, but you want to subclass the control. Use
the SetWindowLong() to substitute your own WndProc for the control.
Something like below :
WNDPROC oldEditProc; // to hold old edit control WndProc
LRESULT CALLBACK NewWndProc(HWND, UINT, WPARAM, LPARAM) //New WndProc for
control
{
... //handle WM_CHAR and replace wparam(?) with the character you want.
...
return CallWindowProc(oldEditProc, hwnd, msg, wParam, lParam);
}
oldWndProc = (WNDPROC) SetWindowLong(hwndEditControl, GWL_WNDPROC, (LONG)
NewWndProc); //replace WndProc for control in WM_CREATE of parent window
HTH,
M
> I know these questions are quite stupid, but I've spent
> all morning browsing the MSDN without finding anything !!!
> Thanks in advance for your help !