CBC中怎么对多个消息进行映射???
头文件中进行如下声明:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_MOVE,TMessage,WndProcaa);
MESSAGE_HANDLER(WM_MOUSELEAVE,TMessage,WndProcaa);
MESSAGE_HANDLER(WM_DROPFILES,TWMDropFiles,WMDropFiles);
END_MESSAGE_MAP(TForm);
protected:
void __fastcall WndProcaa(TMessage &Msg);
void __fastcall WMDropFiles(TWMDropFiles &Msg);
.CPP:
void __fastcall TMainForm::WMDropFiles(TWMDropFiles &Msg)
{
int num = DragQueryFile((HDROP)Msg.Drop,0xFFFFFFFF,NULL,0);
if (num > 1)
{
ShowMessage("收到了" + String(num) + "个文件!" );
}
for (int i = 0; i < num; i++)
{
char buf[256];
DragQueryFile((HDROP)Msg.Drop,0,buf,sizeof(buf));
UnicodeString file = buf;
if (true)
{
if( FileOpen(file) )
{
Refresh(0);
Edit1->Text = "1";
}
else return;
}
}
TForm::Dispatch(&Msg); //如果不加上这句,消息将不会传递给其他函数
}
//---------------------------------------
void __fastcall TMainForm::WndProcaa(TMessage &Msg)
{
StickAt = 15 ;// StrToInt(edStickAt.Text);
TPoint point;
GetCursorPos(&point);
int nTop = point.y ;//- ((TEdit *)Sender)->Height ;
int nLeft = point.x ;//+ ((TEdit *)Sender)->Width ;
switch (Msg.Msg)
{
case WM_MOVE:
if (this->Left < 0 )
{
if(Left != - Width + 10)
{
Left = - Width + 8;
this->FormStyle = fsStayOnTop;//永远置顶
}
}
break;
case WM_MOUSELEAVE :
if(Left <= 0)
{
Left = - Width + 8;
this->FormStyle = fsStayOnTop;//永远置顶
}
break;
case WM_MOUSEMOVE:
case WM_NCHITTEST:
if (this->Left <= ( 20 - Width ) )
{
Left = 0;
this->FormStyle = fsNormal;//恢复
this->SetFocus();
if(!this->Active)
{
TimerForm->Enabled = true;
}
}
else if ((nLeft > this->Width -2 ) && (Left <= 0) )
{
Left = - Width + 8;
this->FormStyle = fsStayOnTop;//永远置顶
}
break;
case WM_DROPFILES:
ShowMessage("Drag Files");
Msg.Result = HTCAPTION ;
return;
break;
default:
;
}
TForm::Dispatch(&Msg); //如果不加上这句,消息将不会传递给其他函数
}
//--------------------------------------------------------------
编译能通过,但只会响应WndProcaa函数,WMDropFiles不会响应。
[解决办法]
这是我代码中的例子,你参考一下!
MESSAGE void MainFrameResponse(TMessage Msg);
MESSAGE void DLLPanelResponse(TMessage Msg);
BEGIN_MESSAGE_MAP//+++
VCL_MESSAGE_HANDLER(WM_SKINCHANGE, TMessage,MainFrameResponse);//+++
VCL_MESSAGE_HANDLER(WM_TESTITEMCHANGE, TMessage,DLLPanelResponse);//+++
END_MESSAGE_MAP(TForm);