GabrielBlumenthal
12-15-2002, 12:52 PM
here are the seperate files:
common.h:
class MANAGER
{
public:
void SetInstance(HINSTANCE);
HINSTANCE GetInstance() const;
private:
HINSTANCE Instance;
};
extern MANAGER* Manager;
window.h:
class WINDOW
{
friend LRESULT CALLBACK
WindowProc(HWND,UINT,WPARAM,LPARAM);
public:
static int Run();
static void Register();
static void Unregister();
void Create(LPCTSTR);
void Show();
private:
LRESULT Destroy(HWND,UINT,WPARAM,LPARAM);
HWND Window;
};
manager.cpp:
#include <windows.h>
#include "common.h"
void MANAGER::SetInstance(HINSTANCE instance)
{
Instance = instance;
}
HINSTANCE MANAGER::GetInstance() const
{
return Instance;
}
window.cpp:
#include <windows.h>
#include "window.h"
#include "common.h"
int WINDOW::Run()
{
MSG message;
while (GetMessage(&message,NULL,0,0))
DispatchMessage(&message);
return message.wParam;
}
void WINDOW::Register()
{
WNDCLASS windowclass;
LPCSTR icon,cursor;
HBRUSH brush;
icon = MAKEINTRESOURCE(IDI_APPLICATION);
cursor = MAKEINTRESOURCE(IDC_ARROW);
brush = (HBRUSH) GetStockObject(WHITE_BRUSH);
windowclass.lpszClassName = "windowclassname";
windowclass.hInstance = Manager->GetInstance();
windowclass.lpfnWndProc = WindowProc;
windowclass.style = CS_HREDRAW | CS_VREDRAW;
windowclass.lpszMenuName = NULL;
windowclass.hIcon = LoadIcon(NULL,icon);
windowclass.hCursor = LoadCursor(NULL,cursor);
windowclass.hbrBackground = brush;
windowclass.cbClsExtra = 0;
windowclass.cbWndExtra = 4;
RegisterClass(&windowclass);
}
void WINDOW::Unregister()
{
UnregisterClass("windowclassname",
Manager->GetInstance());
}
void WINDOW::Create(LPCSTR title)
{
DWORD style = WS_OVERLAPPEDWINDOW;
HMENU menu = NULL;
HWND parent = NULL;
LPVOID params = this;
Window = CreateWindow("windowclassname",
title,
style,
0,
0,
200,
150,
parent,
menu,
Manager->GetInstance(),
params);
}
LRESULT WINDOW: http://forums.massassi.net/html/biggrin.gifestroy(HWND window,
UINT message,
WPARAM wparam,
LPARAM lparam)
{
PostQuitMessage(0);
return 0;
}
main.cpp:
#include <windows.h>
#include "window.h"
#include "common.h"
MANAGER* Manager;
int WINAPI WinMain(HINSTANCE instance,
HINSTANCE,
LPSTR,
int)
{
Manager = (MANAGER*) new MANAGER;
Manager->SetInstance(instance);
WINDOW::Register();
WINDOW window;
window.Create("Test Program");
window.Show();
return WINDOW::Run();
}
LRESULT CALLBACK WindowProc(HWND window,
UINT message,
WPARAM wparam,
LPARAM lparam)
{
if (message == WM_CREATE)
{
CREATESTRUCT* createstruct;
createstruct = (CREATESTRUCT*)lparam;
SetWindowLong(window,
0,
(LONG) (createstruct->lpCreateParams));
return 0;
}
WINDOW* object = (WINDOW*) GetWindowLong(window,0);
if (object)
{
if (message == WM_DESTROY)
return object->Destroy(window,
message,
wparam,
lparam);
}
return DefWindowProc(window,
message,
wparam,
lparam);
}
They all compile fine, but when I try to create the executable, it says:
Linking...
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall WINDOW::Show(void)" (?Show@WINDOW@@QAEXXZ)
Debug/FRAMEWORK.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
FRAMEWORK.exe - 2 error(s), 0 warning(s)
umm... the smilie in it is supposd to be a "d", the name of the function is Destroy, yeah so there you go.
[This message has been edited by GabrielBlumenthal (edited December 15, 2002).]
common.h:
class MANAGER
{
public:
void SetInstance(HINSTANCE);
HINSTANCE GetInstance() const;
private:
HINSTANCE Instance;
};
extern MANAGER* Manager;
window.h:
class WINDOW
{
friend LRESULT CALLBACK
WindowProc(HWND,UINT,WPARAM,LPARAM);
public:
static int Run();
static void Register();
static void Unregister();
void Create(LPCTSTR);
void Show();
private:
LRESULT Destroy(HWND,UINT,WPARAM,LPARAM);
HWND Window;
};
manager.cpp:
#include <windows.h>
#include "common.h"
void MANAGER::SetInstance(HINSTANCE instance)
{
Instance = instance;
}
HINSTANCE MANAGER::GetInstance() const
{
return Instance;
}
window.cpp:
#include <windows.h>
#include "window.h"
#include "common.h"
int WINDOW::Run()
{
MSG message;
while (GetMessage(&message,NULL,0,0))
DispatchMessage(&message);
return message.wParam;
}
void WINDOW::Register()
{
WNDCLASS windowclass;
LPCSTR icon,cursor;
HBRUSH brush;
icon = MAKEINTRESOURCE(IDI_APPLICATION);
cursor = MAKEINTRESOURCE(IDC_ARROW);
brush = (HBRUSH) GetStockObject(WHITE_BRUSH);
windowclass.lpszClassName = "windowclassname";
windowclass.hInstance = Manager->GetInstance();
windowclass.lpfnWndProc = WindowProc;
windowclass.style = CS_HREDRAW | CS_VREDRAW;
windowclass.lpszMenuName = NULL;
windowclass.hIcon = LoadIcon(NULL,icon);
windowclass.hCursor = LoadCursor(NULL,cursor);
windowclass.hbrBackground = brush;
windowclass.cbClsExtra = 0;
windowclass.cbWndExtra = 4;
RegisterClass(&windowclass);
}
void WINDOW::Unregister()
{
UnregisterClass("windowclassname",
Manager->GetInstance());
}
void WINDOW::Create(LPCSTR title)
{
DWORD style = WS_OVERLAPPEDWINDOW;
HMENU menu = NULL;
HWND parent = NULL;
LPVOID params = this;
Window = CreateWindow("windowclassname",
title,
style,
0,
0,
200,
150,
parent,
menu,
Manager->GetInstance(),
params);
}
LRESULT WINDOW: http://forums.massassi.net/html/biggrin.gifestroy(HWND window,
UINT message,
WPARAM wparam,
LPARAM lparam)
{
PostQuitMessage(0);
return 0;
}
main.cpp:
#include <windows.h>
#include "window.h"
#include "common.h"
MANAGER* Manager;
int WINAPI WinMain(HINSTANCE instance,
HINSTANCE,
LPSTR,
int)
{
Manager = (MANAGER*) new MANAGER;
Manager->SetInstance(instance);
WINDOW::Register();
WINDOW window;
window.Create("Test Program");
window.Show();
return WINDOW::Run();
}
LRESULT CALLBACK WindowProc(HWND window,
UINT message,
WPARAM wparam,
LPARAM lparam)
{
if (message == WM_CREATE)
{
CREATESTRUCT* createstruct;
createstruct = (CREATESTRUCT*)lparam;
SetWindowLong(window,
0,
(LONG) (createstruct->lpCreateParams));
return 0;
}
WINDOW* object = (WINDOW*) GetWindowLong(window,0);
if (object)
{
if (message == WM_DESTROY)
return object->Destroy(window,
message,
wparam,
lparam);
}
return DefWindowProc(window,
message,
wparam,
lparam);
}
They all compile fine, but when I try to create the executable, it says:
Linking...
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall WINDOW::Show(void)" (?Show@WINDOW@@QAEXXZ)
Debug/FRAMEWORK.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
FRAMEWORK.exe - 2 error(s), 0 warning(s)
umm... the smilie in it is supposd to be a "d", the name of the function is Destroy, yeah so there you go.
[This message has been edited by GabrielBlumenthal (edited December 15, 2002).]