开发者

Disable accelerator table items in MFC

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 开发者_JS百科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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜