MFC-ON_WM_TIMER () - Problem mit static cast

Probleme mit ON_WM_TIMER in meiner Klasse CDatabaseApplicationApp die sich CWinApp

> 1>c:\programs\databaseapplication\databaseapplication\databaseapplication.cpp(20):
> error C2440: 'static_cast' : cannot convert from 'void (__thiscall
> CDatabaseApplicationApp::* )(UINT_PTR)' to 'void (__thiscall CWnd::*
> )(UINT_PTR)' 1>          Types pointed to are unrelated; conversion
> requires reinterpret_cast, C-style cast or function-style cast

Habe ich die Funktion OnTimer:

class CLifescanDatabaseApplicationApp : public CWinApp
{
public:
    CLifescanDatabaseApplicationApp();
protected:
    CLifescanDatabaseApplicationDlg * m_ptheWindow;
//Overrides
public:
    virtual BOOL InitInstance();

//Implementation
    afx_msg void OnTimer(UINT_PTR nTimerID);
    DECLARE_MESSAGE_MAP()
};

OnTimer ist nur:

void CDatabaseApplicationApp::OnTimer(UINT_PTR nTimerID)
{
    AfxMessageBox(_T("Help"));
}

Ist der timer eingestellt mit ein definieren, an der Spitze der Quellcode-Datei:

#define ID_TIMER_DATABASEQUERY 1

sowie SetTimer definiert ist, in

BOOL CDatabaseApplicationApp::InitInstance()
{
    //InitCommonControlsEx() is required on Windows XP if an application
    //manifest specifies use of ComCtl32.dll version 6 or later to enable
    //visual styles.  Otherwise, any window creation will fail.
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    //Set this to include all the common control classes you want to use
    //in your application.
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    CWinApp::InitInstance();


    AfxEnableControlContainer();
AfxInitRichEdit2();
    //Create the shell manager, in case the dialog contains
    //any shell tree view or shell list view controls.
    CShellManager *pShellManager = new CShellManager;

    //Standard initialization
    //If you are not using these features and wish to reduce the size
    //of your final executable, you should remove from the following
    //the specific initialization routines you do not need
    //Change the registry key under which our settings are stored
    //TODO: You should modify this string to be something appropriate
    //such as the name of your company or organization
    SetRegistryKey(_T("Local AppWizard-Generated Applications"));



    m_ptheWindow = new CDatabaseApplicationDlg();
    m_pMainWnd = m_ptheWindow;
    if(m_ptheWindow!=nullptr)
    {
        m_ptheWindow->Create(CDatabaseApplicationDlg::IDD,CWnd::GetDesktopWindow());
        m_ptheWindow->ShowWindow(SW_SHOW);
    }
    //Delete the shell manager created above.
    if (pShellManager != NULL)
    {
        delete pShellManager;
    }

    if(!m_ptheWindow->SetTimer(ID_TIMER_DATABASEQUERY,10000,nullptr))
    {
        return false;
    }
    //Since the dialog has been closed, return FALSE so that we exit the
    // application, rather than start the application's message pump.
    return TRUE;
}

Irgendwelche Ideen, wie ich dieses problem lösen?

  • ist das der code? Verwenden Sie keine OnTimer im SetTimer, weder gibt es eine static_cast überall
  • Ja, es ist echtes code. Nicht sicher, was du damit meinst OnTimer in SetTimer, Beispiele in der Prosise Buch und im internet haben beide.
  • compiler beschwert sich über static_cast in Zeile 20 der databaseapplication.cpp. Dies ist nicht in dem code, den Sie vorgelegt. Da Sie nicht angeben, den Rückruf in SetTimer aufrufen OnTimer Methode in der Klasse auf, die Sie nennen SetTimer die CDatabaseApplicationDlg, so müssen Sie zum überschreiben OnTimer es.
  • Also, wie würde ich call SetTimer auf einer Klasse ohne ein Fenster. Sie müssen erklären, einen Rückruf, da ich noch keine verwendet man vor, sorry.
  • Ich habe die Antwort. Ich bin jedoch immer noch unklar, Woher die static_cast kommen.
InformationsquelleAutor James | 2012-09-14
Schreibe einen Kommentar