Results 1 to 4 of 4

Thread: Drawing Text :) :confused: :)

  1. #1

    Thread Starter
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191

    Drawing Text :) :confused: :)



    • Win32 API I need help on
    • TextOut (not really but it applies)
    • SetBkColor //doesn't work
    • SetTextColor //doesn't work


    ok i am making a cheap old api spy to help myself learn about strings and pointers and so on and I want to do TextOut with a Black Background Rect and a White Text face and i try doing it like so

    Code:
        COLORREF cBack, cTxt;
        char txtOut = "Some Text";
        cBack = RGB(0, 0, 0);
        cTxt = RGB(255, 255, 255);
        
        SetBkColor(GetDC(hwnd), cBack);
        SetTextColor(GetDC(hwnd), cTxt);
    
        TextOut(GetDC(hwnd), 5, 5, txtOut, strlen(txtOut));
    And basicly my window gets Text on it but it is not formated with the color values i used it is using the default.

    so what is the problem? I thought it might be that be the COLORREF coming up bad but i used FillRect to flash my windw RGB and it works, so any ideas?

    Thanks
    Magiaus
    Visual Basic 6.0 SP5
    Visual C++ 6.0 SP5


    The only sovereign you can allow to rule you is reason.

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I think you can only change the backcolor and textcolor this way when you have created a dialogbox.
    If you have dialogbox then this code should work:

    PHP Code:
    HBRUSH cBack;
        
    COLORREF cTxt;
        
    char *txtOut "Some Text";
        
    cBack = (HBRUSH)CreateSolidBrush(RGB(2552550));
        
    cTxt RGB(255255255);
        
        switch(
    Message)
        {
        case 
    WM_CTLCOLORDLG:
            
            
    SetBkMode(GetDC(hwnd), TRANSPARENT);
            
    SetTextColor(GetDC(hwnd), cTxt);
                   
            return (
    LONG)cBack;
        case 
    WM_PAINT:
            
            
    TextOut(GetDC(hwnd), 55txtOutstrlen(txtOut)); 
    Baaaaaaaaah

  3. #3

    Thread Starter
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191
    i'll give that a go after i get done taking my brake and let you know
    Magiaus
    Visual Basic 6.0 SP5
    Visual C++ 6.0 SP5


    The only sovereign you can allow to rule you is reason.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, it's just that you need the same dc for setting the colors and drawing, but you requested a new one for each thing.
    Code:
    COLORREF cBack, cTxt;
        char* txtOut = "Some Text";  // typo here
        cBack = RGB(0, 0, 0);
        cTxt = RGB(255, 255, 255);
        HDC hdc = GetDC(hwnd);
    
        SetBkColor(hdc, cBack);
        SetTextColor(hdc, cTxt);
    
        TextOut(hdc, 5, 5, txtOut, strlen(txtOut));
    
        ReleaseDC(hdc);   // you should always call that
    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.

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