Originally Posted by
novacain
Code:
size_t sz;
TextOut(hdc, PosX, PosY * dwCharY, ch, 1);
GetTextExtentPoint32(hdc, ch, 1, &sz); //you know the number of chars in the string
PosX += sz.cx;
or use lstrlen() to find the string length.
Also look at DrawText() and CALC_RECT
(first call to find out the rect req and then call again to write the text, using the rect to position correctly).
I tried using DrawText in my example program. Basically what I'm aiming at is a program that will let me output text to a window the same way I can with the console (ie text that will just go to the next line when it reaches the edge of the window etc.). I tried using DrawText in the following way, but it didn't work. It just drew a single, weird looking character in the rectangle. Again, I tried to base it on stuff from msdn. Do you know why it doesn't work?
Also, I looked up CALC_RECT but couldn't find anything other than something this guy wrote for his own program:
Problem with function - C++ Forums
Anyway thanks again for the help, and here's my current code:
Code:
static char ch[2]; // current character
static char output_line[500];
static PTCHAR pchOutputBuf; // input buffer
static string outputbuf;
static int PosX = 0;
static int PosY = 0;
Code:
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
PosX = 0;
PosY = 0;
SetRect(&rc, 200, 200, 300, 300);
for (int b = 0; b < 2; b++) {
for (int a = 0; a < strlen(output_line); a++)
ch[0] = 00;
for (int a = 0; a < outputbuf.size(); a++) {
ch[0] = outputbuf[a];
TextOut(hdc, PosX, PosY * dwCharY, ch, 1);
ch1 = ch;
DrawText(hdc, ch1, 1, &rc, DT_LEFT);
GetTextExtentPoint32(hdc, ch1, 1, &sz);
PosX += sz.cx;
if ((DWORD) PosX > dwLineLen) {
PosX = 0;
++PosY;
}
}
}
EndPaint(hwnd, &ps);
return 0;
and
Code:
case WM_TIMER:
//process the timer msgs, check which timer has fired
switch (wParam)
case IDT_TIMER1:
{
hdc = GetDC(hwnd);
outputbuf += "Hello world. This is a long string to fill up the window. ";
ReleaseDC(hwnd, hdc);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
}
return 0;
Thanks for your help.