Click to See Complete Forum and Search --> : WM_KEYDOWN message in the datagrid


Galen
January 6th, 2006, 02:48 PM
I'm trying to handle the WM_KEYDOWN message in a datagrid. Specifically I want to know when ctrl+c is hit when the user wants to copy rows. At first I tried creating the handler like so:

this->m_datagrid->KeyDown += new System::Windows::Forms::KeyEventHandler(this, DataGrid_KeyDown);

void DataGrid_KeyDown(Object* obj, System::Windows::Forms::KeyEventArgs* e)
{
}

However, that didn't work. It never recieved any WM_KEYDOWN messages even though I was using ctrl+c to copy rows from the datagrid. It seems like something else is receiving the message.

I also tried a similar method by overloading the PreProcessMessage function in my datagrid but got the same results. It doesn't recieve the message.

Finally, I learned to use Spy++ a little to see where the WM_KEYDOWN is going. It is going to a child window whose class is "WindowsForms10.EDIT.app4". Does that mean anything to anyone? Any advice is much appreciated.

NoHero
January 6th, 2006, 02:53 PM
Yeah, maybe the internal textbox/label or whatever may hold the data. Usually default hotkeys like Ctrl+C are handled internaly and never passed out to the programmer.

mehdi62b
January 7th, 2006, 06:31 PM
for trapping the ctrl+c for the main window you need to call RegisterHotKey API function..for trapping WM_HOTKEY message then implement IMessageFilter or override PreProcessMessage or WndProc for the form
Btw check out :http://www.codeproject.com/cs/miscctrl/systemhotkey.asp

Galen
January 10th, 2006, 01:20 PM
I was finally able to capture ctrl+c by overriding the ProcessCmdKey function of DataGrid. I have, however, run into problems with editing what is copied to the clipboard. I should probably make that another thread though. Here was how I was able to capture ctrl+c in Datagrid:

bool ProcessCmdKey(Message* msg, Keys keyData)
{
bool b = System::Windows::Forms::Control::ProcessCmdKey (msg, keyData);

if (keyData == (Keys::Control | Keys::C))
{
\\do someting
}
}

Thank you for the input.