#ifndef __HOOKCTRLTAB_H
#define __HOOKCTRLTAB_H
#include <typeinfo>
#include <Afxwin.h>
#include <winuser.h>
namespace amv {
LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam);
class hookctrltab {
public:
static CFrameWnd *pw;
static HHOOK hhk;
hookctrltab(CFrameWnd *p)
{
if(!pw)
pw=p;
if(!hhk)
{
hhk=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,AfxGetInstanceHandle(),GetCurrentThreadId());
if(!hhk)
AfxMessageBox("No se creó el gancho de teclado");
}
}
~hookctrltab()
{
if(hhk)
UnhookWindowsHookEx(hhk);
}
};
HHOOK hookctrltab::hhk=0; CFrameWnd *hookctrltab::pw=0;
LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam)
{
if(code==HC_ACTION)
{
if(wParam==VK_TAB && (GetAsyncKeyState(VK_CONTROL) & 0x8000))
{
CEdit *pedt=0;
CWnd *pcw=hookctrltab::pw->GetFocus();
if(pcw && (pedt=dynamic_cast<CEdit *>(pcw)))
{
hookctrltab::pw->GetNextDlgTabItem(pcw)->SetFocus();
return 1;
}
}
}
return CallNextHookEx(hookctrltab::hhk,code,wParam,lParam);
}
}
#endif