カスタム描画を使用して CSliderCtrl にいくつかの変更を加えています。コントロールはダイアログで使用されます。ここに構造があります:私のMessageMapには次のものがあります:ON_NOTIFY_REFLECT_EX(NM_CUSTOMDRAW, OnNMCustomdraw)
OnNMCustomdraw メソッドは次のようになります。
BOOL CCustomSliderCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
*pResult = CDRF_DODEFAULT;
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
switch(pNMCD->dwDrawStage)
{
case CDDS_PREPAINT:
{
//Dialogs don't receive CDRF_NOTIFYITEMDRAW notifcations by returning it as part of pResult, we must
//use the following so we ensure we receive the msg
SetWindowLong(pNMHDR->hwndFrom, DWL_MSGRESULT, CDRF_NOTIFYITEMDRAW);
return TRUE;
}
case CDDS_ITEMPREPAINT:
if(pNMCD->dwItemSpec == TBCD_CHANNEL)
{
...SNIP...
SetWindowLong(pNMHDR->hwndFrom, DWL_MSGRESULT, CDRF_SKIPDEFAULT);
return TRUE;
}
}
return FALSE;
}
読んでみると、SetWindowLong を使用してカスタム描画の戻り値を設定する必要があることがわかりました。そうしないと、メソッドが常に CDDS_ITEMPREPAINT メッセージを受け取るとは限りません。ただし、SetWindowLong を使用すると、アプリケーションは CDDS_ITEMPREPAINT を受信しないため、スライダーは標準のスライダーのように見えます。スライダーの上にカーソルを置いたり、ダイアログを最小化および最大化したりするなど、スライダー上で何らかの操作が行われると、アプリケーションがクラッシュします。
TBCD_CHANNEL コードには到達しないため、抜粋しました。
デバッグ モードで実行すると、afxcrit.cpp の AfxUnlockGlobals メソッドの最後でクラッシュします。スタック トレースは次のとおりです。
comctl32.dll!_TrackBarWndProc@16() + 0x551 bytes
user32.dll!_InternalCallWinProc@20() + 0x28 bytes
user32.dll!_UserCallWinProcCheckWow@32() + 0xb7 bytes
user32.dll!_CallWindowProcAorW@24() + 0x51 bytes
user32.dll!_CallWindowProcW@20() + 0x1b bytes
mfc90ud.dll!CWnd::DefWindowProcW(unsigned int nMsg=15, unsigned int wParam=0, long lParam=0) Line 1043 + 0x20 bytes C++
mfc90ud.dll!CWnd::WindowProc(unsigned int message=15, unsigned int wParam=0, long lParam=0) Line 1756 + 0x1c bytes C++
mfc90ud.dll!AfxCallWndProc(CWnd * pWnd=0x0012fdbc, HWND__ * hWnd=0x000308fe, unsigned int nMsg=15, unsigned int wParam=0, long lParam=0) Line 240 + 0x1c bytes C++
mfc90ud.dll!AfxWndProc(HWND__ * hWnd=0x000308fe, unsigned int nMsg=15, unsigned int wParam=0, long lParam=0) Line 403 C++
mfc90ud.dll!AfxWndProcBase(HWND__ * hWnd=0x000308fe, unsigned int nMsg=15, unsigned int wParam=0, long lParam=0) Line 441 + 0x15 bytes C++
user32.dll!_InternalCallWinProc@20() + 0x28 bytes
user32.dll!_UserCallWinProcCheckWow@32() + 0xb7 bytes
user32.dll!_DispatchClientMessage@20() + 0x4d bytes
user32.dll!___fnDWORD@4() + 0x24 bytes
ntdll.dll!_KiUserCallbackDispatcher@12() + 0x13 bytes
user32.dll!_NtUserDispatchMessage@4() + 0xc bytes
user32.dll!_DispatchMessageW@4() + 0xf bytes
mfc90ud.dll!AfxInternalPumpMessage() Line 183 C++
mfc90ud.dll!CWinThread::PumpMessage() Line 900 C++
mfc90ud.dll!AfxPumpMessage() Line 190 + 0xd bytes C++
mfc90ud.dll!CWnd::RunModalLoop(unsigned long dwFlags=4) Line 4386 + 0x5 bytes C++
mfc90ud.dll!CDialog::DoModal() Line 584 + 0xc bytes C++
SetSelection.exe!CSetSelectionApp::InitInstance() Line 64 + 0xb bytes C++
mfc90ud.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00020a84, int nCmdShow=1) Line 37 + 0xd bytes C++
SetSelection.exe!wWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00020a84, int nCmdShow=1) Line 34 C++
SetSelection.exe!__tmainCRTStartup() Line 578 + 0x35 bytes C
SetSelection.exe!wWinMainCRTStartup() Line 403 C
kernel32.dll!_BaseProcessStart@4() + 0x23 bytes
それで、誰かがこの問題について何か洞察を持っていますか?さらに情報が必要な場合は、お知らせください。
更新: SetWindowLong を使用する代わりに、結果を pResult に割り当ててから返すだけで、回避策を見つけました。SetRangeMin(GetRangeMin(), TRUE); を呼び出してサブアイテムを再描画する再描画を強制します。正確にはエレガントではありませんが、機能します。