Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 9th, 2006, 6:13 PM   #1
DeLoRtEd1
Newbie
 
Join Date: Jan 2006
Posts: 8
Rep Power: 0 DeLoRtEd1 is on a distinguished road
Hello World! Help

Hi!
Anyways, here's my problem. My class at school is making a "Robot wars game", where we make the engine, then we design our robots (which aren't real, they are just blips on the screen) in the way we want. My job though, is to create the grid for the screen. I really want it in a real window, and not just by using cout's. The only thing that is close to what I want is the typical hello world application, but I want that line of text deleted, and a bitmap that fills the screen (the 10x10 grid, or whatever would fit the screen dimensions) How would I do this? Or can someone do it for me with detailed comments? I'm still pretty shaky on hwnd's and hinstances... or whatever. If you did it for me, I would still be learning a lot.
Hopefully this isn't asking too much. Thanks!
-del
DeLoRtEd1 is offline   Reply With Quote
Old Feb 9th, 2006, 6:21 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
If you're going to be using the Windows API I would suggest reading a couple of tutorials. A very simple hello world program would be easy, just a dialog box popping up saying hello world. But if you want to make an actual window and stuff, just the skeleton is pretty complex the first time you look at it. There will be concepts that you might not be familiar with, and therefore writing a program like that, even with comments, probably won't do much good. Believe it or not, that simple of a program is probably 60 or 70+ lines of code.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Feb 9th, 2006, 7:15 PM   #3
AICkieran
Programmer
 
Join Date: Jan 2006
Location: UK
Posts: 55
Rep Power: 3 AICkieran is on a distinguished road
wxWidgets might be handy, wxBitmap to display the bitmap theres alot of other useful stuff (I havent actually used WxWidgets but ive read through the docs and such and its been reccomended to me, This is just my (uneducated) opinion)

http://www.wxwidgets.org/manuals/2.6....html#classref
AICkieran is offline   Reply With Quote
Old Feb 9th, 2006, 7:17 PM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
All of the drawing would likely be wrapped up in the repaint handler. Using a back buffer would be a waste of memory in this case.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Feb 10th, 2006, 4:51 AM   #5
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Search for some tutorials on GDI, which you can use in your WM_PAINT message.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Feb 10th, 2006, 7:27 AM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Quote:
If you did it for me, I would still be learning a lot.
How do you figure that?

Try this tutorial: http://www.functionx.com/win32/index.htm
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Feb 10th, 2006, 7:33 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
LmAo. iN aDdItIoN tO rEaDiNg TuToRiAlS, i WoUlD sUgGeSt ReAdInG tHe FoRuM fAq/RuLeS rEgArDiNg HoMeWoRk.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 10th, 2006, 3:49 PM   #8
DeLoRtEd1
Newbie
 
Join Date: Jan 2006
Posts: 8
Rep Power: 0 DeLoRtEd1 is on a distinguished road
It's not homework, my teacher / classmates just keep telling me to make it in a DOS program (and I'd like to try and stray away from DOS) where I just draw an ascii grid with cout's, which I can do with my eyes closed. So basically, if someone actually did this (in response to post above) with comments explaining each line, I would still pick up some things about this kind of coding, which is what I'd like to learn outside of class.
DeLoRtEd1 is offline   Reply With Quote
Old Feb 10th, 2006, 4:56 PM   #9
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
If only people read...
/* Includes */
#include <windows.h>

/* Global variables */
const char *clsName = "BasicApp";
const char *wndName = "A Simple Window";

/* Prototypes */
LRESULT CALLBACK WndProcedure(HWND, UINT, WPARAM, LPARAM);

/* Starting point */
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	MSG        msg;
	HWND       hwnd;
	WNDCLASSEX wcx;

	/* Create the application window */
	wcx.cbSize        = sizeof(WNDCLASSEX);
	wcx.style         = CS_HREDRAW | CS_VREDRAW;
	wcx.lpfnWndProc   = WndProcedure;
	wcx.cbClsExtra    = 0;
	wcx.cbWndExtra    = 0;
	wcx.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
	wcx.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wcx.lpszMenuName  = NULL;
	wcx.lpszClassName = clsName;
	wcx.hInstance     = hInstance;
	wcx.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

	/* Register the application */
	if(!RegisterClassEx(&wcx))
	{
		MessageBox(NULL, "RegisterClassEx Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
		return 1;
  	}

	/* Create the window */
	hwnd = CreateWindow(clsName,
			  wndName,
			  WS_OVERLAPPEDWINDOW,
			  CW_USEDEFAULT,
			  CW_USEDEFAULT,
			  CW_USEDEFAULT,
			  CW_USEDEFAULT,
			  NULL,
			  NULL,
			  hInstance,
			  NULL);

	/* If creating failed */
	if(!hwnd)
	{
	      MessageBox(NULL, "CreateWindow Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
	      return 1;
  	}

	ShowWindow(hwnd, SW_SHOWNORMAL);
	UpdateWindow(hwnd);

	/* Message loop */
	while(GetMessage(&msg, NULL, 0, 0))
	{
             TranslateMessage(&msg);
             DispatchMessage(&msg);
	}

	return (int)msg.wParam;
}

/* Window Procedure */
LRESULT CALLBACK WndProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	int numxlines = 0, numylines = 0;
	PAINTSTRUCT ps;
	HDC hdc;

    switch(msg)
    {
		case WM_PAINT:
			hdc = BeginPaint(hwnd, &ps);

			for(int x = 20; numxlines < 20; x += 20, numxlines++)
			{
				MoveToEx(hdc, 60, x, NULL);
				LineTo(hdc, 460, x);
			}

			for(int y = 60; numylines <= 20; y += 20, numylines++)
			{
				MoveToEx(hdc, y, 20, NULL);
				LineTo(hdc, y, 400);
			}

			EndPaint(hwnd, &ps);
			break;

		case WM_DESTROY:
			PostQuitMessage(1);
			break;

		default:
			return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Feb 10th, 2006, 5:18 PM   #10
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
Quote:
Originally Posted by DaWei
LmAo. iN aDdItIoN tO rEaDiNg TuToRiAlS, i WoUlD sUgGeSt ReAdInG tHe FoRuM fAq/RuLeS rEgArDiNg HoMeWoRk.
Hahahahaha!!!
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC