Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Draw and re-pos CStatic controls in CDockablePane

Draw and re-pos CStatic controls in CDockablePane

Scheduled Pinned Locked Moved C / C++ / MFC
help
2 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 8534035
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • M Member 8534035

      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

      M Offline
      M Offline
      Member 8534035
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups