Creating a window
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
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.
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.
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
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
Add this right after where you create the window:
Regards Mats
ShowWindow(hwnd, nCmdShow);UpdateWindow(hwnd);
Regards Mats
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement