Results 1 to 15 of 15

Thread: Text color

  1. #1
    Guest

    Post

    How do i set the text color and then have it stay that way when i leave the prog?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    What do you mean when you leave the program. To simply change the color:

    Code:
    3.2.7. How do I change the background/text color of an EDIT control?
    
    This can easily be accomplished by handling (NOT sending) the messages WM_CTLCOLOREDIT and WM_CTLCOLORSTATIC. Why the STATIC one? Well if the edit control is disabled then it sends WM_CTLCOLORSTATIC instead, so you need to be aware of which you are going to use or both. 
    
    To change the background colour you return the handle to a brush, which windows will use to paint the background of the control. To change the text color, you can use SetTextColor() on the HDC which is passed to you in the wParam parameter. You may also want to use SetBkMode() to set the text drawing mode to TRANSPARENT, otherwise your background color won't show through if you are changing it. 
    
    For example, to make the background black, you would do: 
    
    	case WM_CTLCOLOREDIT:
    	return (LRESULT)GetStockObject(BLACK_BRUSH);
    
    If your edit control is disabled, substitute WM_CTLCOLORSTATIC for WM_CTLCOLOREDIT. 
    
    But if your background is black, you probably don't want your text to be black. So we'll make it white: 
    
    	case WM_CTLCOLOREDIT:
    		SetBkMode((HDC)wParam, TRANSPARENT);
    		SetTextColor((HDC)wParam, RGB(255, 255, 255));
    	return (LRESULT)GetStockObject(BLACK_BRUSH);
    
    If you only want to change the color for a single control, you can match the ID of the control you want to change to the ID of the hwnd you get in lParam: 
    
    	case WM_CTLCOLOREDIT:
    		if(IDC_OF_THE_CONTROL == GetDlgCtrlID((HWND)lParam)){
    			SetBkMode((HDC)wParam), TRANSPARENT);
    			SetTextColor((HDC)wParam, RGB(255, 255, 255));
    			return (LRESULT)GetStockObject(BLACK_BRUSH);
    		}
    	break;
    
    If you haven't guessed by now, you can also use this to change the colors of STATIC controls, and a few others. (look up the WM_CTLCOLOR* messages in MSDN)
    I am become death, the destroyer of worlds.
    mail:vlatkovr@hotmail.com

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Guest
    I meant dos.

  4. #4
    Guest
    Anyone?

  5. #5
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61
    Please anyone
    ---~^ Absalom ^~---

    There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.

  6. #6
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158
    Code:
    #include <conio.h>
    #include <string.h>
                    
    void keypress();
    
    void main()
    {
    
    clrscr();
    keypress();
    
    }
    
    void keypress()
    {
    textcolor(14);
    gotoxy(35,13);
    cprintf("Text color is yellow?");
    getch();
    }
    Compile in Borland, for some reason it vc++ doesnt come with any graphics libraries. so you'll have to get them from somewhere else, or just compile in borland. you may also have to include

    Code:
    #include <graphics.h>
    but I dont think so.
    Stephen Bazemore
    Email:runik@hotmail.com

  7. #7
    Guest
    The problem with that is that it doesnt stay that color after the program has ended.

  8. #8
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158
    What text are you wanting to color? The text in your app or like all dos text?
    Stephen Bazemore
    Email:runik@hotmail.com

  9. #9
    Guest
    All of dos.

  10. #10
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61
    The code to do all of dos (and this works in VC++) is

    Code:
    #include <windows.h>
    #include <string>
    #include <iostream>
    #include <wincon.h>
    int main()
    {
     HANDLE hout;
     DWORD ret;
     hout=GetStdHandle(STD_OUTPUT_HANDLE);
     SetConsoleTextAttribute(hout, FOREGROUND_RED|BACKGROUND_GREEN);
     cout << "Your Message here" << endl;
     WriteConsole(hout,std.c_str(),std.size(),&ret,NULL);
    }
    you can find the different color codes in wincon.h
    ---~^ Absalom ^~---

    There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.

  11. #11
    Guest
    Thats not dos, thats windows.

  12. #12
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61
    Umm.. Sorry thats a VC++ code only I just tried it
    ---~^ Absalom ^~---

    There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.

  13. #13
    Guest
    Its not that it will only work on VC++, itll work with borland too, the problem is that its Windows and not DOS.

  14. #14
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61
    No it is a windows console code
    ---~^ Absalom ^~---

    There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.

  15. #15
    Guest
    Ok, now your just repeating what i said.

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