Initializing a Window
Hello,
Could anyone tell me what''s wrong with this?
Cheers,
Wilben
static char szClass[] = "WinClass";
static char szCaption[] = "WinCode";
HINSTANCE hInstance;
int nCmdShow;
int ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
SetUpWindow(void)
{
wc.style = CS_HREDRAW / CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpszClassName = szClass;
wc.lpszMenuName = NULL;
return 0;
}
I''m not sure...you never actually create a window here....but also usually the hInstance and nCmdShow are passed through WinMain, so I''m not sure why you declared your own...please be more specific, what''s it supposed to do, or maybe just more code, cause taken out of context (as it is) this code doesn''t make sense(to me at least =) )
Chris
Also, you''re not declaring wc (I''m assuming it''s WNDCLASS and not WNDCLASSEX?). wc.lpfnWndProc is being left out in either case. And I assume you''re calling RegisterClass() somewhere after this?
Just a wee bit more code and a description of the actual problem would be helpful.
Just a wee bit more code and a description of the actual problem would be helpful.
Hello,
I''m aiming to create some header files that will speed up development time to enter in a competition. Here is my code, in it''s entirety, called WPWin.h. I made my own Cmd and hInstance like that because I thought that was how you did it!
#include
WNDCLASS wc;
HRESULT Wval;
static char szClass[] = "WinClass";
static char szCaption[] = "WinCode";
HINSTANCE hInstance;
int nCmdShow;
int ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
SetUpWindow(void)
{
wc.style = CS_HREDRAW / CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpszClassName = szClass;
wc.lpszMenuName = NULL;
return 0;
}
InitWindow(void)
{
hWnd=CreateWindow(szClass, szCaption, WS_VISIBLE/WS_POPUP,
0, 0, ScreenWidth, ScreenHeight, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return 0;
}
Wilben
wilben@nerdy.freeserve.co.uk
I''m aiming to create some header files that will speed up development time to enter in a competition. Here is my code, in it''s entirety, called WPWin.h. I made my own Cmd and hInstance like that because I thought that was how you did it!
#include
WNDCLASS wc;
HRESULT Wval;
static char szClass[] = "WinClass";
static char szCaption[] = "WinCode";
HINSTANCE hInstance;
int nCmdShow;
int ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
SetUpWindow(void)
{
wc.style = CS_HREDRAW / CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpszClassName = szClass;
wc.lpszMenuName = NULL;
return 0;
}
InitWindow(void)
{
hWnd=CreateWindow(szClass, szCaption, WS_VISIBLE/WS_POPUP,
0, 0, ScreenWidth, ScreenHeight, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return 0;
}
Wilben
wilben@nerdy.freeserve.co.uk
1. You don''t register your window class in SetupWindow(). Do this with RegisterClass( &wc ).
2. You don''t specify the return type of your functions. This will force the compiler to assume one, usually ''int''.
3. Don''t implement your functions in the header file, only specify their prototype, for example ''int SetupWindow();''. Implement the function in a separate .cpp module. Otherwise the compiler will give you errors saying that the function has already been implementet (if you include the header file in more than one file).
4. It''s always good to have some error checking code, for example ''if( hWnd == NULL ) return E_FAIL;''
2. You don''t specify the return type of your functions. This will force the compiler to assume one, usually ''int''.
3. Don''t implement your functions in the header file, only specify their prototype, for example ''int SetupWindow();''. Implement the function in a separate .cpp module. Otherwise the compiler will give you errors saying that the function has already been implementet (if you include the header file in more than one file).
4. It''s always good to have some error checking code, for example ''if( hWnd == NULL ) return E_FAIL;''
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement