none
c++ RRS feed

答案

  • 您好,

    您的问题是具体设置什么的文本颜色?您的程序是控制台程序还是MFC图形界面程序?

    如果是控制台程序,以下代码是修改文本颜色的例子,供你参考。

    #include "stdafx.h"
    #include<Windows.h>
    int main()
    {
    
        HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    
        printf("绿色\n");
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_RED | FOREGROUND_INTENSITY);
    
        printf("红色\n");
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_RED | FOREGROUND_BLUE);
    
        printf("粉红\n");
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
    
        printf("加强以后的粉红\n");
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    
        printf("颜色可以自己混合\n");
    
        system("pause");
        return 0;
    }
    

    如果是图形界面的程序,您可以使用CDC::SetTextColor 方法来设置;或者您也可以通过在对话框类中实现 ON_WM_CTLCOLOR来设置。

    以下链接中的样例代码供你参考。

    http://stackoverflow.com/questions/1636590/mfc-change-text-color-of-a-cstatic-text-control

    http://msdn.microsoft.com/en-us/library/0wwk06hc.aspx

    希望对您有帮助!

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年1月13日 6:30

全部回复

  • CDC::SetTextColor() ??

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    2014年1月12日 2:04
    版主
  • 您好,

    您的问题是具体设置什么的文本颜色?您的程序是控制台程序还是MFC图形界面程序?

    如果是控制台程序,以下代码是修改文本颜色的例子,供你参考。

    #include "stdafx.h"
    #include<Windows.h>
    int main()
    {
    
        HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    
        printf("绿色\n");
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_RED | FOREGROUND_INTENSITY);
    
        printf("红色\n");
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_RED | FOREGROUND_BLUE);
    
        printf("粉红\n");
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
    
        printf("加强以后的粉红\n");
    
        SetConsoleTextAttribute(hStdout,
            FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    
        printf("颜色可以自己混合\n");
    
        system("pause");
        return 0;
    }
    

    如果是图形界面的程序,您可以使用CDC::SetTextColor 方法来设置;或者您也可以通过在对话框类中实现 ON_WM_CTLCOLOR来设置。

    以下链接中的样例代码供你参考。

    http://stackoverflow.com/questions/1636590/mfc-change-text-color-of-a-cstatic-text-control

    http://msdn.microsoft.com/en-us/library/0wwk06hc.aspx

    希望对您有帮助!

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年1月13日 6:30