How to get the pixel color from a virtual device context ?
-
I want to get some gdi elements color infomation. when I used TextOut function to draw the strings in the device context.but I doesn't want to output the strings in a really device context in the program's window. so I found this way :
#include
#pragma comment(lib,"user32.lib")
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int cmdShow)
{
// create a virtual dc to draw elements.
HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
HDC hdcCompatible = CreateCompatibleDC(hdcScreen);
CString m_strText = _T("Hello");
SIZE m_sz;if(hdcCompatible == NULL) { MessageBox(NULL,\_T("CreateCompatibleDC Failed !"),NULL,NULL); return -1; } // then set the text color is black,the back color is white. SetBkColor(hdcCompatible,RGB(255,255,255)); SetTextColor(hdcCompatible,RGB(0,0,0)); // draw the text int a virtual dc. TextOut(hdcCompatible,0,0,m\_strText,m\_strText.GetLength()); // get the text width and height. GetTextExtentPoint32(hdcCompatible,m\_strText,m\_strText.GetLength(),&m\_sz); // get the pixel infomation. for(int i=0; i
the m_sz value is normal ( 8 * 16),but the color variables is invalied, because is usually is the backcolor.
( I doesn't want to draw it in the program windows and then call GetPixel function from screen,that's not so good ! :) )
why is it ,or is there any other way ?
Thans for your reply !
Best regards !
-
I want to get some gdi elements color infomation. when I used TextOut function to draw the strings in the device context.but I doesn't want to output the strings in a really device context in the program's window. so I found this way :
#include
#pragma comment(lib,"user32.lib")
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int cmdShow)
{
// create a virtual dc to draw elements.
HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
HDC hdcCompatible = CreateCompatibleDC(hdcScreen);
CString m_strText = _T("Hello");
SIZE m_sz;if(hdcCompatible == NULL) { MessageBox(NULL,\_T("CreateCompatibleDC Failed !"),NULL,NULL); return -1; } // then set the text color is black,the back color is white. SetBkColor(hdcCompatible,RGB(255,255,255)); SetTextColor(hdcCompatible,RGB(0,0,0)); // draw the text int a virtual dc. TextOut(hdcCompatible,0,0,m\_strText,m\_strText.GetLength()); // get the text width and height. GetTextExtentPoint32(hdcCompatible,m\_strText,m\_strText.GetLength(),&m\_sz); // get the pixel infomation. for(int i=0; i
the m_sz value is normal ( 8 * 16),but the color variables is invalied, because is usually is the backcolor.
( I doesn't want to draw it in the program windows and then call GetPixel function from screen,that's not so good ! :) )
why is it ,or is there any other way ?
Thans for your reply !
Best regards !