对VC不熟,打了几句话老是提示错误,帮我看一下问题在哪。
void CTESTDlg::OnOK()
{
// TODO: Add extra validation here
HWND hwnd = FindWindow(NULL, 'a');
SendMessage(hwnd, WM_CLOSE, 0, 0);
CDialog::OnOK();
}提示错误两个:
1. TESTDlg.cpp(175) : error C2664: 'FindWindowA' : cannot convert parameter 2 from 'const char' to 'const char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
2. error C2660: 'SendMessageA' : function does not take 4 parameters
void CTESTDlg::OnOK()
{
// TODO: Add extra validation here
HWND hwnd = FindWindow(NULL, 'a');
SendMessage(hwnd, WM_CLOSE, 0, 0);
CDialog::OnOK();
}提示错误两个:
1. TESTDlg.cpp(175) : error C2664: 'FindWindowA' : cannot convert parameter 2 from 'const char' to 'const char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
2. error C2660: 'SendMessageA' : function does not take 4 parameters
{
// TODO: Add extra validation here
HWND hwnd = FindWindow(NULL, "标题");
::SendMessage(hwnd, WM_CLOSE, 0, 0);
CDialog::OnOK();
}
error C2440: 'initializing' : cannot convert from 'class CWnd *' to 'struct HWND__ *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.还是提示错误
CWnd* hWnd = FindWindow(NULL, "±êÌâ");
::SendMessage(hWnd->GetSafeHwnd(),WM_CLOSE, 0, 0);
::SendMessage(hwnd, WM_CLOSE, 0, 0);
FindWindow(NULL, 'a');返回的是MFC里的CWnd
改成 ::FindWindow(NULL, 'a'); 返回的就是HWND了
{
// TODO: Add extra validation here
HWND hwnd = ::FindWindow(NULL, 'a');
::SendMessage(hwnd, WM_CLOSE, 0, 0);
CDialog::OnOK();
} 我改成这样编译通过了,下午去单位看看效果那位朋友解释下原因
而没有::则是成员函数,也就是Dlg的函数。
{
// TODO: Add extra validation here
CString Str="a";
HWND hwnd = FindWindow(NULL,&Str);
SendMessage(要接收的窗体.m_hwnd, WM_CLOSE, 0, 0);
CDialog::OnOK();
}
能解释下为什么吗? 我对VC不太熟,用Delphi写了主程序,其中调用一个VC写的总线测试程序,由于时间关系没改写那个VC程序,只是让两个程序互发消息完成界面的切换和关闭,这样两个程序就不容易看不出来是两个程序了。