Was ist der Unterschied zwischen dem Klick auf einen Toolbarbutton und WM_COMMAND?



  • Moin!

    Ich habe eine SDI mit mehreren Formviews (wie in der FAQ beschrieben).
    Wenn ich per Menü oder Toolbar zu einem anderen View umschalte, funktioniert alles super.

    Wenn ich aber so umschalte:

    AfxGetMainWnd()->SendMessage(WM_COMMAND, ID_KUNDENVIEW);
    

    dann bekomme ich einen ASSERT (Zeile 17).

    void CWnd::AssertValid() const
    {
    	if (m_hWnd == NULL)
    		return;     // null (unattached) windows are valid
    
    	// check for special wnd??? values
    	ASSERT(HWND_TOP == NULL);       // same as desktop
    	if (m_hWnd == HWND_BOTTOM)
    		ASSERT(this == &CWnd::wndBottom);
    	else if (m_hWnd == HWND_TOPMOST)
    		ASSERT(this == &CWnd::wndTopMost);
    	else if (m_hWnd == HWND_NOTOPMOST)
    		ASSERT(this == &CWnd::wndNoTopMost);
    	else
    	{
    		// should be a normal window
    		ASSERT(::IsWindow(m_hWnd));
    
    		// should also be in the permanent or temporary handle map
    		CHandleMap* pMap = afxMapHWND();
    		ASSERT(pMap != NULL);
    
    		CObject* p;
    		ASSERT((p = pMap->LookupPermanent(m_hWnd)) != NULL ||
    			(p = pMap->LookupTemporary(m_hWnd)) != NULL);
    		ASSERT((CWnd*)p == this);   // must be us
    
    		// Note: if either of the above asserts fire and you are
    		// writing a multithreaded application, it is likely that
    		// you have passed a C++ object from one thread to another
    		// and have used that object in a way that was not intended.
    		// (only simple inline wrapper functions should be used)
    		//
    		// In general, CWnd objects should be passed by HWND from
    		// one thread to another.  The receiving thread can wrap
    		// the HWND with a CWnd object by using CWnd::FromHandle.
    		//
    		// It is dangerous to pass C++ objects from one thread to
    		// another, unless the objects are designed to be used in
    		// such a manner.
    	}
    }
    

    Den Kommentar habe ich gesehen, aber ich verwende keine Threads.

    Im Callstack ist kein Code von mir zu sehen. 😕

    CWnd::AssertValid() line 875 + 36 bytes
    AfxAssertValidObject(const CObject * 0x01a4e8b0 {CTempWnd hWnd=0x000d0bf8}, const char * 0x5f4cccf0 THIS_FILE, int 2153) line 108
    CWnd::GetTopLevelParent() line 2155
    CWinThread::PreTranslateMessage(tagMSG * 0x00432b08 {msg=0x00000100 wp=0x0000000d lp=0x001c0001}) line 673 + 8 bytes
    CWinThread::PumpMessage() line 841 + 30 bytes
    CWinThread::Run() line 480 + 11 bytes
    CWinApp::Run() line 400
    AfxWinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00134045, int 1) line 49 + 11 bytes
    WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00134045, int 1) line 30
    WinMainCRTStartup() line 330 + 54 bytes

    Wie suche ich den Fehler nun? Wenn ich ihn ignoriere bemerke ich keine Probleme.



  • Hat niemand eine Idee?
    Nichtmal, was ich wo gucken könnte?
    😞



  • An welcher Stelle in deinem Programm steht denn dieser Aufruf? Das einzige Problem, das mir spontan auffällt, ist, daß du den SendMessage()-Befehl eventuell vor der Erzeugung des Fensters gestartet haben könntest.



  • Das SendMessage steht in einer Funktion die vom PreTranslateMessage meines einen Views aufgerufen wird.
    Den Mainframe sehe ich zu dem Zeitpunkt schon.

    PS: Ich löse das SendMessage ja per Barcodescan aus.
    Klicke ich stattdessen in die Toolbar auf die Schaltfläche für den neuen View, dann kommt kein ASSERT.


Anmelden zum Antworten