vcl - How to determine which component has the program focus in C++Builder -


i using c++builder xe4 32bit vcl platform. writing windows os.

i have mainform lot of components on it. when press keyboard arrow key , form's onshortcut event triggered, how determine component has program focus?

i have different actions must taken based on component has focus.

void __fastcall tmainform::formshortcut(twmkey &msg, bool &handled) {     //determine component has focus. } 

use global screen->activecontrol property:

indicates control has input focus on screen.

read activecontrol learn windowed control object in active form receives input keyboard.

void __fastcall tmainform::formshortcut(twmkey &msg, bool &handled) {     twincontrol *ctrl = screen->activecontrol;     if (ctrl == control1)     {         // something...     }     else if (ctrl == control2)     {         // else...     }     // , on... } 

or, can use form's own activecontrol property:

specifies control has focus on form.

use activecontrol or set control has focus on form. 1 control can have focus @ given time in application.

if form not have focus, activecontrol control on form receive focus when form receives focus.

void __fastcall tmainform::formshortcut(twmkey &msg, bool &handled) {     twincontrol *ctrl = this->activecontrol;     if (ctrl == control1)     {         // something...     }     else if (ctrl == control2)     {         // else...     }     // , on... } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -