By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,433 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,433 IT Pros & Developers. It's quick & easy.

colors

P: 3
Hi there, how can i make a background color in a C program? Must i use structures or unions?
Nov 8 '08 #1
Share this Question
Share on Google+
8 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Nov 8 '08 #2

boxfish
Expert 100+
P: 469
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");
Nov 8 '08 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
I didn't know you could do that. Nice reply.
Nov 8 '08 #4

boxfish
Expert 100+
P: 469
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.
Nov 8 '08 #5

P: 3
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,LPARAM);
char szWinName[]= "MyWin";
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE
hPrevInst, LPSTR lpszArgs,
int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize=sizeof(WNDCLASSEX);
wcl.hInstance=hThisInst;
wcl.lpszClassName=szWinName;
wcl.lpfnWndProc=WindowFunc;
wcl.style=0;
wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
//стил на иконата
wcl.hIconSm=LoadIcon(NULL,IDI_WINLOGO);
//стил на малката икона
wcl.hCursor=LoadCursor(NULL,IDC_ARROW);
//стил на курсора
wcl.lpszMenuName=NULL;
wcl.cbClsExtra=0;
wcl.cbWndExtra = 0;
//цветът на фона на прозореца да бъде бял
wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
//регистриране на класа на прозореца
if(!RegisterClassEx(&wcl)) return 0;

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

ShowWindow(hwnd,nWinMode);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&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(hwnd, message, wParam, lParam);
}
return 0;
}
Nov 10 '08 #6

100+
P: 424
What error do you get? It would help if you used [CODE] ... [/code] tags as this code is hardly legible.
Nov 10 '08 #7

P: 3
"Undefined reference to LoadIcon". The compilation is ok, the linkage can not work.
Nov 10 '08 #8

Banfa
Expert Mod 5K+
P: 8,916
But you don't have a problem with LoadCursor?

Try calling LoadImage instead (of either or both of them).
Nov 10 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.