0
我有一個類。現在的問題是,經過幾次嘗試,我仍然存在巨大的錯誤。我的問題是我不知道如何正確地爲這個類聲明一個新的對象,在另一個cpp文件中。我想從其他cpp文件中調用/觸發此RebarHandler類中的函數。我一直在得到如'未經初始化使用','調試斷言失敗'等問題。需要知道如何在另一個cpp文件中正確創建一個新對象
在其他CPP文件,我包括RebarHandler.h,做這樣的:
CRebarHandler *test=NULL;
test->setButtonMenu2();
當編譯,我不會給任何錯誤。但是,當運行時,它會給出錯誤和我的IE崩潰。我需要幫助。
下面是我說的是類:
#pragma once
class CIEWindow;
class CRebarHandler : public CWindowImpl<CRebarHandler>{
public:
CRebarHandler(HWND hWndToolbar, CIEWindow *ieWindow);
CRebarHandler(){};
~CRebarHandler();
BEGIN_MSG_MAP(CRebarHandler)
NOTIFY_CODE_HANDLER(TBN_DROPDOWN, onNotifyDropDown)
NOTIFY_CODE_HANDLER(TBN_TOOLBARCHANGE, onNotifyToolbarChange)
NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, onNotifyCustomDraw)
NOTIFY_CODE_HANDLER(TBN_ENDADJUST, onNotifyEndAdjust)
MESSAGE_HANDLER(WM_SETREDRAW, onSetRedraw)
END_MSG_MAP()
// message handlers
LRESULT onNotifyDropDown(WPARAM wParam, LPNMHDR pNMHDR, BOOL& bHandled);
LRESULT onNotifyToolbarChange(WPARAM wParam, LPNMHDR pNMHDR, BOOL& bHandled);
LRESULT onNotifyCustomDraw(WPARAM wParam, LPNMHDR pNMHDR, BOOL& bHandled);
LRESULT onNotifyEndAdjust(WPARAM wParam, LPNMHDR pNMHDR, BOOL& bHandled);
LRESULT onSetRedraw(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
// manage the subclassing of the IE rebar
void subclass();
void unsubclass();
void handleSettings();
void setButtonMenu2();
bool findButton(HWND hWndToolbar);
private:
// handles to the various things
HWND m_hWnd;
HWND m_hWndToolbar, m_hWndRebar, m_hWndTooltip;
HMENU m_hMenu;
int m_buttonID;
int m_ieVer;
CIEWindow *m_ieWindow;
// toolbar finding functions
void scanForToolbarSlow();
void getRebarHWND();
void setButtonMenu();
};