Keyboard Accelerators
-
I have a MDI application of CListView. One of the listviews has a maximum of 20 entries(rows) with various column data and settings. In one of the settings I would like the user to configure a keyboard accelerator key or hotkey for each row. When the user double clicks on a row a dialog box opens which allows the user to enter the hotkey in an EditBox. I have read about ACCEL table, CreateAcceleratorTable, TranslateAccelerator and PreTranslateMessage, but is does not make sense to me at this time. Can someone please show what the code for this look like. Thanks :confused:
-
I have a MDI application of CListView. One of the listviews has a maximum of 20 entries(rows) with various column data and settings. In one of the settings I would like the user to configure a keyboard accelerator key or hotkey for each row. When the user double clicks on a row a dialog box opens which allows the user to enter the hotkey in an EditBox. I have read about ACCEL table, CreateAcceleratorTable, TranslateAccelerator and PreTranslateMessage, but is does not make sense to me at this time. Can someone please show what the code for this look like. Thanks :confused:
I don't know if got your problem well,but first you can ovverriden NM_DBCLK of your view,and inside it create your dialog class,and in your dialog class use WM_SETHOTKEY or WM_SYSCOMMAND Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without
-
I don't know if got your problem well,but first you can ovverriden NM_DBCLK of your view,and inside it create your dialog class,and in your dialog class use WM_SETHOTKEY or WM_SYSCOMMAND Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without
Thanks. I do appreciate you input. I still have no joy though. I read the info on the MSDN but it makes little sense to me. The sample code are not relevant to MFC. It could be that I do not have the latest MSDN Cds. I am not sure whether I am way off the tracks, but would appreciate any help on this. This is what I have in mind at the moment : typedef struct _Accel { BYTE fVirt; WORD Key; WORD cmd; }Accel; class MyListView : public CListView { public : Accel *pAccel; HACCEL haccel; int count; // number of hotkeys can be defined ..... }; // in the CPP file // in class constructor void MyListView :: MyListView () { count = 20; haccel = CreateAcceleratorTable(pAccel, count); } void MyListView :: OnDblclk (...., ....) { // assign hotkey string to structure ... // I DO NOT KNOW HOW TO ASSIGN THE HOTKEY TO THE PARTICULAR ID RESOURCE NAME ... } void MyListView :: OnKeyDown (....) { // read the key being pressed and activate the neccessary toolbar button HOW IS THIS DONE } // DestroyAcceleratorTable when application closes ... ..... Thanks Louis :confused:
-
Thanks. I do appreciate you input. I still have no joy though. I read the info on the MSDN but it makes little sense to me. The sample code are not relevant to MFC. It could be that I do not have the latest MSDN Cds. I am not sure whether I am way off the tracks, but would appreciate any help on this. This is what I have in mind at the moment : typedef struct _Accel { BYTE fVirt; WORD Key; WORD cmd; }Accel; class MyListView : public CListView { public : Accel *pAccel; HACCEL haccel; int count; // number of hotkeys can be defined ..... }; // in the CPP file // in class constructor void MyListView :: MyListView () { count = 20; haccel = CreateAcceleratorTable(pAccel, count); } void MyListView :: OnDblclk (...., ....) { // assign hotkey string to structure ... // I DO NOT KNOW HOW TO ASSIGN THE HOTKEY TO THE PARTICULAR ID RESOURCE NAME ... } void MyListView :: OnKeyDown (....) { // read the key being pressed and activate the neccessary toolbar button HOW IS THIS DONE } // DestroyAcceleratorTable when application closes ... ..... Thanks Louis :confused:
As far as I can tell from my experimentation with the accelerators functions, you need to do something like the following. In my example, the user would hold down Ctrl and a key they have assigned to the item. you have the following member variables in your header file: ACCEL* m_pAccel; //pointer to an array of ACCEL structs HACCEL m_hAccel; //the actual accel table int m_count; //number of accelerators in your implementation file: //your constructor void MyListView :: MyListView () { m_count = 20; m_pAccel = new ACCEL[count]; } //your handler for double click void MyListView :: OnDblClk(....,....) { int index = HitTest(....,....); ... // store hotkey information pAccel[index].fVirt = FCONTROL|FVIRTKEY; //virtual keys work best imho pAccel[index].key = VK_1; //the key pAccel[index].cmd = IDM_FIRST_ROW; //a menu id ... //unregister the hotkeys ::DestroyAcceleratorTable( hAccel ); //register the hotkeys hAccel = ::CreateAcceleratorTable( pAccel, count ); } //your handler for pre-translate message BOOL MyListView :: PreTranslateMessage(MSG* pMsg) { ::TranslateAccelerator( this->GetSafeHwnd(), hAccel, pMsg ); return CListView::PreTranslateMessage(pMsg); } Good luck. ;) Sef Tarbell "A mind all logic is like a knife all blade, it makes the hand bleed that wields it." --Rabindranath Tagore
-
As far as I can tell from my experimentation with the accelerators functions, you need to do something like the following. In my example, the user would hold down Ctrl and a key they have assigned to the item. you have the following member variables in your header file: ACCEL* m_pAccel; //pointer to an array of ACCEL structs HACCEL m_hAccel; //the actual accel table int m_count; //number of accelerators in your implementation file: //your constructor void MyListView :: MyListView () { m_count = 20; m_pAccel = new ACCEL[count]; } //your handler for double click void MyListView :: OnDblClk(....,....) { int index = HitTest(....,....); ... // store hotkey information pAccel[index].fVirt = FCONTROL|FVIRTKEY; //virtual keys work best imho pAccel[index].key = VK_1; //the key pAccel[index].cmd = IDM_FIRST_ROW; //a menu id ... //unregister the hotkeys ::DestroyAcceleratorTable( hAccel ); //register the hotkeys hAccel = ::CreateAcceleratorTable( pAccel, count ); } //your handler for pre-translate message BOOL MyListView :: PreTranslateMessage(MSG* pMsg) { ::TranslateAccelerator( this->GetSafeHwnd(), hAccel, pMsg ); return CListView::PreTranslateMessage(pMsg); } Good luck. ;) Sef Tarbell "A mind all logic is like a knife all blade, it makes the hand bleed that wields it." --Rabindranath Tagore