•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 422,380 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,683 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Put the following code in a C++ Header File.
The following function is to make it way more easier to draw text onto the client area of a window.
Now the only thing you need to do is include the C++ Header file containing this function into any C++ Source file and use the following code to dynamically write text onto the screen:
70 and 50 are the values of the X and Y coordinates of the position to drawm the text in.
Tell me if this way is obsolete, returns errors, or in any other way is not a good thing to use.
Tell me if this helps.
The following function is to make it way more easier to draw text onto the client area of a window.
Now the only thing you need to do is include the C++ Header file containing this function into any C++ Source file and use the following code to dynamically write text onto the screen:
DoText(hwnd, 70, 50, "This is my text!!!");
70 and 50 are the values of the X and Y coordinates of the position to drawm the text in.
Tell me if this way is obsolete, returns errors, or in any other way is not a good thing to use.
Tell me if this helps.
void DoText(HWND hwnd, int x, int y, LPSTR text) { HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hwnd, &ps); TextOut(hdc, x, y, text, strlen(text)); EndPaint(hwnd, &ps); }
Comments (Newest First)
killdude69 | Newbie Poster | Jul 15th, 2008
williamhemsworth | Posting Pro in Training | Jul 14th, 2008
•
•
•
•
No thanks.. that way is very in-efficient, and doesn't give you the options of text size, font, colour and many other styles. Also, say you want to write 100 lines using that function, you would have constructed 200 un-needed variables and made 200 un-needed function calls.
What I would use is something more like:
Even though this may be slightly slower in some cases, it offers many more options and is worth it in the end. But to be honest I think I would just do it all manually to save time and problems
What I would use is something more like:
CPP Syntax (Toggle Plain Text)
static COLORREF oldTextRGB = 0, oldBackRGB = 0xFFFFFF; void Write(HDC hdc, int x, int y, char *text, /* Optional params */ COLORREF txtRGB = oldTextRGB, COLORREF backRGB = oldBackRGB, HFONT font = NULL) { if (font) SelectObject(hdc, font); if (txtRGB != oldTextRGB) { SetTextColor(hdc, txtRGB); oldTextRGB = txtRGB; } if (backRGB != oldBackRGB) { SetBkColor(hdc, backRGB); oldBackRGB = backRGB; } TextOut(hdc, x, y, text, strlen(text)); }
Even though this may be slightly slower in some cases, it offers many more options and is worth it in the end. But to be honest I think I would just do it all manually to save time and problems
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)