|
vs2010,其它的消息映射可以正确映射,调试的时候也能正确中断在函数开头。
这里Myedit.cpp文件
// MyCEdit
IMPLEMENT_DYNAMIC(MyCEdit, CEdit)
MyCEdit::MyCEdit()
{
}
MyCEdit::~MyCEdit()
{
}
BEGIN_MESSAGE_MAP(MyCEdit, CEdit)
ON_MESSAGE(WM_ACAD_KEEPFOCUS, onAcadKeepFocus)
ON_CONTROL_REFLECT(EN_CHANGE, OnEnChange)
END_MESSAGE_MAP()
void MyCEdit::OnEnChange()
{
CString str;
int len;
GetWindowText(str);
//len=str.GetLength();
//len=GetStringLength(str);
//this->SetWindowPos(NULL,0,0,13*len,20,SWP_NOMOVE);//这句
CDC* pDC = this->GetDC();
CSize size = pDC->GetTextExtent(str);
this->ReleaseDC(pDC);
CRect rc;
this->GetWindowRect(&rc);
ScreenToClient(&rc);
//rc.right = rc.left + size.cx;
this->SetWindowPos(NULL,0,0,size.cx+50,20,SWP_NOMOVE);//这句
}
这里MyEdit.h文件
#include "StdAfx.h"
// MyCEdit
class MyCEdit : public CEdit
{
DECLARE_DYNAMIC(MyCEdit)
public:
MyCEdit();
virtual ~MyCEdit();
LRESULT onAcadKeepFocus(WPARAM wPara,LPARAM lPara) //(UINT, LONG)
{
return TRUE;//在这里按F9设置断点,不能正确中断
}
int GetStringLength(CString& strTest)
{
int iLength = 0;
for( int i = 0; i 255 )
{// 汉字
iLength += 2;
}
else
{// 非汉字
iLength += 1;
}
}
return iLength;
}
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnEnChange();
};
有人说WM_ACAD_KEEPFOCUS应该定义为0x1001,但系统是这样定义的:
#define WM_ACAD_KEEPFOCUS (0x0400+0x6D01)
即0x7101才对
|
|