-
March 18th, 2009, 06:34 AM
#1
How to paint color Text on background DC
I want to draw text or image on background DC, so i write code as below. But the output text is also mono. why and how to modify my program. Thanks a lot.
g_PCanvas.cdc = new CDC;
g_PCanvas.cdc->CreateCompatibleDC(NULL);
g_PCanvas.hDC = g_PCanvas.cdc->Detach();
g_PCanvas.hBitmap = CreateCompatibleBitmap(g_PCanvas.hDC, EVOLIS_MAX_WIDTH, EVOLIS_MAX_HEIGHT);
SelectObject(g_PCanvas.hDC, g_PCanvas.hBitmap);
...
...
SetTextColor(hDc, RGB(0xff,0,0xff);
retval = ExtTextOutA(hDc, x, y, ETO_CLIPPED, &rc, szText, strlen(szText), NULL);
..
best regard.
-
March 18th, 2009, 06:40 AM
#2
Re: How to paint color Text on background DC
Hi!
Try
GetDC(NULL); // this DC will draw to the entire screen
or
CPaintDC(this); // this == a CWnd derived class
or
CClientDC(this);
and I also wonder what is the purpose of this line:
g_PCanvas.hDC = g_PCanvas.cdc->Detach();
Last edited by zerver; March 18th, 2009 at 06:43 AM.
Nobody cares how it works as long as it works
-
March 18th, 2009, 07:06 AM
#3
Re: How to paint color Text on background DC
Are you painting in the OnPaint or OnDraw function ?
-
March 18th, 2009, 07:55 PM
#4
Re: How to paint color Text on background DC
Thanks for your reply,
I want to write a indepandent DLL API but under OnDraw or OnPaint .
Below is my program source. I define SHOW_WND is available, but this window will splash on screen.
PAINT_CANVAS g_PCanvas;
DWORD CreateCanvas()
{
HINSTANCE hInst = AfxGetInstanceHandle();
g_PCanvas.rc.left=g_PCanvas.rc.top=0;
g_PCanvas.rc.right = EVOLIS_MAX_WIDTH;
g_PCanvas.rc.bottom = EVOLIS_MAX_HEIGHT;
#ifdef SHOW_WND
g_PCanvas.hWnd = uniCreateWindow(hInst, g_PCanvas.rc); // will create a window by another function
g_PCanvas.cWnd.Attach(g_PCanvas.hWnd);
g_PCanvas.cdc = g_PCanvas.cWnd.GetDC();
g_PCanvas.hDC = g_PCanvas.cdc->Detach();
#else // only mono available, why?
// g_PCanvas.hbmColor = CreateBitmap(EVOLIS_MAX_WIDTH, EVOLIS_MAX_HEIGHT, 1, 24, NULL);
g_PCanvas.cdc = new CDC;
g_PCanvas.cdc->CreateCompatibleDC(NULL);
g_PCanvas.hDC = g_PCanvas.cdc->Detach();
g_PCanvas.hBitmap = CreateCompatibleBitmap(g_PCanvas.hDC, EVOLIS_MAX_WIDTH, EVOLIS_MAX_HEIGHT);
SelectObject(g_PCanvas.hDC, g_PCanvas.hBitmap);
#endif
g_PCanvas.hBrush = CreateSolidBrush(RGB(0xff,0xff,0xff));
SelectObject(g_PCanvas.hDC, g_PCanvas.hBrush);
FillRect(g_PCanvas.hDC, &g_PCanvas.rc, g_PCanvas.hBrush);
DeleteObject(g_PCanvas.hBrush);
g_PCanvas.cdc->Attach(g_PCanvas.hDC);
return 0;
}
typedef struct _PAINT_CANVAS
{
RECT rc;
CWnd cWnd;
HWND hWnd;
CDC *cdc;
HDC hDC;
HBRUSH hBrush;
HBITMAP hBitmap, hbmColor, hbmColorOld;
DWORD dwPartial;
DWORD dwStartLine; // partial printing
DWORD dwAreaWidth; // partial printing
DWORD dwColorSmooth; // bit 5 / 6 / 7
} PAINT_CANVAS;
Last edited by uni8931; March 18th, 2009 at 08:03 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|