Archived

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

Creating a window

This topic is 5656 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

Yes I''am trying to learn win32 and directX programming with the game programming genesis. But I got a small problem with the first lesson. I''recieve no errors or warnings but the window only blinks one time an the program ends. If you can help me thanks. here''s the code: #include <stdio.h> #include <windows.h> #include <windowsx.h> #define WIN32_LEAN_AND_MEAN LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); // denk aan het leveren van een functie prototype int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdline, int nCmdShow) { MSG msg; WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = MsgHandler; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hinstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "wc"; wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO); RegisterClassEx(&wc); HWND hwnd; if(!(hwnd = CreateWindowEx( NULL, "wc", "Mijn eerste venster", WS_POPUP |WS_VISIBLE, 0, 0, 320, 240, NULL, NULL, hinstance, NULL))) if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { return(DefWindowProc(hwnd, msg, wparam, lparam)); } ________________ end code thanks for all your help. Christianen

Share this post


Link to post
Share on other sites
The only problem that I see is that there is no loops so the program just runs once and exits. Try this

while(1)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam

and another thing you put in the CreateWindowEx function WS_POPUP this will make the window have no buttons,try putting
WS_OVERLAPPEDWINDOW.

Share this post


Link to post
Share on other sites
Ok, I''am sorry to boder you again but a
changed the code and infortunately the result
remains the same. Here you have the new code
To look what (the f****) I have don wrong.


CODE:


#include <stdio.h>
#include <windows.h>
#include <windowsx.h>

#define WIN32_LEAN_AND_MEAN

LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
// denk aan het leveren van een functie prototype




int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdline, int nCmdShow)


{

MSG msg;
WNDCLASSEX wc;

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MsgHandler;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "wc";
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

RegisterClassEx(&wc);

HWND hwnd;

if(!(hwnd = CreateWindowEx( NULL,
"wc",
"Mjn eerste venster",
WS_OVERLAPPEDWINDOW |WS_VISIBLE,
// denk hierbij aan de verschilende mogelijkheden van stijl naar
// het venster toe.
70, 120, 320, 240,
NULL,
NULL,
hinstance,
NULL)))




do
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}while(msg.message != WM_QUIT);

return msg.wParam;

}


LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{

return(DefWindowProc(hwnd, msg, wparam, lparam));
}


__________________________
END CODE


So again thanks for all of your help.

Christianen

Share this post


Link to post
Share on other sites