• Advertisement

Archived

This topic is now archived and is closed to further replies.

Creating a window...

This topic is 5874 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hehe im lazy can somebody copy and paste the window procedure and winmain, i dont feel like looking it up, i dont have my old programs

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Well, I have it right infront of me, but I''m too lazy to paste it into this reply.

Share this post


Link to post
Share on other sites

  
#include<windows.h> //Windows headers


const int WINDOW_WIDTH=640;
const int WINDOW_HEIGHT=480;
const int WINDOW_X = 100;
const int WINDOW_Y = 100;
const char *WINDOW_NAME = "Dx";
const char *WINDOW_CLASS_NAME = "DirectX App";

HWND hWnd;


LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM
wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
}
return DefWindowProc(hWnd, msg, wParam,lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc; ////Fönsterklassen


//Fyll klassen

wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = WINDOW_CLASS_NAME;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW|CS_VREDRAW;


if(!(RegisterClassEx(&wc))
return 1;

hWnd = CreateWindowEx(NULL,
WINDOW_CLASS_NAME,
WINDOW_NAME,
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
WINDOW_X,WINDOW_Y,
WINDOW_WIDTH,WINDOW_HEIGHT,
NULL,NULL,
hInstance,
NULL);

if(hWnd==NULL)
return 1;


MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}


return 0;

}


*yaaawn*

sHaKaZeD

Share this post


Link to post
Share on other sites
Would this be more correct? :

  
for (;;)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message==WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}

// run game loop: yes a single frame: TODO: Make a multi-threaded version.

GameFrame();
}

Share this post


Link to post
Share on other sites
quote:
Original post by Oluseyi
Your main loop is malformed.

It''s a windows loop, not a game loop. And under normal circumstances it will end when WM_QUIT is posted and GetMessage returns 0.

Share this post


Link to post
Share on other sites

  • Advertisement