我在对话框内有一个按钮,现在我想响应按钮的WM_LBUTTONDOWN,WM_LBUTTONUP,也就是在鼠标左键按下响应一个事件,鼠标左键弹开时响应另外一个事件。
以下是我的代码:
BOOL CMy12Dlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
CString str;
CWnd *pWnd;
if(pWnd->GetDlgCtrlID() == IDC_BUTTON1)
{
if(pMsg->message == WM_LBUTTONDOWN)
{
str.Format("ON");
SetDlgItemText(IDC_EDIT1,str);
}
if(pMsg->message == WM_LBUTTONUP)
{
str.Format("OFF");
SetDlgItemText(IDC_EDIT1,str);
}
}
return CDialog::PreTranslateMessage(pMsg);
}
编译后出现报警。12.exe - 0 error(s), 1 warning(s)
C:\Documents and Settings\Administrator\桌面\12\12Dlg.cpp(177) : warning C4700: local variable 'pWnd' used without having been initialized
运行后就出现了程序终止对话框。
请问各位VC++高手,问题出在哪里?谢谢
以下是我的代码:
BOOL CMy12Dlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
CString str;
CWnd *pWnd;
if(pWnd->GetDlgCtrlID() == IDC_BUTTON1)
{
if(pMsg->message == WM_LBUTTONDOWN)
{
str.Format("ON");
SetDlgItemText(IDC_EDIT1,str);
}
if(pMsg->message == WM_LBUTTONUP)
{
str.Format("OFF");
SetDlgItemText(IDC_EDIT1,str);
}
}
return CDialog::PreTranslateMessage(pMsg);
}
编译后出现报警。12.exe - 0 error(s), 1 warning(s)
C:\Documents and Settings\Administrator\桌面\12\12Dlg.cpp(177) : warning C4700: local variable 'pWnd' used without having been initialized
运行后就出现了程序终止对话框。
请问各位VC++高手,问题出在哪里?谢谢
然后你用这个空的窗口指针GetDlgCtrlID() 当然就错了。
那应该怎么做修改呢,怎么操作这个CWnd *pWnd呢?谢谢!
我的要求在不同的按钮中响应WM_LBUTTONDOWN,WM_LBUTTONUP,
WM_LBUTTONDOWN,WM_LBUTTONUP所对应的内容也多不一样。
如何知道,某个LButton是哪个Button发出的?
谢谢!
你的pWnd是空值哎
HWND hWnd=0;
GetDlgItem(IDC_EDIT1,&hWnd);
if (pMsg->hwnd==hWnd)
{
switch (pMsg->message )
{
case WM_KEYDOWN:
AfxMessageBox(L"d");
break; } }