#include <afxdlgs.h>
#define BUTTON 1000
class CSimpleApp : public CWinApp
{
public:
BOOL InitInstance();
};
class CMainFrame : public CFrameWnd
{
public:
void refreshwindows(WPARAM, LPARAM );
CMainFrame();
afx_msg void modelessButtonClick();
afx_msg void modalButtonClick();
DECLARE_MESSAGE_MAP()
CButton Button;
afx_msg void OnPaint();
COLORREF wcolor;
};
BOOL CSimpleApp::InitInstance(){
m_pMainWnd = new CMainFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
return true;
}
CMainFrame::CMainFrame()
{
Create(NULL, "MFC Colour dialog",WS_OVERLAPPEDWINDOW ,CRect(25,25,410,200));
Button.Create ("Colour dialog",BS_DEFPUSHBUTTON| WS_CHILD | WS_VISIBLE , CRect(12,12,150,62), this,BUTTON);
wcolor=RGB(255,255,255);
}
BEGIN_MESSAGE_MAP(CMainFrame,CFrameWnd)
ON_BN_CLICKED(BUTTON,modelessButtonClick)
ON_WM_PAINT()
END_MESSAGE_MAP()
CSimpleApp MFCApp1;
//selects modeless dialog when button clicked
afx_msg void CMainFrame::modelessButtonClick()
{
CColorDialog Tmp( 0, CC_ANYCOLOR | CC_RGBINIT, this );
if( Tmp.DoModal() == IDOK )
{
CString Msg;
Msg.Format( "You selected color %d", Tmp.GetColor() );
wcolor = Tmp.GetColor();
Invalidate();
}
}
afx_msg void CMainFrame::OnPaint()
{
CPaintDC paintDC(this);
CRect rect;
GetClientRect(&rect);
paintDC.FillSolidRect(&rect,wcolor);
}