GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Jan-2005, 16:15
Rosdahale Rosdahale is offline
New Member
 
Join Date: Dec 2004
Posts: 20
Rosdahale is on a distinguished road

Changing window start colour


I have this basic template set up to create a blank window to start drawing in, how do i change the colour of the background, so I dont get black when it starts up (instad of actually drawing a green rectangle to fill the window)

Main_Prog.cpp
CPP / C++ / C Code:
#include "Globals.h"

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	// this is the main message handler of the system
	PAINTSTRUCT		ps;		// used in WM_PAINT
	HDC				hdc;	// handle to a device context	

	switch(msg)
	{	
		case WM_CREATE: 
		{
			// do initialization stuff here
			return(0); // return success
		} break;
   
		case WM_PAINT: 
		{
   			hdc = BeginPaint(hwnd,&ps);	// simply validate the window 
			EndPaint(hwnd,&ps); // end painting
			return(0); // return success
   		} break;

		case WM_DESTROY: 
		{
			PostQuitMessage(0); // kill the application, this sends a WM_QUIT message
			return(0); // return success
		} break;

		default:break;

	} // end switch
	
	return (DefWindowProc(hwnd, msg, wparam, lparam)); // process any messages that we didn't take care of 

} // end WinProc

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{

	WNDCLASSEX winclass; // this will hold the class we create
	HWND	   hwnd;	 // generic window handle
	MSG		   msg;		 // generic message

	// first fill in the window class stucture
	winclass.cbSize         = sizeof(WNDCLASSEX);
	winclass.style			= 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;
	winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

	
	// register the window class
	if (!RegisterClassEx(&winclass))
		return(0);

	// create the window
	if (!(hwnd = CreateWindowEx(
		NULL, // extended style
		WINDOW_CLASS_NAME,   // class
		TITLE, // title
		WS_CAPTION | WS_VISIBLE,
		100,50,	  // initial x,y
		WINDOW_WIDTH, // initial width
		WINDOW_HEIGHT,// initial height
		NULL,	  // handle to parent 
		NULL,	  // handle to menu
		hinstance,// instance of this application
		NULL)))	// extra creation parms
		return(0);


	//main_window_handle = hwnd; // save main window handle
	GameHandle = hwnd;

	// enter main event loop
	Initialise(); // Draw the graphics
	while(TRUE)
	{
		// test if there is a message in queue, if so get it
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{ 
		   // test if this is a quit
		   if (msg.message == WM_QUIT)
			   break;
		
		   // translate any accelerator keys
		   TranslateMessage(&msg);

		   // send the message to the window proc
		   DispatchMessage(&msg);
		 } // end if	
		
		 
		 Main_Loop();		 		 
       
	} // end while
	
	// return to Windows like this
	return(msg.wParam);

} // End WinMain

Globals.cpp
CPP / C++ / C Code:
#include "Globals.h"

HWND GameHandle;

Globals.h
CPP / C++ / C Code:
#pragma once

#define WIN32_LEAN_AND_MEAN  // Compile only necessary elements

#include <windows.h>   // include all the windows headers
#include <stdlib.h>
#include <stdio.h>

// defines for windows 
#define WINDOW_CLASS_NAME "WINCLASS1"
#define TITLE "Window title here"
#define WINDOW_WIDTH  808 // Need these settings to give 800x600 ex border
#define WINDOW_HEIGHT 634

// Macros
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

// Structures

//Globals
extern HWND GameHandle;
Last edited by dsmith : 17-Jan-2005 at 17:10. Reason: Please use [c] & [/c] for posting C code.
  #2  
Old 18-Jan-2005, 09:37
Dr. Evil Dr. Evil is offline
Member
 
Join Date: Oct 2004
Location: Netherlands
Posts: 120
Dr. Evil will become famous soon enough
It's the hbrBackground struct element. You're calling GetStockObject() with BLACK_BRUSH, so, naturally, the background will be black. Try GREEN_BRUSH or look up the other definitions to see what the possible colors are.
  #3  
Old 18-Jan-2005, 09:39
Rosdahale Rosdahale is offline
New Member
 
Join Date: Dec 2004
Posts: 20
Rosdahale is on a distinguished road
I've tried that. GREEN_BRUSH not recognised. It only does BLACK_BRUSH and WHITE_BRUSH
  #4  
Old 19-Jan-2005, 04:54
veppe veppe is offline
New Member
 
Join Date: Jan 2005
Location: Sundsvall, Sweden
Posts: 3
veppe is on a distinguished road
try the RGB Macro like :

...
winclass.hbrBackground =(HBRUSH)CreateSolidBrush(RGB(0,255,0));
...
  #5  
Old 19-Jan-2005, 06:24
veppe veppe is offline
New Member
 
Join Date: Jan 2005
Location: Sundsvall, Sweden
Posts: 3
veppe is on a distinguished road
Ofcouse, the CreateSolidBrush function returns a HBRUSH so you dont have to cast it... a litte to fast copy/paste by me.

Regards

// Veppe
  #6  
Old 19-Jan-2005, 15:51
Rosdahale Rosdahale is offline
New Member
 
Join Date: Dec 2004
Posts: 20
Rosdahale is on a distinguished road
Thanks ill give it a go
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FLTK && fluid In Motion cable_guy_67 FLTK Forum 4 20-Mar-2008 03:52
Urgent ! Pls Help Me ! mycashmoney C Programming Language 4 01-Jul-2006 22:49
Simple FLTK dialog box sample cable_guy_67 FLTK Forum 4 02-Nov-2004 08:46
Looking for Reliable, Cheap ASP, ASP.NET MSSQL Hosting start from $4 stevewatt88 Web Hosting Advertisements & Offers 1 31-Jul-2004 04:27
Athlon system locking up on start up. Is it MoBo, Processor, PSU or what? ebolaosu Computer Hardware Forum 8 26-Feb-2004 11:19

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:10.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.