Re: How to catch keydown
I would hope that he would only wants to get the keys when the control has
focus. Otherwise it would be a breach of contract between the other
controls. ;)
AliR.
"Tom Serface" <tom.nospam@camaswood.com> wrote in message
news:17854817-BE1C-4388-98D5-EA1F2BA4C2C3@microsoft.com...
Hi Ali,
That's how I would normally do this sort of thing as well. Nish wrote a
nice, albeit short, article about this a while back:
http://www.codeproject.com/dialog/pretransdialog01.asp
Since your example has the control getting the key that would be the right
way to do it. Of course, it will only work if the control has focus at
the time.
Tom
"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message
news:ZgjHh.7487$re4.1162@newssvr12.news.prodigy.net...
Try this, and make sure that you are creating a CMyIPAddressCtrl not a
CIPAddressCtrl
///////////////////////////////////////// header file
#pragma once
// CMyIPAddressCtrl
class CMyIPAddressCtrl : public CIPAddressCtrl
{
DECLARE_DYNAMIC(CMyIPAddressCtrl)
public:
CMyIPAddressCtrl();
virtual ~CMyIPAddressCtrl();
protected:
virtual BOOL PreTranslateMessage(MSG* pMsg);
DECLARE_MESSAGE_MAP()
};
///////////////////////////////////////// cpp file
// MyIPAddressCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "IPControl.h"
#include "MyIPAddressCtrl.h"
IMPLEMENT_DYNAMIC(CMyIPAddressCtrl, CIPAddressCtrl)
CMyIPAddressCtrl::CMyIPAddressCtrl()
{
}
CMyIPAddressCtrl::~CMyIPAddressCtrl()
{
}
BEGIN_MESSAGE_MAP(CMyIPAddressCtrl, CIPAddressCtrl)
END_MESSAGE_MAP()
// CMyIPAddressCtrl message handlers
BOOL CMyIPAddressCtrl::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
TRACE("Key down\n");
}
else if (pMsg->message == WM_CHAR)
{
TRACE("CHAR\n");
}
return CIPAddressCtrl::PreTranslateMessage(pMsg);
}