I had the code before, but I somehow lost it. How do I use TextOut?
Printable View
I had the code before, but I somehow lost it. How do I use TextOut?
Hi,
BOOL TextOut(
HDC hdc, // handle to device context
int nXStart, // x-coordinate of starting position
int nYStart, // y-coordinate of starting position
LPCTSTR lpString, // pointer to string
int cbString // number of characters in string
);
Eg:
TextOut(hdc, 10, 10, "Printing Text", 13);
Hope That Helps...
Cheers
TNT
Arg!!! You got to it before me TNT. I'm new to Windows programming (1 week to be exact) and I actaully had the answer to it. Oh well, at least I know I know it.
WINDOWS PROGRAMMING IS GREAT!!!
--Garfield
Well, I tried:
HDC hdc;
TextOut(hdc,10,10,"Hi",2);
but no text shows up.
forgot to assign hdc to something
hdc = GetDC(hwnd);
I tried:
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc,10,10,"Hi",2);
but it didn't show up.
KEN is right, you forgot to assign the HDC to something. You could do what KEN said:
[code]
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc, 10, 10, TEXT("TEST"), 4);
ReleaseDC(hwnd, hdc); // don't forget to release the HDC
[code]
Or you could use another set of functions known as BeginPaint and EndPaint:
So, there are a couple of ways. You would normally use BeginPaint and EndPaint inside the WM_PAINT message. And then GetDC and ReleaseDC outside of it.Code:case WM_PAINT:
hdc = BeginPaint(hwnd, &ps); // where ps is defined PAINTSTRUCT
TextOut(hdc, 10, 10, TEXT("TEST"), 4);
EndPaint(hwnd, &ps);
return 0;
--Garfield
How's that for just one week of learning Windows Programming :D
then try...
PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint(hwnd, &ps);
TextOut(hdc,10,10,"Hi",2);
EndPaint(hwnd, &ps);
Ack! Garfield beat me to it while I was replying...damn you, garfield! :p
>
I tried:
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc,10,10,"Hi",2);
but it didn't show up.
<
Maybe you need to release the HDC (ReleaseDC(hwnd)). I don't know if that's the problem though. By the way, I'll have to check the parameters for ReleaseDC, it doesn't look right.
--Garfield
KEN, am I on the right track? After all, I'm really new to Windows programming. Thanks.
--Garfield
sure, but I dunno if releasing the DC would do much to stop the text from showing up...
Yeh, I didn't think it would cause the text not to appear. Maybe it is the rest of his code. And, KEN, do I have the parameters right for ReleaseDC? Thanks.
--Garfield
(Wow, 10 posts in 9 minutes. That has to be a record)
Oh, and garfield I can't send large PMs, so in response to you PM...
Here's how I want you to think of a message from now on (and if you look at the struct MSG I'm not far off)
Windows Messages:
Kinda gettin the picture? Every time a message is sent to windows, the WPARAM is to the main window, and LPARAM is a message to any child window, etc. The Hiword and loword contain additional data such as coordinates.PHP Code:
WPARAM LPARAM
------------------------------------------------------
| | |
| | |
| HIWORD | HIWORD |
| | |
| | |
| ---------------------------------------------------|
| | |
| | |
| | |
| LOWORD | LOWORD |
| | |
| | |
------------------------------------------------------
Okay, so LPARAM and WPARAM are just additional information of the MSG? And HIWORD and LOWARD are different ways to get at the different information? Thanks. I guess I understand.
--Garfield
whoo. I got my graph working right...