这是我的createialogparam函数,它从这里调用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;
}
}
}
并且声明就像这样 -
static 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中的全局声明的变量而不将这些变量声明为静态,因为它们在其他部分也被用作非静态变量。程序??
答案 0 :(得分:0)
如果通过
静态DialogProc中的全局声明变量
你的意思是AMEPreviewHandler
实例中的成员变量,我想你已经在LPARAM中发送了你需要的东西:
m_hwndPreview = CreateDialogParam( ...(LPARAM)this);
当它调用你的DialogProc时,这些转到最后一个参数:LPARAM lParam
所以你可以这样做
AMEPreviewHandler* instance = (AMEPreviewHandler *)lParam;
instance->m_Whatever...