最近在翻资料的时候,尝试了用 ATL (active template library) 的方法,来写 GUI 窗口,是以 C++ 方式控制,但没有 MFC 的负累和慢速 (微软自称ATL 和 MFC 的最大分别,是 ATL 快很多,它是 light weight 的窗口 class 封装)
希望没有试过的兄弟玩玩 (大侠们请略过)
(VC 中建立一般 Win32 SDK 程序,不要选 ATL/COM)
#include <windows.h>
#include <atlbase.h>
extern CComModule _Module;
#include <atlwin.h>
CComModule _Module;
class CMyWindow : public CWindowImpl<CMyWindow> {
BEGIN_MSG_MAP( CMyWindow )
MESSAGE_HANDLER( WM_PAINT, OnPaint )
MESSAGE_HANDLER( WM_DESTROY, OnDestroy )
END_MSG_MAP()
LRESULT OnPaint( UINT, WPARAM, LPARAM, BOOL& ){
PAINTSTRUCT ps;
HDC hDC = GetDC();
BeginPaint( &ps );
TextOut( hDC, 0, 0, _T("Hello world"), 11 );
EndPaint( &ps );
return 0;
}
LRESULT OnDestroy( UINT, WPARAM, LPARAM, BOOL& ){
PostQuitMessage( 0 );
return 0;
}
};
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int )
{
_Module.Init( NULL, hInstance );
CMyWindow wnd;
wnd.Create( NULL, CWindow::rcDefault, _T("Hello"),
WS_OVERLAPPEDWINDOW|WS_VISIBLE );
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) ){
TranslateMessage( &msg );
DispatchMessage( &msg );
}
_Module.Term();
return msg.wParam;
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvc60/html/atlwindow.asp
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!