Click here to Skip to main content
15,901,205 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Solving a repaint problem in VS2005 Pin
SimplCodr22-Oct-09 11:25
SimplCodr22-Oct-09 11:25 
GeneralRe: Solving a repaint problem in VS2005 Pin
CPallini22-Oct-09 12:02
mveCPallini22-Oct-09 12:02 
GeneralRe: Solving a repaint problem in VS2005 Pin
SimplCodr22-Oct-09 12:20
SimplCodr22-Oct-09 12:20 
GeneralRe: Solving a repaint problem in VS2005 Pin
CPallini22-Oct-09 20:38
mveCPallini22-Oct-09 20:38 
QuestionRe: Solving a repaint problem in VS2005 Pin
SimplCodr23-Oct-09 3:51
SimplCodr23-Oct-09 3:51 
AnswerRe: Solving a repaint problem in VS2005 Pin
SimplCodr22-Oct-09 11:32
SimplCodr22-Oct-09 11:32 
GeneralRe: Solving a repaint problem in VS2005 Pin
theCPkid22-Oct-09 16:57
theCPkid22-Oct-09 16:57 
AnswerRe: Solving a repaint problem in VS2005 Pin
SimplCodr23-Oct-09 4:05
SimplCodr23-Oct-09 4:05 
Maybe you didn't get my phsyco babble but the previous code works perfectly as long the application is created manually using the method shown. The only portion of code that I'm trying to use is the code under "Virtual Window Stuff" the Create function in that is working fine if not I wouldn't get a window.

My problem is with App-Wizard generated MFC single document application. However I have a kind-of-solution but for what ever reason the background of the view goes black so I have to change the text color and text background. Not quite what I'm after yet.
Check out the code below it works quite well.

I think this is how it works;

A bitmsap is created to hold the content of the device context.
draw stuff is added to the bitmap in memory then pasted to the view when I call ShowIt().

I had to use a message handler or other function to create the "virtual window" (memory DC). The problem is It doesn't stick around like this I have try and keep everything in the bitmap and recreate the memory DC each time before I draw.

Source File Stuff

void Ccom_testView::OnLButtonDblClk(UINT nFlags, CPoint point)
{

	// Get the extents of the screen
	maxX = GetSystemMetrics(SM_CXSCREEN);
	maxY = GetSystemMetrics(SM_CYSCREEN);

	CClientDC dc(this);
	memDC.CreateCompatibleDC(&dc);

	if (m_bmp.m_hObject == NULL)
		m_bmp.CreateCompatibleBitmap(&dc, maxX, maxY);

	memDC.SelectObject(&m_bmp);


	// This does not do what it should. Expect a white background.
	// Program Still starts with a black background
	bkBrush.CreateStockObject(WHITE_BRUSH);
	memDC.SelectObject(&bkBrush);

	CBitmap* pOldBitmap = memDC.SelectObject(&m_bmp);
	CBrush* pOldbkBrush = memDC.SelectObject(&bkBrush);
	
	// Had to set text color manually
	memDC.SetTextColor(RGB(0, 200, 100));
	memDC.SetBkColor(RGB(0,0,0));	

	wsprintf(str, "Hello World");
	memDC.TextOutA(point.x, point.y, str, strlen(str));

	memDC.SelectObject(pOldbkBrush);

	memDC.SelectObject(pOldBitmap);
	memDC.DeleteDC();

	ShowIt();

	CView::OnLButtonDblClk(nFlags, point);
}

void Ccom_testView::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	ShowIt();
	
	//	dc.BitBlt(0, 0, maxX, maxY, &memDC, 0, 0, SRCCOPY);
	// Do not call CView::OnPaint() for painting messages
}

bool Ccom_testView::ShowIt(void)
{
//	CDC memDC;
	CClientDC dc(this);
	CBitmap* pbmOld = NULL;

	memDC.CreateCompatibleDC(&dc);
	pbmOld = memDC.SelectObject(&m_bmp);
	
	dc.BitBlt(0, 0, maxX, maxY, &memDC, 0, 0, SRCCOPY);

	memDC.SelectObject(pbmOld);
	memDC.DeleteDC();
	
	return false;
}


Header File Stuff

class Ccom_testView : public CView
{
public:
	CDC memDC;
	CBrush bkBrush;
	CBitmap m_bmp;
	CFont m_SystemFont, m_AnsiVarFont;

protected: // create from serialization only
	Ccom_testView();
	DECLARE_DYNCREATE(Ccom_testView)

// Attributes
public:
	Ccom_testDoc* GetDocument() const;

// Operations
public:

// Overrides
public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);

// Implementation
public:
	virtual ~Ccom_testView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
public:
	afx_msg void OnPaint();
public:
	bool ShowIt(void);
};


Comments or suggestions would be great. Even better yet a better way to do it.

Thank you for your help.
GeneralRe: Solving a repaint problem in VS2005 Pin
theCPkid23-Oct-09 5:07
theCPkid23-Oct-09 5:07 
GeneralRe: Solving a repaint problem in VS2005 Pin
SimplCodr23-Oct-09 5:49
SimplCodr23-Oct-09 5:49 
GeneralRe: Solving a repaint problem in VS2005 Pin
CPallini23-Oct-09 5:41
mveCPallini23-Oct-09 5:41 
GeneralRe: Solving a repaint problem in VS2005 Pin
SimplCodr23-Oct-09 6:03
SimplCodr23-Oct-09 6:03 
QuestionRe: Solving a repaint problem in VS2005 Pin
SimplCodr23-Oct-09 8:21
SimplCodr23-Oct-09 8:21 
AnswerRe: Solving a repaint problem in VS2005 Pin
CPallini23-Oct-09 10:05
mveCPallini23-Oct-09 10:05 
GeneralRe: Solving a repaint problem in VS2005 Pin
SimplCodr23-Oct-09 10:29
SimplCodr23-Oct-09 10:29 
GeneralRe: Solving a repaint problem in VS2005 Pin
CPallini23-Oct-09 10:50
mveCPallini23-Oct-09 10:50 
GeneralRe: Solving a repaint problem in VS2005 Pin
theCPkid23-Oct-09 19:00
theCPkid23-Oct-09 19:00 
GeneralRe: Solving a repaint problem in VS2005 Pin
SimplCodr24-Oct-09 5:12
SimplCodr24-Oct-09 5:12 
QuestionConvert BYTE* array (unmanaged) to SAFEARRAY Pin
TalSt22-Oct-09 6:13
TalSt22-Oct-09 6:13 
QuestionRe: Convert BYTE* array (unmanaged) to SAFEARRAY Pin
CPallini22-Oct-09 8:20
mveCPallini22-Oct-09 8:20 
AnswerRe: Convert BYTE* array (unmanaged) to SAFEARRAY Pin
Randor 22-Oct-09 16:13
professional Randor 22-Oct-09 16:13 
GeneralRe: Convert BYTE* array (unmanaged) to SAFEARRAY Pin
TalSt24-Oct-09 19:50
TalSt24-Oct-09 19:50 
GeneralRe: Convert BYTE* array (unmanaged) to SAFEARRAY Pin
Randor 26-Oct-09 9:59
professional Randor 26-Oct-09 9:59 
QuestionHow to read the characters in the EditTable of SysListView32 style control ? Pin
wangningyu22-Oct-09 5:41
wangningyu22-Oct-09 5:41 
QuestionRe: How to read the characters in the EditTable of SysListView32 style control ? Pin
David Crow22-Oct-09 6:23
David Crow22-Oct-09 6:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.