Thread: I made a window... now how do I fill it?

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    48

    I made a window... now how do I fill it?

    I have an empty window... how do I...

    1) How do I add text on the window?

    2) How do I add text entry boxes and buttons? And how do I set the text in the box at the time of the button press to a variable?

    thanks

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution id DrawText().

    Kuphryn

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    48
    Can you give me a example please?

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    CRect rect;
    DrawText(TEXT("Display Texts"), &rect, DT_CENTER);

    Kuphryn

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    48
    Errors:

    1)`CRect' undeclared (first use this function)

    2)`rect' undeclared (first use this function)

    3) passing `const char *' as argument 1 of `DrawTextA(HDC__ *, const CHAR *, int, tagRECT *, unsigned int)'

  6. #6
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Please post your ccode here!
    Do not make direct eye contact with me.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    48
    I used exactly what kuphryn said:

    Code:
     
    void posttext()
    {
    CRect rect;
    DrawText(TEXT("Display Texts"), &rect, DT_CENTER);
    }

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Kuphryn's example uses MFC, I suspect you are not.

    1) How do I add text on the window?

    Using Win32 API: Handle the WM_PAINT message and:
    Code:
    PAINTSTRUCT ps;
    TCHAR chTxt[]=TEXT("Hello world");
    BeginPaint(hwnd,&ps);
      SetBkMode(ps.hdc,TRANSPARENT);
      TextOut(ps.hdc,20,20,chTxt,lstrlen(chTxt));
    EndPaint(hwnd,&ps);
    2) How do I add text entry boxes and buttons? And how do I set the text in the box at the time of the button press to a variable?

    These are windows controls. You will find examples in msdn from that link, elsewhere on the web and by searching this board.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    48
    This compiles successfully buit does not put any text

    Code:
    void posttext()
    {
    HWND hwnd;
    PAINTSTRUCT ps;
    TCHAR chTxt[]=TEXT("Hello world");
    BeginPaint(hwnd,&ps);
      SetBkMode(ps.hdc,TRANSPARENT);
      TextOut(ps.hdc,20,20,chTxt,lstrlen(chTxt));
    EndPaint(hwnd,&ps);
    }

  10. #10
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    That should draw some text, but you need to have that within your window procedure. Somewhere, you handle WM_CLOSE, etc?

    You need to handle WM_PAINT there as well. When you get a WM_PAINT, you should run that code.

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    48
    That should draw some text, but you need to have that within your window procedure. Somewhere, you handle WM_CLOSE, etc?
    I don't, how do I do that?

  12. #12
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Check out Adrianxw's example in this thread:

    http://www.cprogramming.com/cboard/s...threadid=39836

  13. #13
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    Copying and pasting code to make a window won't help you if you don't know what any of it does. I'm sorry, but if you can't figure out where your window procedure is, go back to console.

  14. #14
    Registered User
    Join Date
    Nov 2002
    Posts
    48
    I couldn't care less how it works if it does what I want it to do

  15. #15
    Registered User
    Join Date
    Nov 2002
    Posts
    48
    http://www.cprogramming.com/cboard/showthread.php?threadid=39836 wont open.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button positioning
    By Lionmane in forum Windows Programming
    Replies: 76
    Last Post: 10-21-2005, 05:22 AM
  2. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  3. no errors but still errors
    By Megatron in forum Windows Programming
    Replies: 7
    Last Post: 01-12-2003, 11:21 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 04:49 PM