Hi there, how can i make a background color in a C program? Must i use structures or unions?
colors
Collapse
X
-
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. -
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
-
-
Originally posted by weaknessforcatsThere'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.
//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
Comment