Disable accelerator table items in MFC

I need to temporarily disable several items from the accelerator table when the input focus is in the CEdit field.

My application has several commands related to keyboard keys (A, S, D, etc.), and I need to disable them while the user enters text in the field.

+6
c ++ mfc
source share
2 answers

You can try CopyAcceleratorTable to get ARRAY from ACCEL structures, then edit the ones you don't want Call DEstroyAcceleratorTable in the current table. Then use CreateAcceleratorTable to create a new table with the edited accelerator table.

Edit: This link may be helpful.

+6
source share

The answer from Goz works very well. To save all other people for a while, here is an example 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; 
+1
source share

All Articles