Re: ListBox with ctrl-c and other ctrl keys.
I still have one problem.
I successfully implemented OnKeyDown to capture ctrl-c and I
successfully implemented the clipboard stuff.
What I want to do is to disable the default mechanism. In a ListBox when
you type ctrl-any letter. Whatever you have selected is unselected and a
new selection is made of the top most line that begins with whatever
ctrl-letter you are using. I don't want that. I want to disable that
functionality.
How do I do that?
FYI: here is my OnKeyDown function in my subclassed ListBox. Instead of
handling the clipboard in the subclass, I chose to pass it to the dialog
to deal with. I have a reason to do that.
void ZScListBox::OnKeyDown(
UINT nChar,
UINT nRepCnt,
UINT nFlags
)
{
switch(nChar)
{
case 65: // a
// check if ctrl is depressed
if (0x8000 == (GetKeyState(VK_CONTROL) & 0x8000))
{
// ctrl-a is pressed
// tell the parent
// send the ID of the list box
GetParent()->SendMessage(SC__MESSAGE_LIST_BOX_CTRL_A, 0,
GetDlgCtrlID());
}
break;
case 67: // c
// check if ctrl is depressed
if (0x8000 == (GetKeyState(VK_CONTROL) & 0x8000))
{
// ctrl-c is pressed
// tell the parent
// send the ID of the list box
GetParent()->SendMessage(SC__MESSAGE_LIST_BOX_CTRL_C, 0,
GetDlgCtrlID());
}
break;
case 17: // ctrl
default:
// call base class
CListBox::OnKeyDown(nChar, nRepCnt, nFlags);
break;
};
}
Ajay wrote:
On Mar 31, 8:39 am, TonyG <To...@junk.com> wrote:
I have a many line owner-draw list box in my program. I use the
"Extended" selection method that allows lines to be highlighted.
How do I trap the ctrl-c key so that I can copy the selected lines to
the paste buffer?
Once I have text, how do I put the text into the paste buffer?
You should be able to use OnKeyDown of your control to trap it. Also
to put the data on clipboard, take a look at SetClipboardData.
--
Ajay