Thread: Painting with Tex on a Win32 Application

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    3

    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

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well if I understand your question correctly, it's actually quite a simple solution. Let's say you wrote printf("Hello World!"). That's writing static text, because you passed a string literal to the printf function. To write dynamic text that you had determined in another function, you could also use the printf function, but instead using variables, like printf("The number you entered was %d", x).

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    3
    Hi,

    I am refering to this link: http://www.cprogramming.com/tutorial/gl4.html that has the actual approach that I am using. My question is the following: I want to use a function to process osme data from instructions received from an INI file. Then, I want to report to the program's view client the results of what actually happend, jus tlike the client is able to paint "Hello World". I want to be able to write all the messages in a separate line and have them all visible to the User using the program, sort of like a report of an install, etc.
    I was hoping to get some assistance in sending the messages to the Client window.
    Can you help?

    Thanks,

    Johnny

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Once your program has synthesized the string(s) you want to send to the screen you just have the function feed that data into string[]. If you have multiple lines you can do a two dimensional array, or there are a couple of other ways to store multiple strings, but they're all about the same. Then you just have multiple textout() calls. I'm not sure if just having one long string delineated by /n would still format it right but that's the gist of it.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    - You can create a multiline edit control with the ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL styles.

    - If you want the edit control to be read only use the ES_READONLY style also.

    - To start a new line use the characters "\r\n".

    - To change the background or text colors in either an edit control or a static control search the forums for WM_CTLCOLOR, WM_CTLCOLOREDIT or WM_CTLCOLORSTATIC.

    - For a sample of appending to an edit control see this post.

    - For a discussion on removing or disabling the close button see this post.

    - C++ provides a dynamic string class: std::string. This can be added to and automatically resizes. If you wanted to use GDI painting you could use a std::string to add your commands to. You would then paint the contents of the string in WM_PAINT using the DrawText function. To cause a WM_PAINT to be issued you can call the InvalidateRect() function.

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    3

    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
    Last edited by webzest; 08-16-2004 at 04:30 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-08-2008, 04:48 PM
  2. win32 application wizard in microsoft visual studio
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 02-25-2008, 01:26 AM
  3. Adding interface to Win32 console application
    By motiz in forum Windows Programming
    Replies: 5
    Last Post: 01-03-2008, 03:17 AM
  4. making a stealthy win32 console application?
    By killdragon in forum C++ Programming
    Replies: 3
    Last Post: 09-08-2004, 02:50 PM
  5. How To Convert A Dos-Prompt C++ PRogram Into Win32 Application ?
    By SonicWave in forum Windows Programming
    Replies: 1
    Last Post: 09-15-2001, 11:03 AM