Drezard
February 20th, 2007, 09:20 PM
Hello, I'm trying to write an engine. I've almost got the win32 code working.
Okay, Heres my code:
SystemCode.h
// SystemCore.h
// Last updated: 20 Feb 2007, Drezard
#include <windows.h> // Standard windows include file
#include <windowsx.h> // Standard windows include file
#ifndef SYSTEMCORE_H // Checks if the header has already been called
#define SYSTEMCORE_H // If it hasnt then it will call it with this code
class DrezSystem; // Declare the class
static LRESULT CALLBACK AppWindowProc(HWND hWnd, // Declare a WNDPROC to handle Wm_Quit
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
static DrezSystem* g_pApp = 0; // Pointer to the class
class DrezSystem { // Class prototype
private: // Declare all the private members
WNDCLASSEX m_Wcex; // Declare our windows struct
HINSTANCE m_hInst; // Declare a variable for our programs Instance
HWND m_hWnd; // Declare a variable for our programs Handle
public: // Declare all the public members
DrezSystem(); // Constructor
~DrezSystem(); // Destructor
bool run(); // Registers the class
virtual LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
};
#endif
SystemCore.cpp
// SystemCore.cpp
// Last updated: 20 Feb 2007, Drezard
#include "SystemCore.h"
DrezSystem::DrezSystem(){ // Constructor
g_pApp = this; // Set g_aApp pointer to the class
m_hInst = GetModuleHandle(0); // Set the programs instance
m_hWnd = NULL; // Set the programs handle
m_Wcex.cbSize = sizeof(WNDCLASSEX); // Size of the windows class
m_Wcex.style = CS_CLASSDC; // Style
m_Wcex.lpfnWndProc = AppWindowProc; // No Win Proc yet
m_Wcex.cbClsExtra = 0;
m_Wcex.cbWndExtra = 0;
m_Wcex.hInstance = m_hInst; // Hinstance
m_Wcex.hIcon = LoadIcon(0, IDI_APPLICATION); // Load the icon
m_Wcex.hCursor = LoadCursor(0, IDC_ARROW); // Load the cursor
m_Wcex.hbrBackground = 0;
m_Wcex.lpszMenuName = 0;
m_Wcex.lpszClassName = L"TEST";
m_Wcex.hIconSm = LoadIcon(0, IDI_APPLICATION);
}
DrezSystem::~DrezSystem(){ // Destructor
m_hInst = NULL; // Set the programs instance (Memory Release)
m_hWnd = NULL; // Set the programs handle (Memory Release)
}
LRESULT CALLBACK AppWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY:
PostQuitMessage(true);
break;
default:
return g_pApp->MsgProc(hWnd, uMsg, wParam, lParam);
break;
}
return 0;
}
bool DrezSystem::run() { // Registers the class
if(!(RegisterClassEx(&m_Wcex))) { // If Registering the Class fails
return false; // Return false
}
UnregisterClass(L"TEST", m_hInst); // Unregister the class (Memory Release)
return true; // Return true
m_hWnd = CreateWindowEx(NULL, // Set the handle
L"TEST", // Our class
L"Our First Windowed Program", // Window title
WS_OVERLAPPEDWINDOW, // Window style
300, // X-position of the window
300, // Y-position of the window
500, // Width of the window
400, // Height of the window
NULL, // Parent Window
NULL, // Menus
m_hInst, // Application Handle
NULL); // Mutliple Windows
ShowWindow(m_hWnd, nCmdShow); // Show the Window
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
};
WinMain.cpp
#include "SystemCore.h"
#include <windows.h>
#include <windowsx.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
DrezSystem SystemClass;
SystemClass.DrezSystem();
bool SystemClass.run();
SystemClass.~DrezSystem();
}
Now, my problem with my code is... In Win32 Code u declare the variable nCmdShow in the WinMain function. Now I need to
use that variable again in my run function. How would I use that variable in my class?
- Cheers, Daniel
Okay, Heres my code:
SystemCode.h
// SystemCore.h
// Last updated: 20 Feb 2007, Drezard
#include <windows.h> // Standard windows include file
#include <windowsx.h> // Standard windows include file
#ifndef SYSTEMCORE_H // Checks if the header has already been called
#define SYSTEMCORE_H // If it hasnt then it will call it with this code
class DrezSystem; // Declare the class
static LRESULT CALLBACK AppWindowProc(HWND hWnd, // Declare a WNDPROC to handle Wm_Quit
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
static DrezSystem* g_pApp = 0; // Pointer to the class
class DrezSystem { // Class prototype
private: // Declare all the private members
WNDCLASSEX m_Wcex; // Declare our windows struct
HINSTANCE m_hInst; // Declare a variable for our programs Instance
HWND m_hWnd; // Declare a variable for our programs Handle
public: // Declare all the public members
DrezSystem(); // Constructor
~DrezSystem(); // Destructor
bool run(); // Registers the class
virtual LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
};
#endif
SystemCore.cpp
// SystemCore.cpp
// Last updated: 20 Feb 2007, Drezard
#include "SystemCore.h"
DrezSystem::DrezSystem(){ // Constructor
g_pApp = this; // Set g_aApp pointer to the class
m_hInst = GetModuleHandle(0); // Set the programs instance
m_hWnd = NULL; // Set the programs handle
m_Wcex.cbSize = sizeof(WNDCLASSEX); // Size of the windows class
m_Wcex.style = CS_CLASSDC; // Style
m_Wcex.lpfnWndProc = AppWindowProc; // No Win Proc yet
m_Wcex.cbClsExtra = 0;
m_Wcex.cbWndExtra = 0;
m_Wcex.hInstance = m_hInst; // Hinstance
m_Wcex.hIcon = LoadIcon(0, IDI_APPLICATION); // Load the icon
m_Wcex.hCursor = LoadCursor(0, IDC_ARROW); // Load the cursor
m_Wcex.hbrBackground = 0;
m_Wcex.lpszMenuName = 0;
m_Wcex.lpszClassName = L"TEST";
m_Wcex.hIconSm = LoadIcon(0, IDI_APPLICATION);
}
DrezSystem::~DrezSystem(){ // Destructor
m_hInst = NULL; // Set the programs instance (Memory Release)
m_hWnd = NULL; // Set the programs handle (Memory Release)
}
LRESULT CALLBACK AppWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY:
PostQuitMessage(true);
break;
default:
return g_pApp->MsgProc(hWnd, uMsg, wParam, lParam);
break;
}
return 0;
}
bool DrezSystem::run() { // Registers the class
if(!(RegisterClassEx(&m_Wcex))) { // If Registering the Class fails
return false; // Return false
}
UnregisterClass(L"TEST", m_hInst); // Unregister the class (Memory Release)
return true; // Return true
m_hWnd = CreateWindowEx(NULL, // Set the handle
L"TEST", // Our class
L"Our First Windowed Program", // Window title
WS_OVERLAPPEDWINDOW, // Window style
300, // X-position of the window
300, // Y-position of the window
500, // Width of the window
400, // Height of the window
NULL, // Parent Window
NULL, // Menus
m_hInst, // Application Handle
NULL); // Mutliple Windows
ShowWindow(m_hWnd, nCmdShow); // Show the Window
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
};
WinMain.cpp
#include "SystemCore.h"
#include <windows.h>
#include <windowsx.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
DrezSystem SystemClass;
SystemClass.DrezSystem();
bool SystemClass.run();
SystemClass.~DrezSystem();
}
Now, my problem with my code is... In Win32 Code u declare the variable nCmdShow in the WinMain function. Now I need to
use that variable again in my run function. How would I use that variable in my class?
- Cheers, Daniel