Painting with Tex on a Win32 Application
I was reading your article on painting Text into a Win32 application.
I am attempting to write a small program that I would like to read an
INI file to get instructions and execute them accordingly. I am able to
do all that but I am not currently happy with the program That I have
created in MFC. Currently, I am using a Static inlay to send the text
to a dialog interface. I can only use the static Text Control, for if I
use the Edit Control, I am not able to enter the Text messages that I
generate from the execution of the INI instructions in new lines. They
all want to follow each other and "\n" or "\r" does not get me to a new
line. However the Static control do allow it, but it is transparent and
inherits the current windows' colors. So as you can see, I am getting a
little of what I want, but not very effective for what I want to do. I
would like to use your approach and have a white window to paint the
texts. I also would like to remove the ability for the user to close
the program while it is running. The system tools needs to only be
available as a "minimize" and a "maximize" the close option should not
be available.
I did generate a Win32 application using the C++ wizard and do have
the code you have on line. I wanted to know how I can paint to the
generated view dynamically. So far, I do see how to enter a Static
text, such as "hello world", but how do I keep adding to the existing
text and dynamically generate these entries from a separate function
that I will call to read the INI file and execute its instructions?
Any assistance that you can provide or any example of how to paint
dynamically would be appreciated.
Regards,
Johnny
Painting with Text on a Win32 Application
Hi,
I am using this Function:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
// TCHAR m_text[MAX_LOADSTRING];
//LoadString(hInst, IDS_HELLO, m_text, MAX_LOADSTRING);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
SetTextColor(hdc, COLORREF(0x00FF0000));
DrawText(hdc, m_text, strlen(m_text), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
////////////////////// Trying to add text by using the following block of text and... /////////////////////////
m_text= "Welcome to My Process...";
AppendWindowText(hWnd, m_text);
Sleep(150);
m_text = m_text + "This is a test to add test...\r\n";
AppendWindowText(hWnd, m_text);
Sleep(150);
m_text = m_text + "This is a test to add test...\r\n";
AppendWindowText(hWnd, m_text);
return 0;
}
////// The following function to publish the text... ////
void AppendWindowText(HWND hwnd, const char * szFormat)
{
TCHAR szText[4096];
va_list args;
int nTxtLen;
/* Move selection to end of text */
nTxtLen = GetWindowTextLength(hwnd);
SendMessage(hwnd, EM_SETSEL, nTxtLen, nTxtLen);
/* Format the text into the buffer */
va_start(args, szFormat);
StringCchVPrintf(szText, sizeof(szText) / sizeof(szText[0]), szFormat, args);
szText[(sizeof(szText) / sizeof(szText[0])) - 1] = TEXT('\0');
va_end(args);
/* Add the text line and scroll it into view */
SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM) szText);
SendMessage(hwnd, EM_SCROLLCARET, 0, 0);
}
//// That does not work very well for me. IKt takes a long time for the text to apear. Can you please let me know how I can publish text to my client window after the initial WM_PAINT has written the header block of text?
Is there a place where I can place a function that can then send the AppendWindowText(hWnd, m_text); command?
BTW: http://www.cprogramming.com/tutorial/gl4.html : The code from this page takes 99% of my CPU when it runs... Is that by design?
Thanks,
Johnny