I need to temporarily disable a few items from an accelerator table when the input focus is on a CEdit field.
My application has some commands associated with keyboard keys (A, S, D, etc.) and I need to disable those while the user is entering text in the field.
You could try CopyAcceleratorTable to get the ARRAY of ACCEL structures then edit out the ones you don't want, Call DEstroyAcceleratorTable on the current table. Then use CreateAcceleratorTable to create the new table with the edited accelerator table.
Edit: This link may be useful.
The answer from Goz works very fine. To save all other people some time, here is sample code that follows his suggestion:
// Allocate the accelerator buffer
HACCEL hAccelOld = LoadAccelerators(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_ACC_TECONTROL));
int iNumAccelerators = CopyAcceleratorTable(hAccelOld, NULL, 0);
ACCEL *pAccels = new ACCEL[iNumAccelerators];
// Copy the current table to the buffer
VERIFY(CopyAcceleratorTable(hAccelOld, pAccels, iNumAccelerators) == iNumAccelerators);
// Modify the pAccels array as required
...
// Destroy the current table resource...
VERIFY(DestroyAcceleratorTable(hAccelOld) == TRUE);
// ... create a new one, based on our modified table
m_hTerAcceleratorTable = CreateAcceleratorTable(pAccels, iNumAccelerators);
ASSERT(m_hTerAcceleratorTable != NULL);
// Cleanup
delete[] pAccels;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With