Pregunta

I am trying to subclass a progress control in a dialog box using this code:

ATL::CContainedWindowT<WTL::CProgressBarCtrl> progress;
// ...
progress.SubclassWindow(GetDlgItem(IDC_PROGRESS));

All good there. Now if I try to do this:

progress.SetRange(0, 100);

I get access violation exception on SendMessage in a trivial WTL's SetRange() implementation. I have been searching up and down and all I could find was this could be some "thunking" issue as mentioned in Applications Using Older ATL Components May Experience Conflicts With DEP which should not really apply to me because I am using the latest ATL and WTL (Visual Studio 2010 and WTL 8.1). I get the same issue even if I use WTL 8.0.

Subclassing was done OK as HWND is valid. Any ideas?

¿Fue útil?

Solución

WTL::CProgressBarCtrl m_Progress; <~ use that to attach the progress bar, not CContainedWindow.

Otros consejos

If you subclass a window, then you are expected to implement a message map for this subclassed control. This includes connecting your member variable to message map in constructor, adding ALT_MSG_MAP to the class message map. Are you doing this? I suppose you do not.

Do you need this in first place? To only send messages you don't need subclassing, you only need to attach real HWND to the CProgressBarCtrl instance:

WTL::CProgressBarCtrl m_ProgressBar;
// ...
m_ProgressBar = GetDlgItem(IDC_PROGRESS);
m_ProgressBar.SetRange(...

Subclassing was done OK as HWND is valid

No, it was not OK. You hooked the window but you did not supply your WindowProc. Hence, the issue.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top