🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ windows and direct X SDK

Started by
2 comments, last by dannyxyz22 24 years, 4 months ago
Hello fellas. I just started programing in C++ and I can''t find a good tutorial on how I can draw a window. I used to program in VB, but it was really easier to create a window there. Could you guys help me? Please send the source code if possible. I got MS Visual Studio 6 C++. Oh, another question. Do I need a window to draw graphics using Direct X? If so, how can I download a light version of the Software Developer Kit? Thanks, and please post something or e-mail me at: dannyxyz22@zipmail.com.br See ya!
Advertisement
Open up a new windows app and add a new cpp file. The following code creates an empty window. Just look up in MSDN what each does. The main thing when creating the window is the CreateWindow() function.

#include <windows.h>

#define NAME "A window"
#define TITLE "A window"

HWND hWnd;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam){
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

ATOM MyRegisterClass(HINSTANCE hInstance){
WNDCLASS wc;

// Set up and register window class
wc.style = CS_HREDRAW / CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH )GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = NAME;
return RegisterClass(&wc);
}

static BOOL InitApp(HINSTANCE hInstance, int nCmdShow){

// Create a window

hWnd = CreateWindow(NAME,
TITLE,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
0,
hInstance,
NULL);

if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow){
MSG msg;
MyRegisterClass(hInstance);

if( FAILED( InitApp(hInstance, nCmdShow) ) )
return 0;

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}

Edited by - Nytegard on 2/27/00 1:58:58 PM

Edited by - Nytegard on 2/27/00 1:59:48 PM
To create the window and manage a window you'll need these functions:

RegisterClass()
CreateWindow() or CreateWindowEx()
WindowProc() // Actually defined by yourself but search for it in MSDN
PeekMessage()
GetMessage()
TranslateMessage()
DispatchMessage()
PostQuitMessage()

These functions are all described in the online MSDN Library that you get with VC++. I'm sorry if I didn't provide any actual source code but I'm sure someone will soon.

As for DirectX: A lite version can be downloaded here. It's 5.5 MB, with no samples.

(I'm sorry for the redundant information here. Nytegard was faster than me. )


Edited by - Spellbound on 2/27/00 1:59:30 PM
Man you''re really fast. I''ll make some tests during the week and if I have some questions, I''ll ask you (because you''re good in it ,hehe)
So, thank you all!
See ya next week!

This topic is closed to new replies.

Advertisement