![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2006
Posts: 8
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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 |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jan 2006
Location: UK
Posts: 55
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#4 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#6 | |
|
Programming Guru
![]() ![]() ![]() |
Quote:
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." |
|
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jan 2006
Posts: 8
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#10 | |
|
Professional Programmer
|
Quote:
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|