今天读到一个自定义消息函数修改发包命令,下载文件的命令号是4, 没太看懂此处用位运算的逻辑。“4 << 1 | 0”
//int ret = SendCommandPacket(4, false, (BYTE*)(LPCTSTR)strFile, strFile.GetLength()); //修改前
int ret = SendMessageA(WM_SEND_PACKET, 4 << 1 | 0, (LPARAM)(LPCSTR)strFile); //用自定义消息函数发送下载文件命令
......
#define WM_SEND_PACKET (WM_USER + 1)
//自定义消息响应函数
/*用位运算合并参数*/
LRESULT CRemoteControlClientDlg::OnSendPacket(WPARAM wParam, LPARAM lParam)
{
int ret = 0;
int cmd = wParam >> 1;
switch (cmd)
{
case 4: //下载文件
{
CString strFile = (LPCTSTR)lParam;
ret = SendCommandPacket(cmd, wParam & 1,
(BYTE*)(LPCTSTR)strFile, strFile.GetLength());
}
break;
case 6://截取屏幕
{
ret = SendCommandPacket(cmd, wParam & 1);
}
break;
default:
ret = -1;
}
return ret;
}