Results 1 to 21 of 21

Thread: DrawText RECT

  1. #1

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335

    DrawText RECT

    Why do i get a error? i dont know RECT really.
    VB Code:
    1. RECT lbl;
    2.  
    3. lbl.left = 20;
    4. lbl.top = 100;
    5. lbl.right = 200;
    6. lbl.bottom = 30;
    7.  
    8. ::DrawText(NULL,"Jason",-1,lbl,DT_CENTER);
    9.  
    10. E:\Program Files\Microsoft Visual Studio\MyProjects\class2 test\main.cpp(48) : error C2664: 'DrawTextA' : cannot convert parameter 4 from 'struct tagRECT' to 'struct tagRECT *'
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    pass the address &lbl
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    thanks no error but no text maybe because
    in
    VB Code:
    1. int DrawText(
    2.   HDC hDC,          // handle to DC
    3.   LPCTSTR lpString, // text to draw
    4.   int nCount,       // text length
    5.   LPRECT lpRect,    // formatting dimensions
    6.   UINT uFormat      // text-drawing options
    7. );
    How do i use :
    HDC hDC, // handle to DC

    I tried MSDN but cant understand maybe someone can help me thanks
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  4. #4
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    Code:
    HDC hdc = BeginPaint(hWnd, &ps);
    //paint here
    EndPaint(hWnd, &ps);
    VS.NET 2003

    Need to email me?

  5. #5

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    ok sort of helped but still nothing i got
    Code:
    	RECT lbl;
    			lbl.left = 30;
    			lbl.top = 300;
    			lbl.right = 200;
    			lbl.bottom = 30;
    
    PAINTSTRUCT ps;
    
    HDC hdc = BeginPaint(hwnd, &ps);
    ::DrawText(hdc,"Jason",-1,&lbl,DT_CENTER);
    EndPaint(hwnd, &ps);
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  6. #6
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    Do you have your code in WM_PAINT message?
    VS.NET 2003

    Need to email me?

  7. #7

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    I got it like but no good my window bg is white
    Code:
    case WM_PAINT:
    {
    RECT lbl;
    lbl.left = 30;
    lbl.top = 90;
    lbl.right = 200;
    lbl.bottom = 30;
    
    PAINTSTRUCT ps;
    
    HDC hdc = BeginPaint(hwnd, &ps);
    ::DrawText(hdc,"Jason",-1,&lbl,DT_CENTER);
    EndPaint(hwnd, &ps);
    }
    break;
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    rect.top = 90
    rect.bottom = 30


    Positive y axis goes down. Your bottom is higher than your top.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    LOL i thought that ment like how far apart from the top lol. Thankx alot it worked great.
    Last edited by JasonLpz; Jan 30th, 2003 at 11:34 AM.
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  10. #10

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    ok now i go it , it works great but i can i run this from anytime i want?

    Code:
    case WM_PAINT:
    		{
    				RECT lbl;
    			lbl.left = 6;
    			lbl.top = 10;
    			lbl.right = 200;
    			lbl.bottom = 33;
    			
    				RECT lbl2;
    			lbl2.left = 6;
    			lbl2.top = 38;
    			lbl2.right = 200;
    			lbl2.bottom = 66;
    				
    				RECT lbl3;
    			lbl3.left = 6;
    			lbl3.top = 60;
    			lbl3.right = 200;
    			lbl3.bottom = 89;
    PAINTSTRUCT ps;
    
    HDC hdc = BeginPaint(hwnd, &ps);
    ::DrawText(hdc,"First Name",-1,&lbl,DT_LEFT);
    ::DrawText(hdc,"Last Name",-1,&lbl2,DT_LEFT);
    ::DrawText(hdc,"Enter NO. To look up.",-1,&lbl3,DT_LEFT);
    
    EndPaint(hwnd, &ps);
    		}
    		break;
    do i do a refresh? or like update or i cant?
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  11. #11
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555
    You need to send a WM_PAINT message to yourself.
    Code:
    SendMessage(hwnd, WM_PAINT, 0, 0)
    maybe?

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    First you invalidate a region of your window (or all of it):
    Code:
    InvalidateRect(hwnd, &rectToInvalidate, TRUE);
    // or for the whole window
    InvalidateRect(hwnd, NULL, TRUE);
    Then you can either wait for windows to ask your app to redraw (it will do that once your app is idle) or force immediate redrawing:
    Code:
    UpdateWindow(hwnd);
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    oh i c ok thanks i should be buying a couple of api books this week maybe. wheni do i wont ask such small questions anymore , cuz i know its a pain thankz
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  14. #14

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    also can i drawtext to another program?
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yes, given that you find out its hwnd. There are many ways to do that, the most common being FindWindow.
    Then you call GetDC on that window and draw whatever you want into that dc. Call ReleaseDC when you're finished.


    But note that everything you draw is gone once the other app repaints. Also it is considered bad manners for an app to do such a thing.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  16. #16

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    thx i will respect other developers programs. and also if i put that code in a timer will it work ok?

    HDC hdc2 = ::GetDC(i) ? would work

    ADDED
    Code:
    HDC hdc2 = ::GetDC(i);
    ::DrawText(hdc2,"Made By: Jason Lopez aka JayWare",-1,&lbl2,DT_LEFT);
    ReleaseDC (i,hdc2);
    Last edited by JasonLpz; Jan 30th, 2003 at 08:39 PM.
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  17. #17
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Why in a timer?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  18. #18

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    so it will stay on the other form. So how would i do it . That code i got above dont work.
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  19. #19

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    ok yes it does work lol thanks
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  20. #20
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    could you subclass it? or would your winproc be called first and then the original proc overwrite the screen?
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  21. #21

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    i got it to work great in a timer just send WM_PAINT and walla! here is a sample of what i did. if you want the source tell me. This adds some text to notepad in win98 se and winxp(tested). this is the exe ziped up at 52kb.
    Attached Files Attached Files
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width