I have this program that embeds controls programatically to the tool bar. Th problem is that the static control was not trasnparent and so was altering the colour of the tool bar around it. So I wrote my own tool bar class and my own static control class each inheriting the corresponding mfc classes and I handled WM_CtlColor. Rather that that solving the problem, my static control, though now transparent, flickers, disappears and reappears, but mostly stays invisible.
So, I whent on to handle all other kinds of messages in a bid to solve the problem, but the problem persited. Initially I did the handling in the Toolbar class, when that did not work, I started handling in the static class as well. later I handled in both classes all to no avail.
What could be the ptoblem and the solution. MainFrame,my Toolbar, and my static classes are shown below:
#pragma once
#include"MyToolBar.h"
class CMainFrame : public CMDIFrameWndEx
{
DECLARE_DYNAMIC(CMainFrame)
public:
CMainFrame();
public:
public:
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL LoadFrame(UINT nIDResource, DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, CWnd* pParentWnd = NULL, CCreateContext* pContext = NULL);
public:
virtual ~CMainFrame();
afx_msg void OnTest();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected: CMFCMenuBar m_wndMenuBar;
CMyToolBar m_wndToolBar;
CMFCStatusBar m_wndStatusBar;
CMFCToolBarImages m_UserImages;
private:
public:
MyCommand GetCommand() { return m_eCommand;}
public:
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnWindowManager();
afx_msg void OnViewCustomize();
afx_msg LRESULT OnToolbarCreateNew(WPARAM wp, LPARAM lp);
DECLARE_MESSAGE_MAP()
};
#pragma once
#include "MyStatic.h"
class CMyToolBar : public CMFCToolBar
{
DECLARE_DYNAMIC(CMyToolBar)
public:
CMyToolBar();
virtual ~CMyToolBar();
public:
void EmbedControls();
CMyStatic m_pStatic3;
CComboBox m_pCombo1,m_pCombo2,m_pCombo3;
CWnd m_pEdit1;
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnSize(UINT nType, int cx, int cy);
};
#include "stdafx.h"
#include "MyDoc.h"
#include "MyToolBar.h"
IMPLEMENT_DYNAMIC(CMyToolBar, CMFCToolBar)
CMyToolBar::CMyToolBar()
{
}
CMyToolBar::~CMyToolBar()
{
}
BEGIN_MESSAGE_MAP(CMyToolBar, CMFCToolBar)
ON_WM_SIZE()
END_MESSAGE_MAP()
void CMyToolBar::EmbedControls()
{
int iy = 1,icy = 19;
int ixCombo1 = 230,icxCombo1 = 100;
int ixCombo2 = ixCombo1 + icxCombo1 + 5,icxCombo2 = 100;
int ixCombo3 = ixCombo2 + icxCombo2 + 5,icxCombo3 = 100;
int ixStatic1 = ixCombo3 + icxCombo3 + 5,icxStatic1 = 55;
int ixEdit1 = ixStatic1 + icxStatic1 + 5,icxEdit1 = 200;
CRect rcCombo1(ixCombo1,iy,ixCombo1 + icxCombo1,iy + icy);
m_pCombo1.Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST,rcCombo1,(CWnd *)this,0);
CRect rcCombo2(ixCombo2,iy,ixCombo2 + icxCombo2,iy + icy);
m_pCombo2.Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST,rcCombo2,(CWnd *)this,0);
CRect rcCombo3(ixCombo3,iy,ixCombo3 + icxCombo3,iy + icy);
m_pCombo3.Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST,rcCombo3,(CWnd *)this,0);
CRect rcStatic1(ixStatic1,iy,ixStatic1 + icxStatic1|SS_CENTER,iy + icy);
m_pStatic3.CreateEx(WS_EX_TRANSPARENT,_T("STATIC"),_T("Formula"),WS_VISIBLE|WS_CHILD,rcStatic1,(CWnd *)this,0);
CRect rcEdit1(ixEdit1,iy,ixEdit1 + icxEdit1,iy + icy);
m_pEdit1.CreateEx(WS_EX_CLIENTEDGE,_T("EDIT"),_T(""),WS_VISIBLE|WS_CHILD,rcEdit1,(CWnd *)this,0);
}
void CMyToolBar::OnSize(UINT nType, int cx, int cy)
{
CMFCToolBar::OnSize(nType, cx, cy);
if (::IsWindow(m_pStatic3.GetSafeHwnd()))
{
}
}
#pragma once
class CMyStatic : public CWnd
{
DECLARE_DYNAMIC(CMyStatic)
public:
CMyStatic();
virtual ~CMyStatic();
protected:
DECLARE_MESSAGE_MAP()
public:
HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
afx_msg void OnSize(UINT nType, int cx, int cy);
};
#include "stdafx.h"
#include "MyDoc.h"
#include "MyStatic.h"
IMPLEMENT_DYNAMIC(CMyStatic, CWnd)
CMyStatic::CMyStatic()
{
}
CMyStatic::~CMyStatic()
{
}
BEGIN_MESSAGE_MAP(CMyStatic, CWnd)
ON_WM_CTLCOLOR_REFLECT()
ON_WM_SIZE()
END_MESSAGE_MAP()
HBRUSH CMyStatic::CtlColor(CDC* pDC, UINT nCtlColor)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB( 0, 0, 0 ));
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
}
void CMyStatic::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
}