(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
06-12-24 03:17 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - Various text drawing methods are ignoring font colour New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6324 days
Last view: 6324 days
Posted on 11-07-06 03:50 AM Link | Quote
Originally posted by MS Documentation
The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color.

Or not. TextOut, ExtTextOut, DrawText, etc, they all seem to ignore the text and background colour for the most part and just choose arbitrary colours. Generally black on white, but if I set the background to dark blue (0, 0, 127) it becomes white on black. Tried setting a font, pen colour, brush colour etc, nothing works.

//Some global variables
HDC WindowBackDC = NULL, WindowDC = NULL;
HBITMAP WindowBMP = NULL, OldWindowBMP = NULL;
RECT TextRect;
HFONT hFont = NULL, hOldFont = NULL;

LRESULT CALLBACK ProcMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
char S1[] = "I'm testing";
char S2[] = "Hey another test";
SIZE Size;

switch(msg)
{
case WM_CREATE:
WindowBackDC = CreateCompatibleDC(0);
WindowBMP = CreateCompatibleBitmap(WindowBackDC, WindowWidth, WindowHeight);
OldWindowBMP = SelectObject(WindowBackDC, WindowBMP);
if(!WindowBackDC || !WindowBMP || !OldWindowBMP)
DebugOut(DO_NONE, "Failed to create graphic buffer (%08X, %08X, %08X)\n", WindowBackDC, WindowBMP, OldWindowBMP);
WindowDC = GetDC(hWindow);

hFont = CreateFont(0, 0, 0, 0, 0, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "terminal");
hOldFont = SelectObject(WindowBackDC, hFont);

//SetBkMode(WindowBackDC, TRANSPARENT);
break;


case WM_LBUTTONDOWN:
TextRect.top = 5;
TextRect.left = 20;
TextRect.bottom = 20;
TextRect.right = 100;

GetTextExtentPoint32(WindowBackDC, S1, sizeof(S1), &Size);

//if(SetTextColor(WindowBackDC, RGB(0, 255, 0)) == CLR_INVALID)
// DebugOut(DO_MINOR, "Failed to set text colour\n");

//SetBkColor(WindowBackDC, RGB(0, 0, 127));
SetDCPenColor(WindowBackDC, RGB(0, 255, 0));
SetDCBrushColor(WindowBackDC, RGB(255, 0, 0));


//DrawText(WindowBackDC, S1, sizeof(S1), &TextRect, DT_LEFT | DT_CALCRECT | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS);
//DrawText(WindowBackDC, S1, sizeof(S1), &TextRect, DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS);
TextOut(WindowBackDC, TextRect.left, TextRect.top, S1, sizeof(S1));

//TextRect.top += (TextRect.bottom - TextRect.top);
TextRect.top += Size.cy;
TextRect.bottom += Size.cy;

//DrawText(WindowBackDC, S2, sizeof(S2), &TextRect, DT_LEFT | DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS);
TextOut(WindowBackDC, TextRect.left, TextRect.top, S2, sizeof(S2));
BitBlt(WindowDC, 0, 0, WindowWidth, WindowHeight, WindowBackDC, 0, 0, SRCCOPY);

//Window_Redraw(hWindow);
break;


case WM_RBUTTONDOWN:
ProgramRunning = false;
break;


case WM_CLOSE:
ProgramRunning = false;
break;


default:
return DefWindowProc(hWnd, msg, wParam, lParam);
break;
}
}


You can see I've tried pretty much every method to no avail. I can set the text colour and read it back again, but the text drawing routines simply ignore it.
sloat



 





Since: 11-18-05
From: Delaware, US

Last post: 6427 days
Last view: 6427 days
Posted on 11-07-06 12:15 PM Link | Quote
Originally posted by HyperHacker

WindowBackDC = CreateCompatibleDC(0);
WindowBMP = CreateCompatibleBitmap(WindowBackDC, WindowWidth, WindowHeight);


I'm pretty sure this is the issue. You should get the DC of the current window (from the hWnd param) and use that to create both the memory DC and Bitmap.

Originally posted by Buried in MSDN

Note: When a memory device context is created, it initially has a 1-by-1 monochrome bitmap selected into it. If this memory device context is used in CreateCompatibleBitmap, the bitmap that is created is a monochrome bitmap.

HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6324 days
Last view: 6324 days
Posted on 11-08-06 05:42 AM Link | Quote
Ah, thanks. Using the window's DC in both CreateCompatibleDC and CreateCompatibleBitmap did it. I thought it might have been monochrome but I could swear I've done the same before and it worked.

Anyway since I'm here, is there a way to disable the mouse entirely? I'd use BlockInput() but that disables the keyboard too and it becomes enabled again when the program closes. I want to write a program that just prevents any program from responding to the mouse, even after it's closed, until it's run again to re-enable it. Reason being I like to use my computer as an alarm clock, so I'd like to just turn the monitor off through software when I set the alarm and have it come back on when the alarm goes off or when I press a key. I can do that but my mouse likes to randomly send "wheel scrolled" messages when it's just sitting there, turning the monitor back on in the middle of the night.
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - Various text drawing methods are ignoring font colour |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.011 seconds; used 367.55 kB (max 434.30 kB)