//file app.h
#if !defined(__APP_H)
#define __APP_H
#include<windows.h>
#include<string>
class CFWnd
{
static LRESULT CALLBACK xWndProc(HWND,int,WPARAM,LPARAM);
friend class CFWndClass;
HWND hWnd;
class CFWndClass

ublic WNDCLASS
{
friend class CFWnd;
bool isRegistered;
std::string sName;
public:
CFWndClass(char* name="name"

{
sName=name;
int* x=new int;
*x=100;
cbClsExtra=0;
cbWndExtra=0;
hbrBackground=(HBRUSH)1;
hCursor=LoadCursor(0,IDC_ARROW);
hIcon=LoadIcon(0,IDI_APPLICATION);
hInstance=GetModuleHandle(0);
lpfnWndProc=(WNDPROC)xWndProc;
lpszClassName=sName.begin();
lpszMenuName=0;
style=CS_HREDRAW|CS_VREDRAW;
//RegisterClass(this);
}
CFWndClass& Create();
};
CFWndClass cfWndCls;
bool isInitialized;
public:
CFWnd():isInitialized(false){}
virtual ~CFWnd(){}
virtual void initialize(){}
virtual bool WndProc(HWND,int,WPARAM,LPARAM);
operator HWND(){return hWnd;}
CFWnd& Create();
void test(){MessageBox(0,"hello people","",0);}
void show(int nCmdShow = SW_SHOW)
{
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
}
};
#endif
//end of app.h
////////////////////////////////////////////////
////////////////////////////////////////////////
//app.cpp
#include<windows.h>
#include"app.h"
#include<string>
#include<strstream>
using namespace std;
CFWnd& CFWnd::Create()
{
CFWndClass x;
RegisterClass(&cfWndCls);
hWnd=CreateWindow(cfWndCls.sName.c_str(),
cfWndCls.sName.c_str(),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
0,0,GetModuleHandle(0),0);
SetWindowLong(hWnd,GWL_USERDATA,(long)this);
return *this;
}
bool CFWnd::WndProc(HWND,int,WPARAM,LPARAM)
{
return true;
}
LRESULT CALLBACK CFWnd::xWndProc(HWND hWnd,int message,WPARAM wParam,LPARAM lParam)
{
ostrstream xxx;
CFWnd* x=(CFWnd*)GetWindowLong(hWnd,GWL_USERDATA);
if(x==0)
{
return DefWindowProc(hWnd,message,wParam,lParam);
}
if(!x->isInitialized)
{
x->initialize();
x->isInitialized = true;
}
switch(message)
{
case WM_CREATE:
MessageBox(0,"","",0);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
if(!x->WndProc(hWnd,message,wParam,lParam))
{
return 0;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}
//end of app.cpp
//test.cpp
#include "app.h"
int main()
{
CFWnd xx;
xx.Create();
xx.show();
MSG* msg = new MSG;
while(GetMessage(msg,0,0,0))
{
TranslateMessage(msg);
DispatchMessage(msg);
}
return 0;
} John Fill
ivfmd@mail.md