Re: problem in using CPaintDC
 
Scott McPhillips [MVP] wrote:
bruceminoo@hotmail.com wrote:
I think I have impliemented your suggestions but I cant trigger an
invalidate
You can see the different attempts that I have made
Can you please advise what I have done wrong
thanks
Bruce
Your code is good but...OnPaint is a message hander for the WM_PAINT
message.  You need to add this:
    ON_WM_PAINT()
in your message map to direct the message to your OnPaint function.
--
Scott McPhillips [VC++ MVP]
Thanks Scott
&Thanks everybody
for the record the final code looked like
Now to do something useful with it
regards
Bruce
//win32 app
// needs multi threading
#include <afxwin.h>
class A_Std_Window :public CFrameWnd
{
    CPoint m_StartPoint, m_EndPoint;
    public:
    A_Std_Window()
    {
         Create(NULL,"put window title here");
    }
    void OnLButtonUp(UINT,CPoint);
    void OnPaint();
    DECLARE_MESSAGE_MAP()
};
void A_Std_Window::OnPaint()
{
    CPaintDC dc(this);	//paint here
    dc.MoveTo(m_StartPoint);
    dc.LineTo(m_EndPoint);
    dc.FillSolidRect(0,0,40,40, RGB(255,0,0));
    CRect rect;          // Create a CRect object
    GetClientRect(rect); // Retrieve the view's rectangle into the rect
object
    dc.DrawText(_T("hello"), rect, DT_CENTER | DT_VCENTER |
DT_SINGLELINE);
}
BEGIN_MESSAGE_MAP( A_Std_Window, CFrameWnd)
    ON_WM_LBUTTONUP() //Macro to map the left button click to the
handler
    ON_WM_PAINT() //Macro to map the left button click to the handler
END_MESSAGE_MAP()
void A_Std_Window::OnLButtonUp(UINT flags,CPoint location)
{
    m_StartPoint.x=80;
    m_StartPoint.y=150;
 	m_EndPoint.x=4;
    m_EndPoint.y=5;
    Invalidate();
    UpdateWindow();		// force act on message
}
class MyApp :public CWinApp
{
     A_Std_Window *windo;			// create a window pointer
     public:
     BOOL InitInstance()
     {
           windo = new A_Std_Window();
           m_pMainWnd = windo;
           m_pMainWnd->ShowWindow(1);
           m_pMainWnd->UpdateWindow();
           return 1;
      } 
     	
};
MyApp theApp;