需 CChart 2.5.1.4+ 版本。關鍵點:**附加到主對話框而非 Picture 控制項**,因對話框會攔截子控制項訊息導致異常。
Lesson18IDC_CANVASLesson18Dlg.h 引入庫,宣告 CChartWnd m_ChartWnd;OnInitDialog 計算 Picture 相對主視窗偏移:CWnd *pWnd = GetDlgItem(IDC_CANVAS); CRect rtWCtrl, rtWParent; pWnd->GetWindowRect(&rtWCtrl); GetWindowRect(&rtWParent); int capH = GetSystemMetrics(SM_CYCAPTION); int dx = GetSystemMetrics(SM_CXBORDER); int offsetx = rtWCtrl.left - rtWParent.left - dx; int offsety = rtWCtrl.top - rtWParent.top - capH; CRect rtCtrlClient; pWnd->GetClientRect(&rtCtrlClient); OffsetRect(&rtCtrlClient, offsetx, offsety); m_ChartWnd.Attach(m_hWnd, kTypeXY, rtCtrlClient);
OnDestroy 呼叫 Detach()對話框內嵌圖表:
互動彈出屬性對話框(CChart 視窗的子視窗),如俄羅斯套娃:
偏移計算是核心,掌握後對話框嵌入不再困難。