对话框回调函数问题求助:
为什么在程序函数中找不到回调函数?
在一个类中使用DialogBox()宏创建对话框
希望使用一个私有成员作为回调函数
但是把这个函数名作为参数传给DialogBox(..)时,编译出现错误:
error C2440: 'type cast' : cannot convert
from '' to 'int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
None of the functions with this name in scope match the target type
实在弄不懂怎么回事,
于是把回调函数设为全局函数,编译通过,但是
DialogBox(m_hInstance,
MAKEINTRESOURCE(IDD_ADDRECORD),
m_hwnd,
(DLGPROC)AddDlgProc) ;
结果对话框显示很不正常,其后面的窗口(是父窗口)都变灰变白了
并且按动对话框里的按纽时也不响应回调函数中的操作,
最终只好按Alt+Ctrl+Del强行退出程序
谁帮看看是什么问题?
下面是对应的回调函数,把它设为全局函数后才能编译通过:
INT_PTR CALLBACK CMainProc::AddDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance ;
switch (msg)
{
case WM_CREATE :
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
MessageBox(NULL,"CREATE","warning",MB_OK);
return 0 ;
case WM_INITDIALOG:
MessageBox(NULL,"init","warning",MB_OK);
break;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDC_ADD:
MessageBox (
NULL,
"idadd",
"note", MB_OK) ;
EndDialog(hDlg,0);
break ;
}
return 0 ;
case WM_DESTROY :
return 0 ;
}
return 1;
}
谁能告诉我这其中出了什么问题?