I had the code before, but I somehow lost it. How do I use TextOut?
I had the code before, but I somehow lost it. How do I use TextOut?
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
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
TNT
You Can Stop Me, But You Cant Stop Us All
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
1978 Silver Anniversary Corvette
Well, I tried:
HDC hdc;
TextOut(hdc,10,10,"Hi",2);
but no text shows up.
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
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.
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
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
1978 Silver Anniversary Corvette
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!
>
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
1978 Silver Anniversary Corvette
KEN, am I on the right track? After all, I'm really new to Windows programming. Thanks.
--Garfield
1978 Silver Anniversary Corvette
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)
1978 Silver Anniversary Corvette
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 |
| | |
| | |
------------------------------------------------------
Last edited by -KEN-; 11-02-2001 at 05:00 PM.
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
1978 Silver Anniversary Corvette
whoo. I got my graph working right...