BOOL CDicomView3DDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if (pMsg->hwnd == m_pic1.m_hWnd && pMsg->message == WM_MOUSEMOVE)//自定义控件上的消息
{
BYTE *frameBuf ;
BYTE a[256][4];
BYTE *Buf;
HBITMAP hbmp;
...
MFC c++,下边这个是鼠标经过事件,想改成鼠标经过"且"同时按鼠标左键代码才生效怎么改?谢谢
答案:2 悬赏:70 手机版
解决时间 2021-02-15 17:48
- 提问者网友:王者佥
- 2021-02-15 05:20
最佳答案
- 五星知识达人网友:鸽屿
- 2021-02-15 06:36
在你的if里添加 :
UINT nFlags=pMsg->wParam;
if ( nFlags & MK_LBUTTON )
{
}
UINT nFlags=pMsg->wParam;
if ( nFlags & MK_LBUTTON )
{
}
全部回答
- 1楼网友:天凉才是好个秋
- 2021-02-15 06:55
#ifndef _mousepro_h_
#define _mousepro_h_
class cmyapp : public cwinapp {
public:
virtual bool initinstance();
};
class cmainwindow : public cframewnd {
public:
cmainwindow();
protected:
bool m_bup;
cstring buffer;
afx_msg void onpaint();
afx_msg void onlbuttondown();
afx_msg void onlbuttonup();
declare_message_map()
};
#endif // _mousepro_h_
=========================================
#include <afxwin.h>
#include "mousepro.h"
cmyapp myapp;
bool cmyapp::initinstance() {
m_pmainwnd = new cmainwindow;
m_pmainwnd->showwindow(m_ncmdshow);
m_pmainwnd->updatewindow();
return true;
} // initinstance
//
begin_message_map(cmainwindow, cframewnd)
on_wm_paint()
on_wm_lbuttondown()
on_wm_lbuttonup()
end_message_map()
cmainwindow::cmainwindow() {
create(null, "mouse pro");
m_bup = false;
} // default constructor
void cmainwindow::onpaint() {
cpaintdc dc(this);
crect rect;
getclientrect(&rect);
int imousebuttons;
cstring string;
imousebuttons = ::getsystemmetrics(sm_cmousebuttons);
string.format("mouse has %d button(s)!", imousebuttons);
dc.textout(10, 0, string);
if (m_bup) {
dc.textout(10, 60, buffer);
}
else {
// do not recieve onlbuttonup message
// but left button is up
if (::getkeystate(vk_lbutton) < 0) {
buffer.format("left mouse pressed!");
}
dc.textout(10, 50, buffer);
}
} // onpaint
void cmainwindow::onlbuttondown() {
m_bup = false;
buffer.format("left button down!");
setcapture();
invalidate();
} // onlbuttondown
void cmainwindow::onlbuttonup() {
m_bup = true;
if (getcapture() == this) {
::releasecapture();
buffer.format("no matter your mouse is in or out client area! i can capture you! :) ");
}
invalidate();
} // onlbuttonup
=============================================
加入鼠标处理函数就可以了。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯