Draw and re-pos CStatic controls in CDockablePane
-
Hi all, I have spend already many hours to find the reason of my current problem. I have a CDockablePane, in which I am placing a lot of CStatic controls. The CStatic controls I am using to display bitmaps. A dockable pane is designed for resizing at any time. Therefore I try to recalculate the positions of each CStatic after OnSize is called. With some CStatic controls it is running well. But when I am adding an additional control, I am getting strange problems: The pane is not repainted properly and OnPaint is recalled cyclically. My code (partially): Header:
class CPaneCtrlPLC : public CDockablePane
{
DECLARE_DYNAMIC(CPaneCtrlPLC)public:
CPaneCtrlPLC();
virtual ~CPaneCtrlPLC();protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);private:
CStatic m_Ctrl_PLCLED[6];
CStatic m_SwitchCtrl;
CStatic m_Ctrl_test;C-File:
int CPaneCtrlPLC::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;m\_ColorSieGreen = RGB(0, 153, 153); m\_ColorSieWhite = RGB(251, 253, 253); m\_ColorText = RGB(230, 228, 193); m\_ColorBgnd = RGB(119, 117, 127); m\_BrushSieGreen.CreateSolidBrush(m\_ColorSieGreen); m\_BrushBgnd.CreateSolidBrush(m\_ColorBgnd); m\_BitmapSWITCHSTOP.LoadBitmapW(IDB\_SWITCH\_STOP); m\_bitmapLEDOFF.LoadBitmapW(IDB\_LEDOFF); m\_bitmapLEDRED.LoadBitmapW(IDB\_LEDRED); m\_bitmapLEDGREEN.LoadBitmapW(IDB\_LEDGREEN); m\_bitmapTest.LoadBitmapW(IDB\_LEDGREEN); // TODO: Add your specialized creation code here DWORD dwStyle = WS\_CHILD | WS\_VISIBLE | TVS\_SHOWSELALWAYS | SS\_BITMAP; m\_SwitchCtrl.Create(NULL, dwStyle, CRect(0, 0,0,0),this); m\_SwitchCtrl.SetBitmap(m\_BitmapSWITCHSTOP); int iLed; for (iLed = 0; iLed < MaxNumPLCLeds; ++iLed) { DWORD dwStyle = WS\_CHILD | WS\_VISIBLE | TVS\_SHOWSELALWAYS | SS\_BITMAP; m\_Ctrl\_PLCLED\[iLed\].Create(NULL, dwStyle, CRect(xPosPLCLEDS,(yPosPLCLEDS + (26\* iLed)), 0, 0), this); m\_Ctrl\_PLCLED\[iLed\].SetBitmap(m\_bitmapLEDOFF); } { DWORD dwStyle = WS\_CHILD | WS\_VISIBLE | TVS\_SHOWSELALWAYS | SS\_BITMAP; m\_Ctrl\_test.Create(NULL, dwStyle, CRect(xPosPLCLEDS + (17 \* iLed), yPosPAELEDS + 20, 0, 0), this); m\_Ctrl\_test.SetBitmap(m\_bitmapTest); }
...
I was able to strip the OnPaint(0) function to a minumum to reprocude the problem. If I comment out the re-positioning of the m_Ctrl_test, everything works fine, but with this statement I have
-
Hi all, I have spend already many hours to find the reason of my current problem. I have a CDockablePane, in which I am placing a lot of CStatic controls. The CStatic controls I am using to display bitmaps. A dockable pane is designed for resizing at any time. Therefore I try to recalculate the positions of each CStatic after OnSize is called. With some CStatic controls it is running well. But when I am adding an additional control, I am getting strange problems: The pane is not repainted properly and OnPaint is recalled cyclically. My code (partially): Header:
class CPaneCtrlPLC : public CDockablePane
{
DECLARE_DYNAMIC(CPaneCtrlPLC)public:
CPaneCtrlPLC();
virtual ~CPaneCtrlPLC();protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);private:
CStatic m_Ctrl_PLCLED[6];
CStatic m_SwitchCtrl;
CStatic m_Ctrl_test;C-File:
int CPaneCtrlPLC::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;m\_ColorSieGreen = RGB(0, 153, 153); m\_ColorSieWhite = RGB(251, 253, 253); m\_ColorText = RGB(230, 228, 193); m\_ColorBgnd = RGB(119, 117, 127); m\_BrushSieGreen.CreateSolidBrush(m\_ColorSieGreen); m\_BrushBgnd.CreateSolidBrush(m\_ColorBgnd); m\_BitmapSWITCHSTOP.LoadBitmapW(IDB\_SWITCH\_STOP); m\_bitmapLEDOFF.LoadBitmapW(IDB\_LEDOFF); m\_bitmapLEDRED.LoadBitmapW(IDB\_LEDRED); m\_bitmapLEDGREEN.LoadBitmapW(IDB\_LEDGREEN); m\_bitmapTest.LoadBitmapW(IDB\_LEDGREEN); // TODO: Add your specialized creation code here DWORD dwStyle = WS\_CHILD | WS\_VISIBLE | TVS\_SHOWSELALWAYS | SS\_BITMAP; m\_SwitchCtrl.Create(NULL, dwStyle, CRect(0, 0,0,0),this); m\_SwitchCtrl.SetBitmap(m\_BitmapSWITCHSTOP); int iLed; for (iLed = 0; iLed < MaxNumPLCLeds; ++iLed) { DWORD dwStyle = WS\_CHILD | WS\_VISIBLE | TVS\_SHOWSELALWAYS | SS\_BITMAP; m\_Ctrl\_PLCLED\[iLed\].Create(NULL, dwStyle, CRect(xPosPLCLEDS,(yPosPLCLEDS + (26\* iLed)), 0, 0), this); m\_Ctrl\_PLCLED\[iLed\].SetBitmap(m\_bitmapLEDOFF); } { DWORD dwStyle = WS\_CHILD | WS\_VISIBLE | TVS\_SHOWSELALWAYS | SS\_BITMAP; m\_Ctrl\_test.Create(NULL, dwStyle, CRect(xPosPLCLEDS + (17 \* iLed), yPosPAELEDS + 20, 0, 0), this); m\_Ctrl\_test.SetBitmap(m\_bitmapTest); }
...
I was able to strip the OnPaint(0) function to a minumum to reprocude the problem. If I comment out the re-positioning of the m_Ctrl_test, everything works fine, but with this statement I have
Solved by myself! In OnPaint() I changed the positions of the CStaticControls. Of course this is causing "recursive" WM_PAINT calls. I moved this code to other functions (OnSize, OnTimer,...), now it works!