Archive for the ‘Win32 GUI’ Category
-
Hello, Win32 GUI(WTL) World!
Posted on 7月 4th, 2012 by cx20
Win32 GUI(WTL)
Win32 アプリケーションは Windows 標準 API である Win32 API を使用した Windows アプリケーションである。
以下は VC++(WTL) における Win32 GUI アプリケーション の例となっている。ソースコード
#include <atlbase.h> #include <atlapp.h> #include <atlcrack.h> class CHelloWindow : public CWindowImpl<CHelloWindow> { BEGIN_MSG_MAP( CHelloWindow ) MSG_WM_PAINT ( OnPaint ) MSG_WM_DESTROY ( OnDestroy ) END_MSG_MAP() void OnPaint( HDC hDC ) { CPaintDC dc( m_hWnd ); LPCTSTR lpszMessage = _T("Hello, Win32 GUI(WTL) World!"); dc.TextOut( 0, 0, lpszMessage, lstrlen(lpszMessage) ); } void OnDestroy() { PostQuitMessage( 0 ); } }; CAppModule _Module; int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { _Module.Init(NULL, hInstance); CMessageLoop theLoop; _Module.AddMessageLoop(&theLoop); CHelloWindow wnd; wnd.Create( NULL, CWindow::rcDefault, _T("Hello, World!"), WS_OVERLAPPEDWINDOW | WS_VISIBLE ); wnd.ResizeClient( 640, 480 ); int nRet = theLoop.Run(); _Module.RemoveMessageLoop(); _Module.Term(); return nRet; }
コンパイル方法
C:¥> SET INCLUDE=<WTL>Include;%INCLUDE C:¥> cl hello.cpp
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Win32 GUI(WTL) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Win32 GUI(ATL) World!
Posted on 7月 3rd, 2012 by cx20
Win32 GUI(ATL)
Win32 アプリケーションは Windows 標準 API である Win32 API を使用した Windows アプリケーションである。
以下は VC++(ATL) における Win32 GUI アプリケーション の例となっている。ソースコード
#include <atlbase.h> #include <atlwin.h> class CHelloWindow : public CWindowImpl<CHelloWindow> { BEGIN_MSG_MAP( CHelloWindow ) MESSAGE_HANDLER( WM_PAINT, OnPaint ) MESSAGE_HANDLER( WM_DESTROY, OnDestroy ) END_MSG_MAP() LRESULT OnPaint( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) { PAINTSTRUCT ps; HDC hDC = GetDC(); LPCTSTR lpszMessage = _T("Hello, Win32 GUI(C++) World!"); BeginPaint( &ps ); TextOut( hDC, 0, 0, lpszMessage, lstrlen(lpszMessage) ); EndPaint( &ps ); return 0; } LRESULT OnDestroy( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) { PostQuitMessage( 0 ); return 0; } }; CComModule _Module; int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { _Module.Init(NULL, hInstance); CHelloWindow wnd; wnd.Create( NULL, CWindow::rcDefault, _T("Hello, World!"), WS_OVERLAPPEDWINDOW | WS_VISIBLE ); wnd.ResizeClient( 640, 480 ); MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ){ TranslateMessage( &msg ); DispatchMessage( &msg ); } _Module.Term(); return msg.wParam; }
コンパイル方法
C:¥> cl hello.cpp
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Win32 GUI(ATL) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Win32 GUI(C++) World!
Posted on 7月 2nd, 2012 by cx20
Win32 GUI(C++)
Win32 アプリケーションは Windows 標準 API である Win32 API を使用した Windows アプリケーションである。
以下は C++ における Win32 GUI アプリケーション の例となっている。ソースコード
#include <windows.h> #include <tchar.h> LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; LPCTSTR lpszMessage = _T("Hello, Win32 GUI(C++) World!"); switch (message) { case WM_PAINT: hdc = BeginPaint( hWnd, &ps ); TextOut( hdc, 0, 0, lpszMessage, lstrlen(lpszMessage) ); EndPaint( hWnd, &ps ); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LPCTSTR lpszClassName = _T("helloWindow"); LPCTSTR lpszWindowName = _T("Hello, World!"); WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = lpszClassName; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); RegisterClassEx(&wcex); HWND hWnd = CreateWindow( lpszClassName, lpszWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL ); ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; }
コンパイル方法
C:¥> cl hello.cpp /link user32.lib gdi32.lib /SUBSYSTEM:WINDOWS
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Win32 GUI(C++) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Win32 GUI(C言語) World!
Posted on 7月 1st, 2012 by cx20
Win32 GUI(C言語)
Win32 アプリケーションは Windows 標準 API である Win32 API を使用した Windows アプリケーションである。
以下は C言語 における Win32 GUI アプリケーション の例となっている。ソースコード
#include <windows.h> #include <tchar.h> LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; LPCTSTR lpszMessage = _T("Hello, Win32 GUI World!"); switch (message) { case WM_PAINT: hdc = BeginPaint( hWnd, &ps ); TextOut( hdc, 0, 0, lpszMessage, lstrlen(lpszMessage) ); EndPaint( hWnd, &ps ); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LPCTSTR lpszClassName = _T("helloWindow"); LPCTSTR lpszWindowName = _T("Hello, World!"); WNDCLASSEX wcex; HWND hWnd; MSG msg; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = lpszClassName; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); RegisterClassEx(&wcex); hWnd = CreateWindow( lpszClassName, lpszWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL ); ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; }
コンパイル方法
C:¥> cl hello.c /link user32.lib gdi32.lib /SUBSYSTEM:WINDOWS
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Win32 GUI World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+