colors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jivko
    New Member
    • Nov 2008
    • 3

    colors

    Hi there, how can i make a background color in a C program? Must i use structures or unions?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    There's more to this than you suppose.

    First, what operating system?

    Second, you need a window before you can have a background color.

    Assuming you have Windows and know how to create a window, then the backgound color can be set with http://msdn.microsoft.com/en-us/libr...61(VS.85).aspx.

    Comment

    • boxfish
      Recognized Expert Contributor
      • Mar 2008
      • 469

      #3
      At least on windows, you can change the colors of your program's console window by calling an operating system specific command with the system function. If you are running windows, you can type "help color" into the command prompt to get information on the command.
      system("color 6D");

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        I didn't know you could do that. Nice reply.

        Comment

        • boxfish
          Recognized Expert Contributor
          • Mar 2008
          • 469

          #5
          Thanks. You can also do this by right-clicking on the title bar of the command prompt window and clicking on properties. It lets you choose all sorts of things about your command prompt window.

          Comment

          • jivko
            New Member
            • Nov 2008
            • 3

            #6
            Originally posted by weaknessforcats
            There's more to this than you suppose.

            First, what operating system?

            Second, you need a window before you can have a background color.

            Assuming you have Windows and know how to create a window, then the backgound color can be set with http://msdn.microsoft.com/en-us/libr...61(VS.85).aspx.
            operation system is windows xp, i use quincy compiler. What is wrong with the line 17 ...load Icon?
            //line 0
            #include <windows.h>
            LRESULT CALLBACK WindowFunc(HWND ,UINT,WPARAM,LP ARAM);
            char szWinName[]= "MyWin";
            int WINAPI WinMain(HINSTAN CE hThisInst, HINSTANCE
            hPrevInst, LPSTR lpszArgs,
            int nWinMode)
            {
            HWND hwnd;
            MSG msg;
            WNDCLASSEX wcl;
            wcl.cbSize=size of(WNDCLASSEX);
            wcl.hInstance=h ThisInst;
            wcl.lpszClassNa me=szWinName;
            wcl.lpfnWndProc =WindowFunc;
            wcl.style=0;
            wcl.hIcon = LoadIcon(NULL,I DI_APPLICATION) ;
            //ñòèë íà èêîíàòà
            wcl.hIconSm=Loa dIcon(NULL,IDI_ WINLOGO);
            //ñòèë íà ìàëêàòà èêîíà
            wcl.hCursor=Loa dCursor(NULL,ID C_ARROW);
            //ñòèë íà êóðñîðà
            wcl.lpszMenuNam e=NULL;
            wcl.cbClsExtra= 0;
            wcl.cbWndExtra = 0;
            //öâåòúò íà ôîíà íà ïðîçîðåöà äà áúäå áÿë
            wcl.hbrBackgrou nd = (HBRUSH)GetStoc kObject(WHITE_B RUSH);
            //ðåãèñòðèðàíå íà êëàñà íà ïðîçîðåöà
            if(!RegisterCla ssEx(&wcl)) return 0;

            hwnd = CreateWindow(
            szWinName, "Windows Skeleton", WS_OVERLAPPEDWI NDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, HWND_DESKTOP, NULL,hThisInst, NULL);

            ShowWindow(hwnd ,nWinMode);
            UpdateWindow(hw nd);
            while(GetMessag e(&msg, NULL, 0, 0))
            {
            TranslateMessag e(&msg);
            DispatchMessage (&msg);
            }
            return msg.wParam;
            }
            LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
            {
            switch(message) {
            case WM_DESTROY:
            PostQuitMessage (0);
            break;
            default:
            return DefWindowProc(h wnd, message, wParam, lParam);
            }
            return 0;
            }

            Comment

            • arnaudk
              Contributor
              • Sep 2007
              • 425

              #7
              What error do you get? It would help if you used [CODE] ... [/CODE] tags as this code is hardly legible.

              Comment

              • jivko
                New Member
                • Nov 2008
                • 3

                #8
                "Undefined reference to LoadIcon". The compilation is ok, the linkage can not work.

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  But you don't have a problem with LoadCursor?

                  Try calling LoadImage instead (of either or both of them).

                  Comment

                  Working...