这是我的 createdialogparam 函数,它从这里调用 DialogProc 函数-
HRESULT AMEPreviewHandler::CreatePreviewWindow()
{
assert(m_hwndPreview == NULL);
assert(m_hwndParent != NULL);
HRESULT hr = S_OK;
m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this); /here the dialog proc function is called
if (m_hwndPreview == NULL)
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
..........
...
}
这是DialogProc函数的定义-
BOOL CALLBACK AMEPreviewHandler::DialogProc(HWND m_hwndPreview, UINT Umsg, WPARAM wParam, LPARAM lParam)
{
static RECT m_rcParent ;
switch(Umsg)
{
case WM_INITDIALOG:
{
return 0;
}
break;
........
case WM_COMMAND:
{
int ctl = LOWORD(wParam);
int event = HIWORD(wParam);
if (ctl == IDC_PREVIOUS && event == BN_CLICKED )
{
CreateHtmlPreview(); //it must be static now and it is not able to access the non static vraibles delared globally in the program
return 0;
}
}
}
声明是这样的-
静态 BOOL CALLBACK DialogProc(HWND hWindow,UINT uMsg,WPARAM wParam,LPARAM lParam);//假设它是静态的..如果是静态的,它不会给出任何错误..如果它没有声明为静态的,它会
在这里给出错误-
m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this); //error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'DLGPROC'
有什么方法可以访问静态 DialogProc 中的全局声明变量,或者可以访问 dialogproc 中的全局声明变量而不将这些变量声明为静态,因为它们在程序的其他部分也用作非静态变量?