Why my program cannot show colour?
-
My code : CPen penObject; penObject.CreatePen(PS_SOLID, 4, RGB(255,0,0)); CDCPoint->SelectObject(&penObject); CDCPoint->MoveTo(100,100); CDCPoint->LineTo(100,200); Why the line is in colour BLACK instead of RED?????? Also, when i put: CDCPoint->MoveTo(100,100); CDCPoint->LineTo(100,100); It cannot print a dot. It prints nothing.....do you know why???? :eek:
-
My code : CPen penObject; penObject.CreatePen(PS_SOLID, 4, RGB(255,0,0)); CDCPoint->SelectObject(&penObject); CDCPoint->MoveTo(100,100); CDCPoint->LineTo(100,200); Why the line is in colour BLACK instead of RED?????? Also, when i put: CDCPoint->MoveTo(100,100); CDCPoint->LineTo(100,100); It cannot print a dot. It prints nothing.....do you know why???? :eek:
Where does CDCPoint come from? If you're playing with memory device contexts, and your line is black instead of red, you've probably screwed calling CreateCompatibleBitmap. Does your code look like this? CDC CDCPoint; CDCPoint.CreateCompatibleDC(pSomeOtherDC); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&CDCPoint, cx, cy); CDCPoint.SelectObject(&bitmap); If yes, you need need to change first argument in CreateCompatibleBitmap from &CDCPoint to pSomeOtherDC. Currently, your bitmap is monochrome and red pen draws a black line. Use MoveTo(100, 100) and LineTo(100, 101) to display a pixel. Better yet, call SetPixel(100, 100, RGB(...)); Tomasz Sowinski -- http://www.shooltz.com.pl
-
Where does CDCPoint come from? If you're playing with memory device contexts, and your line is black instead of red, you've probably screwed calling CreateCompatibleBitmap. Does your code look like this? CDC CDCPoint; CDCPoint.CreateCompatibleDC(pSomeOtherDC); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&CDCPoint, cx, cy); CDCPoint.SelectObject(&bitmap); If yes, you need need to change first argument in CreateCompatibleBitmap from &CDCPoint to pSomeOtherDC. Currently, your bitmap is monochrome and red pen draws a black line. Use MoveTo(100, 100) and LineTo(100, 101) to display a pixel. Better yet, call SetPixel(100, 100, RGB(...)); Tomasz Sowinski -- http://www.shooltz.com.pl
My program doesn't have CreatCompatibleBitmap...something liked that.....i just have in OnDraw(CDC* pDC): if(CDCPoint==NULL) { CDCPoint=new CDC; } CDCPoint->m_hDC=pDC->m_hDC; CDCPoint->m_hAttribDC=pDC->m_hAttribDC; //creating a global window handler to help with output Handler=m_hWnd; //setting background mode so there wouldn't be a border around text (just in case) pDC->SetBkMode(TRANSPARENT); //setting fixed width font CFont newFont; newFont.CreateFont(18, 9, 0, 0, FW_REGULAR, 0, 0, 0, ANSI_CHARSET, OUT_DEVICE_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN, "Courier New"); pDC->SelectObject(&newFont); Also, I found that there is another problem........normally the output font is Courier New....but suddently....all fonts change to another one....including all message box. Thanks for your help anyway... :) :)
-
My program doesn't have CreatCompatibleBitmap...something liked that.....i just have in OnDraw(CDC* pDC): if(CDCPoint==NULL) { CDCPoint=new CDC; } CDCPoint->m_hDC=pDC->m_hDC; CDCPoint->m_hAttribDC=pDC->m_hAttribDC; //creating a global window handler to help with output Handler=m_hWnd; //setting background mode so there wouldn't be a border around text (just in case) pDC->SetBkMode(TRANSPARENT); //setting fixed width font CFont newFont; newFont.CreateFont(18, 9, 0, 0, FW_REGULAR, 0, 0, 0, ANSI_CHARSET, OUT_DEVICE_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN, "Courier New"); pDC->SelectObject(&newFont); Also, I found that there is another problem........normally the output font is Courier New....but suddently....all fonts change to another one....including all message box. Thanks for your help anyway... :) :)
So what's the point of having CDCPoint variable? Isn't pDC enough? Tomasz Sowinski -- http://www.shooltz.com.pl
-
So what's the point of having CDCPoint variable? Isn't pDC enough? Tomasz Sowinski -- http://www.shooltz.com.pl
CDC* CDCPoint is a global variable for another files in the project. But pDC is just using in OnDraw(). Therefore, CDCPoint and pDC are the same but used in different area.
-
CDC* CDCPoint is a global variable for another files in the project. But pDC is just using in OnDraw(). Therefore, CDCPoint and pDC are the same but used in different area.
You shouldn't to copy HDC handles from pDC passed OnDraw to your global variable. They'll become invalid soon after OnDraw returns, b/c pDC will be released and your CDCPoint will be useless. Just perform your drawing using pDC. If using pDC instead of CDCPoint doesn't produce expected results, post your OnDraw handler code. Tomasz Sowinski -- http://www.shooltz.com.pl