D.V.D
Make a wish
- Reaction score
- 73
So I started to read this(http://www.stromcode.com/2008/03/02/win32-basic-window-creation/) tutorial on how to create a window and use win32 API for C++. I tried using the code they wrote in my program and I was getting a lot of errors. I made a Win32 App in Visual and compared the two and tried to get some stuff to work but I still have no idea how or why some of the changes work and why others do.
For example, in the tutorial, it tells me to use the variable hInstance but visual is telling me that the variable is undeclared. WndProcedure or WndProc is also a undeclared identifier.
My other problem is szTitle and szWindowClass and MAXLOADSTRING. Im not sure why I can't just follow the tutorial and write strings. Im not really sure how to set the variables, I only know you initialize them from looking at Win32 App in Visual. How do I set these variables into the names I want? Also what is MAXLOADSTRINGS?
The last problem I have is using CreateWindowEx. Visual is telling me the second parameter needs to be LPCWSTR which I have no idea what that is or why its telling me that. How do I fix it?
(I created my code in a console application)
Code:
For example, in the tutorial, it tells me to use the variable hInstance but visual is telling me that the variable is undeclared. WndProcedure or WndProc is also a undeclared identifier.
My other problem is szTitle and szWindowClass and MAXLOADSTRING. Im not sure why I can't just follow the tutorial and write strings. Im not really sure how to set the variables, I only know you initialize them from looking at Win32 App in Visual. How do I set these variables into the names I want? Also what is MAXLOADSTRINGS?
The last problem I have is using CreateWindowEx. Visual is telling me the second parameter needs to be LPCWSTR which I have no idea what that is or why its telling me that. How do I fix it?
(I created my code in a console application)
Code:
Code:
// Create Engine.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
// Win32 Libraries
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];
int _tmain(int argc, _TCHAR* argv[]) {
return 0;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
char * cmdParam, int cmdShow);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
char * cmdParam, int cmdShow) {
// Window Class
WNDCLASSEX GameWindow; // Populate the WNDCLASSEX structure
GameWindow.cbSize = sizeof(WNDCLASSEX); // always set to size of WNDCLASSEX or WNDCLASS depending which you use
GameWindow.style =CS_HREDRAW | CS_VREDRAW; // designates when that the window is resized horizontally and vertically
GameWindow.lpfnWndProc = WndProcedure; // pointer to the start of the windows message handler
GameWindow.cbClsExtra = 0;
GameWindow.cbWndExtra = 0;
GameWindow.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Window icon
GameWindow.hCursor = LoadCursor(NULL, IDC_ARROW); // Window cursor
GameWindow.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // Color of the background
GameWindow.lpszMenuName = NULL;
GameWindow.lpszClassName = szWindowClass; // unique name to the window class. Used when we call CreateWindow(Ex) to tell the function which window class we want an object instance of
GameWindow.hInstance = hInstance;// the handle to the instance of your app. This is given to your WinMain function and is passed there
GameWindow.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// Register the class
RegisterClassEx(&GameWindow);
// HWND is a handle to a window object
// We have a opportunity to chose window style and to add a menu.
HWND hWnd = CreateWindow("GameWindow", // Choses my window class
szTitle, // Gives a title to the window
WS_OVERLAPPEDWINDOW, // Sets a window style. If window style is WS_VISIBLE, window is shown noramlly
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
// Show the Window
ShowWindow(hWnd, SW_SHOWNORMAL); // Second parameter is a style to show the window
UpdateWindow(hWnd);
return 0;
}