不知为什么一打开就自动关了!晕~~~~~

chenyec 2005-05-19 09:24:17
#include "winclass.h"
#include "winmaker.h"
#include "window.h"
#include "winctrl.h"

using namespace wtf;

int WINAPI WinMain (
HINSTANCE hInst, HINSTANCE hPrevInst,
LPSTR cmdParam, int cmdShow )
{
char const *className = "Windows";
WinClass winCls ( hInst, className );
winCls.Register ();
WinMaker winMak ( hInst, className );
TopCtrl topCtrl;
Window win = winMak.Create ( topCtrl, "Hello Windows" );
win.Display ( cmdShow );
MSG msg;
int status;
while ( (status = ::GetMessage ( &msg,0,0,0 )) != 0 )
{
if ( status = -1 )
return -1;
::DispatchMessage ( &msg );
}
return msg.wParam;
}



#ifndef WINCLASS_H
#define WINCLASS_H
#include <windows.h>
#include "winproc.h"

namespace wtf
{
class WinClass
{
public:
WinClass ( HINSTANCE hInst, char const *className )
{
_class.lpfnWndProc = wtf::Procedure;
_class.hInstance = hInst;
_class.lpszClassName = className;
_class.cbSize = sizeof(WNDCLASSEX);
_class.hCursor = ::LoadCursor ( 0, IDC_ARROW );
_class.hbrBackground = reinterpret_cast<HBRUSH> ( COLOR_WINDOW + 1 );
_class.style = 0;
_class.cbClsExtra = 0;
_class.cbWndExtra = 0;
_class.hIcon = 0;
_class.hIconSm = 0;
_class.lpszMenuName = 0;
}
void Register ()
{
if ( ::RegisterClassEx ( &_class ) == 0 )
throw "注册失败\n";
}
private:
WNDCLASSEX _class;
};
}

#endif //winclass.h



#ifndef WINMAKER_H
#define WINMAKER_H
#include <windows.h>
#include "winctrl.h"

namespace wtf
{
class WinMaker
{
public:
WinMaker ( HINSTANCE hInst, char const *className )
: _hInst(hInst), _className(className),
_style(WS_OVERLAPPEDWINDOW), _exStyle(0),
_x(CW_USEDEFAULT), _y(0),
_width(CW_USEDEFAULT), _height(0),
_hWndParent(0), _hMenu(0), _data(0)
{}

HWND Create ( Controller &ctrl, char const *title )
{
HWND hwnd = ::CreateWindow (
_className, title, _style,
_x, _y, _width, _height,
_hWndParent, _hMenu, _hInst, &ctrl );
if ( hwnd == 0 )
throw "创建窗口失败!\n";
return hwnd;
}
private:
HINSTANCE _hInst;
char const *_className;
DWORD _style;
DWORD _exStyle;
int _x;
int _y;
int _width;
int _height;
HMENU _hMenu;
HWND _hWndParent;
void *_data;
};
}

#endif //winmaker.h


#ifndef WINDOW_H
#define WINDOW_H
#include <windows.h>
#include <cassert>

namespace wtf
{
class Window
{
public:
Window ( HWND hwnd = 0 ) : _hwnd(hwnd) {}
void Display ( int cmdShow )
{
assert ( _hwnd != 0 );
::ShowWindow ( _hwnd, cmdShow );
::UpdateWindow ( _hwnd );
}
template <class T>
T GetLong ( int which = GWL_USERDATA )
{
return reinterpret_cast<T> (::GetWindowLong ( _hwnd, which ));
}
template <class T>
void SetLong ( T value, int which = GWL_USERDATA )
{
::SetWindowLong ( _hwnd, which, reinterpret_cast<long> ( vlaue ) );
}
private:
HWND _hwnd;
};
}

#endif //window.h


#ifndef WINCTRL_H
#define WINCTRL_H
#include <windows.h>

namespace wtf
{
class Controller
{};
class TopCtrl: public Controller
{};
}

#endif //winctrl.h



#ifndef WINPROC_H
#define WINPROC_H
#include <windows.h>

namespace wtf
{
LRESULT CALLBACK Procedure (
HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam );
}

#endif //winproc.h



#include "winproc.h"
#include "winctrl.h"
#include "window.h"
#include "winctrl.h"


LRESULT CALLBACK wtf::Procedure (
HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam )
{
//Window win(hwnd);
//Controller pCtrl = win.GetLong<Controller *> ();
switch ( message )
{
case WM_DESTROY:
{
::PostQuitMessage (0);
return 0;
}
}
return ::DefWindowProc ( hwnd, message, wParam, lParam );
}

...全文
64 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2005-06-28
  • 打赏
  • 举报
回复
关闭? 设置断点调试
xmxjh 2005-06-27
  • 打赏
  • 举报
回复
太长,没时间看……

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧