-
What is my window?
I'm trying to make a template of a window using functions, making it more efficient. I still have these two errors in which I cannot figure out what is wrong.
Code:
#include "window.h"
RECT windowRect = {100, 100, 400, 400};
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
void MakeWindow(HINSTANCE hInstance, char * className, char * title, int iCmdShow);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
MakeWindow(hInstance,"Windows Class","Title",iCmdShow);
}
void MakeWindow(HINSTANCE hInstance, char * className, char * title, int iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wndClass;
wndClass.cbSize = sizeof(wndClass);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = className;
RegisterClassEx (&wndClass);
hWnd = CreateWindow(title,wndClass,WS_OVERLAPPEDWINDOW,windowRect.left,windowRect.top,windowRect.right,windowRect.bottom,NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,iCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClassEx(wndClass,hInstance);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch(iMsg)
{
case WM_CLOSE:
case WM_QUIT:
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
-
First of all you should include the correct header file. The proper way of doing this is:
Code:
#include <windows.h>
Next you should post the actual errors you are getting so that we can help you.
-
ok well right of the bat I can tell you that you are mixing up your datatypes and functions which is no doubt causing you problems:
Code:
WNDCLASSEX wndClass;
// . . .
RegisterClassEx (&wndClass);
// . . . .
hWnd = CreateWindow(// . . .should be CreatWindowEx
// . . .
UnregisterClassEx //doesn't exist, should be UnregisterClass
Maybe that will help you.
-
Errors:
The "window.h" is where you would include everything because this is supposed to be a template.
The errors I get are:
1. win_main.cpp(31): error C2664: 'CreateWindowExA' : cannot convert parameter 3 from 'WNDCLASSEX' to 'LPCSTR'
2. win_main.cpp(39): error C3861: 'UnregisterClassEx': identifier not found, even with argument-dependent lookup
For other information the contents of 'window.h' are:
Code:
#include <windows.h>
#include <iostream>
-
Look at the post above. Either stick with WNDCLASS, RegisterClass and CreateWindow or do WNDCLASSEX, RegisterClassEx and CreateWindowEX.
-
Thank You
Yeah that worked. Thanks.