Hi,
It took a while to sort things out but I have finally cracked it.
Based on the info I got from nv3 and Espen Harlin and a very instructive video I found
http://msdn.microsoft.com/en-us/vstudio/cc843613 I introduced a custom dialog control Called CGraph based on class Cwnd and integrated it into my dialog box application.
Integrating it into the dialog box is ultimately dead easy once you know how. Simply adding a custom control to the dialog and specify its class to be "GraphClass" (see c++ code) does the trick.
It works very well now and does everything I want and expect it to do.
In reality its just another case of "Glaringly obvious once pointed out".
What really tricked me is that when the dialog box initialises windows is capable of and does work on the basis of the dialog box's main WM_PAINT message and subsequent OnPaint() function, it just never repeats it afterwards.
The result was that I did get the expected graph, the code faithfully executed again without any error but it did no more redraw.
Thanks for all the help.
This is the header file for the new class:
#pragma once
#include "ToolBox.h"
#include "Data.h"
class CGraph : public CWnd
{
DECLARE_DYNAMIC(CGraph)
public:
CGraph();
virtual ~CGraph();
CWorkData workData;
protected:
BOOL CGraph::RegisterWndClass();
static TCHAR m_szWndClass[];
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
private:
void ShowGraph(void);
int m_iCount;
};
This is the bit of c++ code that handles it:
#include "stdafx.h"
#include "Eerste.h"
#include "Graph.h"
IMPLEMENT_DYNAMIC(CGraph, CWnd)
TCHAR CGraph::m_szWndClass[] = _T("GraphClass");
BEGIN_MESSAGE_MAP(CGraph, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
CGraph::CGraph()
{
RegisterWndClass();
m_iCount = 0;
}
CGraph::~CGraph()
{
}
BOOL CGraph::RegisterWndClass()
{
WNDCLASS wndclass;
if (::GetClassInfo(AfxGetInstanceHandle(),m_szWndClass, &wndclass))
return TRUE;
wndclass.style = 0;
wndclass.lpfnWndProc = ::DefWindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = ::AfxGetInstanceHandle();
wndclass.hIcon = NULL;
wndclass.hCursor = NULL;
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = m_szWndClass;
return::AfxRegisterClass(&wndclass);
}
void CGraph::OnPaint()
{
ShowGraph();
CWnd::OnPaint();
int fdtest =1;
}
void CGraph::ShowGraph(void)
{
RECT rect;
GetClientRect(&rect);
CPaintDC dc (this);
dc.SetWindowExt(rect.left,rect.bottom);
CPen lpen(PS_SOLID, 1, RGB(255, 0, 0));
dc.SelectObject(&lpen);
m_iCount +=10;
dc.LineTo(100,m_iCount);
}