Advertisement

problem with windows color

Started by August 07, 2000 08:21 PM
0 comments, last by OoMMMoO 24 years, 4 months ago
I made a program to display random pixels in just one color(a also tried it with random colors too) but it just uses one of 3 colors a red a dark green and a tan color. I can set the color of RGB to RGB(0,0,0) and it will display it red my code is #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #include //DEFINES/////////////////////////////// #define WINDOW_CLASS_NAME "WinClass" //GLOBALS////////////////////////////// HWND main_window_handle=NULL; //FUNCTIONS//////////////////////////// LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch(msg) { case WM_CREATE: { return(0); }break; case WM_PAINT: { hdc=BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps); return(0); }break; case WM_DESTROY: { PostQuitMessage(0); return(0); }break; default:break; } return(DefWindowProc(hwnd,msg,wparam,lparam)); } //WINMAIN/////////////////////////////////////// int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,LPSTR lpcmdline,int ncmdshow) { WNDCLASS winclass; HWND hwnd; MSG msg; HDC hdc; PAINTSTRUCT ps; winclass.style= CS_DBLCLKS|CS_OWNDC| CS_HREDRAW|CS_VREDRAW; winclass.lpfnWndProc= WindowProc; winclass.cbClsExtra= 0; winclass.cbWndExtra= 0; winclass.hInstance= hinstance; winclass.hIcon= LoadIcon(NULL,IDI_APPLICATION); winclass.hCursor= LoadCursor(NULL,IDC_ARROW); winclass.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName= NULL; winclass.lpszClassName= WINDOW_CLASS_NAME; if(!RegisterClass(&winclass)) return(0); if(!(hwnd=CreateWindow(WINDOW_CLASS_NAME,"Lines",WS_OVERLAPPEDWINDOW|WS_VISIBLE,0,0,320,200, NULL,NULL,hinstance,NULL))) return(0); main_window_handle=hwnd; srand((unsigned)time(NULL)); while(1) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message==WM_QUIT)break; TranslateMessage(&msg); DispatchMessage(&msg); } //DRAWLINES//////////////////////////////////////// hdc=GetDC(hwnd); HPEN random_color=CreatePen(PS_SOLID,0,RGB(0,0,0)); HPEN old_color=SelectObject(hdc,random_color); SetPixel(hdc,(rand()%799)+1,(rand()%599)+1,random_color); SelectObject(hdc,old_color); DeleteObject(random_color); ReleaseDC(hwnd,hdc); } return(msg.wParam); } can someone please help
Well, I don''t really see why you''re using an HPEN in your SetPixel. SetPixel''s parameters are as follows:

COLORREF SetPixel( HDC hdc, // handle to device context
int X, // x-coordinate of pixel
int Y, // y-coordinate of pixel
COLORREF crColor // pixel color
);

as cut-pasted out of DevStudio, if you''re using the pure Win32 GDI call as it appears you''re doing. So basically you''re passing it a handle, and I''m guessing that the numerical value of the HPEN your system comes up with just happens to be the color red when interpreted... not sure why it''s not picking up an error on that to be honest.

Make your 4th parameter a COLORREF and you should be fine.

HTH
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~

This topic is closed to new replies.

Advertisement