We help IT Professionals succeed at work.

CPaintDC VC++

viswanathat
viswanathat asked
on
Hi

I want to partially paint On a third party spread sheet control cell . For this,  the control gives API to get the current cell's Rect Value. If I paint on this it is not paining..

-- code  --------------
CWnd* wnds;
wnds =  GetDlgItem(IDC_TEST);
CPaintDC dc(wnds);

CRECT lpRect;
BOOL b = VarList.MLGetCellRect(hwnd, 1,1,&lpRect);
lpRect.Right  -= 10;

CBrush *cbr = new CBrush;
cbr->CreateSolidBrush(RGB(0,0,0));

dc.FillRect(lpRect,cbr);

------------------------------
Even for a edit box in a  dialog box we are not able to paint by  getting its coordinates in CRect.

But if we create one new Window (using CWnd::Create function) on the dialog and paint on the window it is allowing me to paint..

What can be done to draw on prebuilt controls..?

Regards

Viswanath AT.

 
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Hi viswanathat,

try it without using CPaintDC ... CPaintDC is especially designed to handle painting
required through a WM_PAINT message (so it includes calls to BeginPaint, EndPaint
and even sets clipping region to invalidate region of the window).

Try it simply like this:

CWnd* wnds;
wnds =  GetDlgItem(IDC_TEST);
CDC* pDC = wnds->GetDC();

// do the paint here with pDC
...

// cleanup
wnds->ReleaseDC( pDC );


hope that helps,

ZOPPO
CERTIFIED EXPERT
Commented:
BTW, 10 points is not much if 50 points should be offered for easy questions...

Author

Commented:
It has solved the problem..

I have also increased the points to 50

Tanx a lot..

Regards..

Viswanath AT.
CERTIFIED EXPERT

Commented:
You're welcome,

have a nice day,

regards,

ZOPPO

Explore More ContentExplore courses, solutions, and other research materials related to this topic.