-
Hello, DirectX(MASM) World!
Posted on 7月 27th, 2012 by cx20
Win32 DirectX(MASM)
DirectX はマイクロソフトが Wnidows 用に開発したマルチメディア処理用 API である。
以下は MSAM における DirectX アプリケーション の例となっている。ソースコード
; Listing generated by Microsoft (R) Optimizing Compiler Version 14.00.50727.762 TITLE hello.c .686P .XMM include listing.inc .model flat INCLUDELIB LIBCMT INCLUDELIB OLDNAMES PUBLIC _g_pD3D PUBLIC _g_pd3dDevice PUBLIC _g_pd3dFont PUBLIC _g_rect _BSS SEGMENT _g_pD3D DD 01H DUP (?) _g_pd3dDevice DD 01H DUP (?) _g_pd3dFont DD 01H DUP (?) _g_rect DB 010H DUP (?) _BSS ENDS _DATA SEGMENT $SG94060 DB 082H, 'l', 082H, 'r ', 083H, 'S', 083H, 'V', 083H, 'b', 083H DB 'N', 00H ORG $+2 $SG94064 DB 'Hello, DirectX(MASM) World!', 00H $SG94084 DB 'Hello, DirectX(MASM) World!', 00H $SG94116 DB 'helloWindow', 00H $SG94118 DB 'Hello, World!', 00H _DATA ENDS PUBLIC _InitD3D EXTRN _Direct3DCreate9@4:PROC ; Function compile flags: /Odtp _TEXT SEGMENT _d3dpp$ = -60 ; size = 56 _hr$ = -4 ; size = 4 _hWnd$ = 8 ; size = 4 _InitD3D PROC ; File hello.c ; Line 17 push ebp mov ebp, esp sub esp, 60 ; 0000003cH ; Line 20 push 32 ; 00000020H call _Direct3DCreate9@4 mov DWORD PTR _g_pD3D, eax ; Line 21 cmp DWORD PTR _g_pD3D, 0 jne SHORT $LN2@InitD3D ; Line 23 mov eax, -2147467259 ; 80004005H jmp $LN3@InitD3D $LN2@InitD3D: ; Line 26 mov DWORD PTR _d3dpp$[ebp], 0 ; Line 27 mov DWORD PTR _d3dpp$[ebp+4], 0 ; Line 28 mov DWORD PTR _d3dpp$[ebp+8], 0 ; Line 29 mov DWORD PTR _d3dpp$[ebp+12], 0 ; Line 30 mov DWORD PTR _d3dpp$[ebp+16], 0 ; Line 31 mov DWORD PTR _d3dpp$[ebp+20], 0 ; Line 32 mov DWORD PTR _d3dpp$[ebp+24], 1 ; Line 33 mov DWORD PTR _d3dpp$[ebp+28], 0 ; Line 34 mov DWORD PTR _d3dpp$[ebp+32], 1 ; Line 35 mov DWORD PTR _d3dpp$[ebp+36], 0 ; Line 36 mov DWORD PTR _d3dpp$[ebp+40], 0 ; Line 37 mov DWORD PTR _d3dpp$[ebp+44], 0 ; Line 38 mov DWORD PTR _d3dpp$[ebp+48], 0 ; Line 39 mov DWORD PTR _d3dpp$[ebp+52], 0 ; Line 49 push OFFSET _g_pd3dDevice lea eax, DWORD PTR _d3dpp$[ebp] push eax push 32 ; 00000020H mov ecx, DWORD PTR _hWnd$[ebp] push ecx push 1 push 0 mov edx, DWORD PTR _g_pD3D push edx mov eax, DWORD PTR _g_pD3D mov ecx, DWORD PTR [eax] mov edx, DWORD PTR [ecx+64] call edx mov DWORD PTR _hr$[ebp], eax ; Line 51 cmp DWORD PTR _hr$[ebp], 0 jge SHORT $LN1@InitD3D ; Line 53 mov eax, -2147467259 ; 80004005H jmp SHORT $LN3@InitD3D $LN1@InitD3D: ; Line 56 xor eax, eax $LN3@InitD3D: ; Line 57 mov esp, ebp pop ebp ret 0 _InitD3D ENDP _TEXT ENDS PUBLIC _Cleanup PUBLIC __$ArrayPad$ PUBLIC _InitFont EXTRN _D3DXCreateFontIndirectA@12:PROC EXTRN __imp__lstrcpyA@8:PROC EXTRN ___security_cookie:DWORD EXTRN @__security_check_cookie@4:PROC ; Function compile flags: /Odtp _TEXT SEGMENT _hr$ = -64 ; size = 4 _lf$ = -60 ; size = 56 __$ArrayPad$ = -4 ; size = 4 _InitFont PROC ; Line 60 push ebp mov ebp, esp sub esp, 64 ; 00000040H mov eax, DWORD PTR ___security_cookie xor eax, ebp mov DWORD PTR __$ArrayPad$[ebp], eax ; Line 64 mov DWORD PTR _lf$[ebp], 16 ; 00000010H ; Line 65 mov DWORD PTR _lf$[ebp+4], 0 ; Line 66 mov DWORD PTR _lf$[ebp+8], 0 ; Line 67 mov DWORD PTR _lf$[ebp+12], 1 ; Line 68 mov DWORD PTR _lf$[ebp+16], 0 ; Line 69 mov BYTE PTR _lf$[ebp+20], 128 ; 00000080H ; Line 70 mov BYTE PTR _lf$[ebp+21], 7 ; Line 71 mov BYTE PTR _lf$[ebp+22], 2 ; Line 72 mov BYTE PTR _lf$[ebp+23], 49 ; 00000031H ; Line 73 push OFFSET $SG94060 lea eax, DWORD PTR _lf$[ebp+24] push eax call DWORD PTR __imp__lstrcpyA@8 ; Line 75 push OFFSET _g_pd3dFont lea ecx, DWORD PTR _lf$[ebp] push ecx mov edx, DWORD PTR _g_pd3dDevice push edx call _D3DXCreateFontIndirectA@12 mov DWORD PTR _hr$[ebp], eax ; Line 76 cmp DWORD PTR _hr$[ebp], 0 jge SHORT $LN2@InitFont ; Line 78 call _Cleanup ; Line 79 mov eax, DWORD PTR _hr$[ebp] jmp SHORT $LN3@InitFont $LN2@InitFont: ; Line 90 push -1 push 1056 ; 00000420H push OFFSET _g_rect push -1 push OFFSET $SG94064 push 0 mov eax, DWORD PTR _g_pd3dFont push eax mov ecx, DWORD PTR _g_pd3dFont mov edx, DWORD PTR [ecx] mov eax, DWORD PTR [edx+56] call eax mov DWORD PTR _hr$[ebp], eax ; Line 92 cmp DWORD PTR _hr$[ebp], 0 jge SHORT $LN1@InitFont ; Line 94 call _Cleanup ; Line 95 mov eax, DWORD PTR _hr$[ebp] jmp SHORT $LN3@InitFont $LN1@InitFont: ; Line 98 mov eax, DWORD PTR _hr$[ebp] $LN3@InitFont: ; Line 99 mov ecx, DWORD PTR __$ArrayPad$[ebp] xor ecx, ebp call @__security_check_cookie@4 mov esp, ebp pop ebp ret 0 _InitFont ENDP ; Function compile flags: /Odtp _Cleanup PROC ; Line 102 push ebp mov ebp, esp ; Line 103 cmp DWORD PTR _g_pd3dFont, 0 je SHORT $LN3@Cleanup ; Line 105 mov eax, DWORD PTR _g_pd3dFont push eax mov ecx, DWORD PTR _g_pd3dFont mov edx, DWORD PTR [ecx] mov eax, DWORD PTR [edx+8] call eax $LN3@Cleanup: ; Line 108 cmp DWORD PTR _g_pd3dDevice, 0 je SHORT $LN2@Cleanup ; Line 110 mov ecx, DWORD PTR _g_pd3dDevice push ecx mov edx, DWORD PTR _g_pd3dDevice mov eax, DWORD PTR [edx] mov ecx, DWORD PTR [eax+8] call ecx $LN2@Cleanup: ; Line 113 cmp DWORD PTR _g_pD3D, 0 je SHORT $LN4@Cleanup ; Line 115 mov edx, DWORD PTR _g_pD3D push edx mov eax, DWORD PTR _g_pD3D mov ecx, DWORD PTR [eax] mov edx, DWORD PTR [ecx+8] call edx $LN4@Cleanup: ; Line 117 pop ebp ret 0 _Cleanup ENDP _TEXT ENDS PUBLIC __real@3f800000 PUBLIC _Render EXTRN __fltused:DWORD ; COMDAT __real@3f800000 CONST SEGMENT __real@3f800000 DD 03f800000r ; 1 ; Function compile flags: /Odtp CONST ENDS _TEXT SEGMENT _Render PROC ; Line 120 push ebp mov ebp, esp ; Line 121 cmp DWORD PTR _g_pd3dDevice, 0 jne SHORT $LN3@Render ; Line 123 jmp $LN4@Render $LN3@Render: ; Line 126 cmp DWORD PTR _g_pd3dFont, 0 jne SHORT $LN2@Render ; Line 128 jmp $LN4@Render $LN2@Render: ; Line 139 push 0 push ecx fld1 fstp DWORD PTR [esp] push -16776961 ; ff0000ffH push 1 push 0 push 0 mov eax, DWORD PTR _g_pd3dDevice push eax mov ecx, DWORD PTR _g_pd3dDevice mov edx, DWORD PTR [ecx] mov eax, DWORD PTR [edx+172] call eax ; Line 141 mov ecx, DWORD PTR _g_pd3dDevice push ecx mov edx, DWORD PTR _g_pd3dDevice mov eax, DWORD PTR [edx] mov ecx, DWORD PTR [eax+164] call ecx test eax, eax jl SHORT $LN1@Render ; Line 151 push -1 push 32 ; 00000020H push OFFSET _g_rect push -1 push OFFSET $SG94084 push 0 mov edx, DWORD PTR _g_pd3dFont push edx mov eax, DWORD PTR _g_pd3dFont mov ecx, DWORD PTR [eax] mov edx, DWORD PTR [ecx+56] call edx ; Line 153 mov eax, DWORD PTR _g_pd3dDevice push eax mov ecx, DWORD PTR _g_pd3dDevice mov edx, DWORD PTR [ecx] mov eax, DWORD PTR [edx+168] call eax $LN1@Render: ; Line 156 push 0 push 0 push 0 push 0 mov ecx, DWORD PTR _g_pd3dDevice push ecx mov edx, DWORD PTR _g_pd3dDevice mov eax, DWORD PTR [edx] mov ecx, DWORD PTR [eax+68] call ecx $LN4@Render: ; Line 157 pop ebp ret 0 _Render ENDP _TEXT ENDS PUBLIC _WndProc@16 EXTRN __imp__DefWindowProcA@16:PROC EXTRN __imp__ValidateRect@8:PROC EXTRN __imp__PostQuitMessage@4:PROC ; Function compile flags: /Odtp _TEXT SEGMENT tv64 = -4 ; size = 4 _hWnd$ = 8 ; size = 4 _message$ = 12 ; size = 4 _wParam$ = 16 ; size = 4 _lParam$ = 20 ; size = 4 _WndProc@16 PROC ; Line 160 push ebp mov ebp, esp push ecx ; Line 161 mov eax, DWORD PTR _message$[ebp] mov DWORD PTR tv64[ebp], eax cmp DWORD PTR tv64[ebp], 2 je SHORT $LN2@WndProc cmp DWORD PTR tv64[ebp], 15 ; 0000000fH je SHORT $LN1@WndProc jmp SHORT $LN3@WndProc $LN2@WndProc: ; Line 164 call _Cleanup ; Line 165 push 0 call DWORD PTR __imp__PostQuitMessage@4 ; Line 166 xor eax, eax jmp SHORT $LN5@WndProc $LN1@WndProc: ; Line 169 call _Render ; Line 170 push 0 mov ecx, DWORD PTR _hWnd$[ebp] push ecx call DWORD PTR __imp__ValidateRect@8 ; Line 171 xor eax, eax jmp SHORT $LN5@WndProc $LN3@WndProc: ; Line 174 mov edx, DWORD PTR _lParam$[ebp] push edx mov eax, DWORD PTR _wParam$[ebp] push eax mov ecx, DWORD PTR _message$[ebp] push ecx mov edx, DWORD PTR _hWnd$[ebp] push edx call DWORD PTR __imp__DefWindowProcA@16 $LN5@WndProc: ; Line 175 mov esp, ebp pop ebp ret 16 ; 00000010H _WndProc@16 ENDP _TEXT ENDS PUBLIC _WinMain@16 EXTRN __imp__DispatchMessageA@4:PROC EXTRN __imp__TranslateMessage@4:PROC EXTRN __imp__GetMessageA@16:PROC EXTRN __imp__UpdateWindow@4:PROC EXTRN __imp__ShowWindow@8:PROC EXTRN __imp__CreateWindowExA@48:PROC EXTRN __imp__RegisterClassExA@4:PROC EXTRN __imp__LoadCursorA@8:PROC EXTRN __imp__LoadIconA@8:PROC ; Function compile flags: /Odtp _TEXT SEGMENT _lpszClassName$ = -88 ; size = 4 _msg$ = -84 ; size = 28 _wcex$ = -56 ; size = 48 _hWnd$ = -8 ; size = 4 _lpszWindowName$ = -4 ; size = 4 _hInstance$ = 8 ; size = 4 _hPrevInstance$ = 12 ; size = 4 _lpCmdLine$ = 16 ; size = 4 _nCmdShow$ = 20 ; size = 4 _WinMain@16 PROC ; Line 178 push ebp mov ebp, esp sub esp, 88 ; 00000058H ; Line 179 mov DWORD PTR _lpszClassName$[ebp], OFFSET $SG94116 ; Line 180 mov DWORD PTR _lpszWindowName$[ebp], OFFSET $SG94118 ; Line 185 mov DWORD PTR _wcex$[ebp], 48 ; 00000030H ; Line 186 mov DWORD PTR _wcex$[ebp+4], 3 ; Line 187 mov DWORD PTR _wcex$[ebp+8], OFFSET _WndProc@16 ; Line 188 mov DWORD PTR _wcex$[ebp+12], 0 ; Line 189 mov DWORD PTR _wcex$[ebp+16], 0 ; Line 190 mov eax, DWORD PTR _hInstance$[ebp] mov DWORD PTR _wcex$[ebp+20], eax ; Line 191 push 32512 ; 00007f00H mov ecx, DWORD PTR _hInstance$[ebp] push ecx call DWORD PTR __imp__LoadIconA@8 mov DWORD PTR _wcex$[ebp+24], eax ; Line 192 push 32512 ; 00007f00H push 0 call DWORD PTR __imp__LoadCursorA@8 mov DWORD PTR _wcex$[ebp+28], eax ; Line 193 mov DWORD PTR _wcex$[ebp+32], 6 ; Line 194 mov DWORD PTR _wcex$[ebp+36], 0 ; Line 195 mov edx, DWORD PTR _lpszClassName$[ebp] mov DWORD PTR _wcex$[ebp+40], edx ; Line 196 push 32512 ; 00007f00H mov eax, DWORD PTR _hInstance$[ebp] push eax call DWORD PTR __imp__LoadIconA@8 mov DWORD PTR _wcex$[ebp+44], eax ; Line 198 lea ecx, DWORD PTR _wcex$[ebp] push ecx call DWORD PTR __imp__RegisterClassExA@4 ; Line 205 push 0 mov edx, DWORD PTR _hInstance$[ebp] push edx push 0 push 0 push 480 ; 000001e0H push 640 ; 00000280H push -2147483648 ; 80000000H push -2147483648 ; 80000000H push 13565952 ; 00cf0000H mov eax, DWORD PTR _lpszWindowName$[ebp] push eax mov ecx, DWORD PTR _lpszClassName$[ebp] push ecx push 0 call DWORD PTR __imp__CreateWindowExA@48 mov DWORD PTR _hWnd$[ebp], eax ; Line 207 mov edx, DWORD PTR _hWnd$[ebp] push edx call _InitD3D add esp, 4 ; Line 208 call _InitFont ; Line 210 push 10 ; 0000000aH mov eax, DWORD PTR _hWnd$[ebp] push eax call DWORD PTR __imp__ShowWindow@8 ; Line 211 mov ecx, DWORD PTR _hWnd$[ebp] push ecx call DWORD PTR __imp__UpdateWindow@4 $LN2@WinMain: ; Line 213 push 0 push 0 push 0 lea edx, DWORD PTR _msg$[ebp] push edx call DWORD PTR __imp__GetMessageA@16 test eax, eax je SHORT $LN1@WinMain ; Line 215 lea eax, DWORD PTR _msg$[ebp] push eax call DWORD PTR __imp__TranslateMessage@4 ; Line 216 lea ecx, DWORD PTR _msg$[ebp] push ecx call DWORD PTR __imp__DispatchMessageA@4 ; Line 217 jmp SHORT $LN2@WinMain $LN1@WinMain: ; Line 219 xor eax, eax ; Line 220 mov esp, ebp pop ebp ret 16 ; 00000010H _WinMain@16 ENDP _TEXT ENDS END
上記コードは以下のC言語のソースを VC++ でアセンブリコード出力(cl /FA hello.c)したものに相当する。
ソースコード
#include <windows.h> #include <tchar.h> #include <d3d9.h> #include <d3dx9.h> LPDIRECT3D9 g_pD3D = NULL; LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; LPD3DXFONT g_pd3dFont = NULL; RECT g_rect = { 0, 0, 0, 0 }; HRESULT InitD3D( HWND hWnd ); HRESULT InitFont(); VOID Cleanup(); VOID Render(); HRESULT InitD3D( HWND hWnd ) { HRESULT hr; D3DPRESENT_PARAMETERS d3dpp; g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( g_pD3D == NULL ) { return E_FAIL; } d3dpp.BackBufferWidth = 0; d3dpp.BackBufferHeight = 0; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 0; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = NULL; d3dpp.Windowed = TRUE; d3dpp.EnableAutoDepthStencil = 0; d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = 0; hr = g_pD3D->lpVtbl->CreateDevice( g_pD3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ); if( FAILED( hr ) ) { return E_FAIL; } return S_OK; } HRESULT InitFont() { HRESULT hr; D3DXFONT_DESC lf; lf.Height = 16; lf.Width = 0; lf.Weight = 0; lf.MipLevels = 1; lf.Italic = 0; lf.CharSet = SHIFTJIS_CHARSET; lf.OutputPrecision = OUT_TT_ONLY_PRECIS; lf.Quality = PROOF_QUALITY; lf.PitchAndFamily = FIXED_PITCH | FF_MODERN; lstrcpy( lf.FaceName, _T("MS ゴシック") ); hr = D3DXCreateFontIndirect( g_pd3dDevice, &lf, &g_pd3dFont ); if ( FAILED( hr ) ) { Cleanup(); return hr; } hr = g_pd3dFont->lpVtbl->DrawText( g_pd3dFont, NULL, _T("Hello, DirectX(MASM) World!"), -1, &g_rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE, 0xffffffff ); if ( FAILED( hr ) ) { Cleanup(); return hr; } return hr; } VOID Cleanup() { if ( g_pd3dFont != NULL ) { g_pd3dFont->lpVtbl->Release( g_pd3dFont ); } if( g_pd3dDevice != NULL ) { g_pd3dDevice->lpVtbl->Release( g_pd3dDevice ); } if( g_pD3D != NULL ) { g_pD3D->lpVtbl->Release( g_pD3D ); } } VOID Render() { if( g_pd3dDevice == NULL ) { return; } if ( g_pd3dFont == NULL ) { return; } g_pd3dDevice->lpVtbl->Clear( g_pd3dDevice, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); if( SUCCEEDED( g_pd3dDevice->lpVtbl->BeginScene( g_pd3dDevice ) ) ) { g_pd3dFont->lpVtbl->DrawText( g_pd3dFont, NULL, _T("Hello, DirectX(MASM) World!"), -1, &g_rect, DT_LEFT | DT_SINGLELINE, 0xffffffff ); g_pd3dDevice->lpVtbl->EndScene( g_pd3dDevice ); } g_pd3dDevice->lpVtbl->Present( g_pd3dDevice, NULL, NULL, NULL, NULL ); } LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_DESTROY: Cleanup(); PostQuitMessage( 0 ); return 0; case WM_PAINT: Render(); ValidateRect( hWnd, NULL ); return 0; } return DefWindowProc( hWnd, message, wParam, lParam ); } int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { LPCTSTR lpszClassName = _T("helloWindow"); LPCTSTR lpszWindowName = _T("Hello, World!"); MSG msg; HWND hWnd; 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(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); RegisterClassEx(&wcex); hWnd = CreateWindow( lpszClassName, lpszWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL ); InitD3D( hWnd ); InitFont(); ShowWindow( hWnd, SW_SHOWDEFAULT ); UpdateWindow( hWnd ); while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return 0; }
コンパイル方法
C:¥> SET INCLUDE=%DXSDK_DIR%INCLUDE;%INCLUDE% C:¥> SET LIB=%DXSDK_DIR%Libx86;%LIB% C:¥> ml hello.asm ^ /link ^ user32.lib ^ dxguid.lib ^ d3d9.lib ^ d3dx9.lib ^ /SUBSYSTEM:WINDOWS実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, DirectX(MASM) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, DirectX(MFC) World!
Posted on 7月 26th, 2012 by cx20
Win32 DirectX(MFC)
DirectX はマイクロソフトが Wnidows 用に開発したマルチメディア処理用 API である。
以下は VC++(MFC) における DirectX アプリケーション の例となっている。ソースコード
#include <afxwin.h> #include <tchar.h> #include <tchar.h> #include <d3d9.h> #include <d3dx9.h> class CMainFrame : public CFrameWnd { public: CMainFrame(); ~CMainFrame(); BOOL PreCreateWindow(CREATESTRUCT& cs); HRESULT InitD3D(); HRESULT InitFont(); VOID Cleanup(); VOID Render(); protected: afx_msg void OnPaint(); DECLARE_MESSAGE_MAP() private: LPDIRECT3D9 m_pD3D; LPDIRECT3DDEVICE9 m_pd3dDevice; LPD3DXFONT m_pd3dFont; RECT m_rect; }; class CHelloApp : public CWinApp { public: BOOL InitInstance(); }; BOOL CHelloApp::InitInstance() { m_pMainWnd = new CMainFrame; m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } CHelloApp App; BEGIN_MESSAGE_MAP( CMainFrame, CFrameWnd ) ON_WM_PAINT() END_MESSAGE_MAP() CMainFrame::CMainFrame() { m_pD3D = NULL; m_pd3dDevice = NULL; m_pd3dFont = NULL; memset( &m_rect, 0, sizeof(m_rect) ); Create( NULL, _T("Hello, World!") ); InitD3D(); InitFont(); } CMainFrame::~CMainFrame() { Cleanup(); } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { CFrameWnd::PreCreateWindow(cs); cs.cx = 640; cs.cy = 480; return TRUE; } void CMainFrame::OnPaint() { Render(); } HRESULT CMainFrame::InitD3D() { HRESULT hr; m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( m_pD3D == NULL ) { return E_FAIL; } D3DPRESENT_PARAMETERS d3dpp; d3dpp.BackBufferWidth = 0; d3dpp.BackBufferHeight = 0; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 0; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = NULL; d3dpp.Windowed = TRUE; d3dpp.EnableAutoDepthStencil = 0; d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = 0; hr = m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_pd3dDevice ); if( FAILED( hr ) ) { return E_FAIL; } return S_OK; } HRESULT CMainFrame::InitFont() { HRESULT hr; D3DXFONT_DESC lf; lf.Height = 16; lf.Width = 0; lf.Weight = 0; lf.MipLevels = 1; lf.Italic = 0; lf.CharSet = SHIFTJIS_CHARSET; lf.OutputPrecision = OUT_TT_ONLY_PRECIS; lf.Quality = PROOF_QUALITY; lf.PitchAndFamily = FIXED_PITCH | FF_MODERN; lstrcpy( lf.FaceName, _T("MS ゴシック") ); hr = D3DXCreateFontIndirect(m_pd3dDevice, &lf, &m_pd3dFont ); if ( FAILED( hr ) ) { Cleanup(); return hr; } hr = m_pd3dFont->DrawText( NULL, _T("Hello, DirectX(MFC) World!"), -1, &m_rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE, 0xffffffff ); if ( FAILED( hr ) ) { Cleanup(); return hr; } return hr; } VOID CMainFrame::Cleanup() { if ( m_pd3dFont != NULL ) { m_pd3dFont->Release(); } if( m_pd3dDevice != NULL ) { m_pd3dDevice->Release(); } if( m_pD3D != NULL ) { m_pD3D->Release(); } } VOID CMainFrame::Render() { if( m_pd3dDevice == NULL ) { return; } if ( m_pd3dFont == NULL ) { return; } m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { m_pd3dFont->DrawText( NULL, _T("Hello, DirectX(MFC) World!"), -1, &m_rect, DT_LEFT | DT_SINGLELINE, 0xffffffff ); m_pd3dDevice->EndScene(); } m_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }
コンパイル方法
C:¥> SET INCLUDE=%DXSDK_DIR%INCLUDE;%INCLUDE% C:¥> SET LIB=%DXSDK_DIR%Libx86;%LIB% C:¥> cl hello.cpp ^ /link ^ user32.lib ^ dxguid.lib ^ d3d9.lib ^ d3dx9.lib ^ /SUBSYSTEM:WINDOWS実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, DirectX(MFC) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, DirectX(WTL) World!
Posted on 7月 25th, 2012 by cx20
Win32 DirectX(WTL)
DirectX はマイクロソフトが Wnidows 用に開発したマルチメディア処理用 API である。
以下は VC++(WTL) における DirectX アプリケーション の例となっている。ソースコード
#include <atlbase.h> #include <atlapp.h> #include <atlcrack.h> #include <d3d9.h> #include <d3dx9.h> class CHelloWindow : public CWindowImpl<CHelloWindow> { public: CHelloWindow() { m_pD3D = NULL; m_pd3dDevice = NULL; m_pd3dFont = NULL; memset( &m_rect, 0, sizeof(m_rect) ); } BEGIN_MSG_MAP( CHelloWindow ) MSG_WM_PAINT ( OnPaint ) MSG_WM_DESTROY ( OnDestroy ) END_MSG_MAP() void OnPaint( HDC hDC ) { Render(); } void OnDestroy() { Cleanup(); PostQuitMessage( 0 ); } LRESULT OnPaint( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) { Render(); return 0; } LRESULT OnDestroy( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) { Cleanup(); PostQuitMessage( 0 ); return 0; } HRESULT InitD3D() { HRESULT hr; m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( m_pD3D == NULL ) { return E_FAIL; } D3DPRESENT_PARAMETERS d3dpp; d3dpp.BackBufferWidth = 0; d3dpp.BackBufferHeight = 0; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 0; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = NULL; d3dpp.Windowed = TRUE; d3dpp.EnableAutoDepthStencil = 0; d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = 0; hr = m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_pd3dDevice ); if( FAILED( hr ) ) { return E_FAIL; } return S_OK; } HRESULT InitFont() { HRESULT hr; D3DXFONT_DESC lf; lf.Height = 16; lf.Width = 0; lf.Weight = 0; lf.MipLevels = 1; lf.Italic = 0; lf.CharSet = SHIFTJIS_CHARSET; lf.OutputPrecision = OUT_TT_ONLY_PRECIS; lf.Quality = PROOF_QUALITY; lf.PitchAndFamily = FIXED_PITCH | FF_MODERN; lstrcpy( lf.FaceName, _T("MS ゴシック") ); hr = D3DXCreateFontIndirect(m_pd3dDevice, &lf, &m_pd3dFont ); if ( FAILED( hr ) ) { Cleanup(); return hr; } hr = m_pd3dFont->DrawText( NULL, _T("Hello, DirectX(WTL) World!"), -1, &m_rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE, 0xffffffff ); if ( FAILED( hr ) ) { Cleanup(); return hr; } return hr; } VOID Cleanup() { if ( m_pd3dFont != NULL ) { m_pd3dFont->Release(); } if( m_pd3dDevice != NULL ) { m_pd3dDevice->Release(); } if( m_pD3D != NULL ) { m_pD3D->Release(); } } VOID Render() { if( m_pd3dDevice == NULL ) { return; } if ( m_pd3dFont == NULL ) { return; } m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { m_pd3dFont->DrawText( NULL, _T("Hello, DirectX(WTL) World!"), -1, &m_rect, DT_LEFT | DT_SINGLELINE, 0xffffffff ); m_pd3dDevice->EndScene(); } m_pd3dDevice->Present( NULL, NULL, NULL, NULL ); } private: LPDIRECT3D9 m_pD3D; LPDIRECT3DDEVICE9 m_pd3dDevice; LPD3DXFONT m_pd3dFont; RECT m_rect; }; 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 ); wnd.InitD3D(); wnd.InitFont(); int nRet = theLoop.Run(); _Module.RemoveMessageLoop(); _Module.Term(); return nRet; }
コンパイル方法
C:¥> SET INCLUDE=<WTL>Include;%DXSDK_DIR%INCLUDE;%INCLUDE% C:¥> SET LIB=%DXSDK_DIR%Libx86;%LIB% C:¥> cl hello.cpp ^ /link ^ user32.lib ^ dxguid.lib ^ d3d9.lib ^ d3dx9.lib ^ /SUBSYSTEM:WINDOWS実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, DirectX(WTL) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, DirectX(ATL) World!
Posted on 7月 24th, 2012 by cx20
Win32 DirectX(ATL)
DirectX はマイクロソフトが Wnidows 用に開発したマルチメディア処理用 API である。
以下は VC++(ATL) における DirectX アプリケーション の例となっている。ソースコード
#include <atlbase.h> #include <atlwin.h> #include <d3d9.h> #include <d3dx9.h> class CHelloWindow : public CWindowImpl<CHelloWindow> { public: CHelloWindow() { m_pD3D = NULL; m_pd3dDevice = NULL; m_pd3dFont = NULL; memset( &m_rect, 0, sizeof(m_rect) ); } 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 ) { Render(); return 0; } LRESULT OnDestroy( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) { Cleanup(); PostQuitMessage( 0 ); return 0; } HRESULT InitD3D() { HRESULT hr; m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( m_pD3D == NULL ) { return E_FAIL; } D3DPRESENT_PARAMETERS d3dpp; d3dpp.BackBufferWidth = 0; d3dpp.BackBufferHeight = 0; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 0; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = NULL; d3dpp.Windowed = TRUE; d3dpp.EnableAutoDepthStencil = 0; d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = 0; hr = m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_pd3dDevice ); if( FAILED( hr ) ) { return E_FAIL; } return S_OK; } HRESULT InitFont() { HRESULT hr; D3DXFONT_DESC lf; lf.Height = 16; lf.Width = 0; lf.Weight = 0; lf.MipLevels = 1; lf.Italic = 0; lf.CharSet = SHIFTJIS_CHARSET; lf.OutputPrecision = OUT_TT_ONLY_PRECIS; lf.Quality = PROOF_QUALITY; lf.PitchAndFamily = FIXED_PITCH | FF_MODERN; lstrcpy( lf.FaceName, _T("MS ゴシック") ); hr = D3DXCreateFontIndirect(m_pd3dDevice, &lf, &m_pd3dFont ); if ( FAILED( hr ) ) { Cleanup(); return hr; } hr = m_pd3dFont->DrawText( NULL, _T("Hello, DirectX(ATL) World!"), -1, &m_rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE, 0xffffffff ); if ( FAILED( hr ) ) { Cleanup(); return hr; } return hr; } VOID Cleanup() { if ( m_pd3dFont != NULL ) { m_pd3dFont->Release(); } if( m_pd3dDevice != NULL ) { m_pd3dDevice->Release(); } if( m_pD3D != NULL ) { m_pD3D->Release(); } } VOID Render() { if( m_pd3dDevice == NULL ) { return; } if ( m_pd3dFont == NULL ) { return; } m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { m_pd3dFont->DrawText( NULL, _T("Hello, DirectX(ATL) World!"), -1, &m_rect, DT_LEFT | DT_SINGLELINE, 0xffffffff ); m_pd3dDevice->EndScene(); } m_pd3dDevice->Present( NULL, NULL, NULL, NULL ); } private: LPDIRECT3D9 m_pD3D; LPDIRECT3DDEVICE9 m_pd3dDevice; LPD3DXFONT m_pd3dFont; RECT m_rect; }; 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 ); wnd.InitD3D(); wnd.InitFont(); MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ){ TranslateMessage( &msg ); DispatchMessage( &msg ); } _Module.Term(); return (int)msg.wParam; }
コンパイル方法
C:¥> SET INCLUDE=%DXSDK_DIR%INCLUDE;%INCLUDE% C:¥> SET LIB=%DXSDK_DIR%Libx86;%LIB% C:¥> cl hello.cpp ^ /link ^ user32.lib ^ dxguid.lib ^ d3d9.lib ^ d3dx9.lib ^ /SUBSYSTEM:WINDOWS実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, DirectX(ATL) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, DirectX(C++) World!
Posted on 7月 23rd, 2012 by cx20
Win32 DirectX(C++)
DirectX はマイクロソフトが Wnidows 用に開発したマルチメディア処理用 API である。
以下は C++ における DirectX アプリケーション の例となっている。ソースコード
#include <windows.h> #include <tchar.h> #include <d3d9.h> #include <d3dx9.h> LPDIRECT3D9 g_pD3D = NULL; LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; LPD3DXFONT g_pd3dFont = NULL; RECT g_rect = { 0, 0, 0, 0 }; HRESULT InitD3D( HWND hWnd ); HRESULT InitFont(); VOID Cleanup(); VOID Render(); HRESULT InitD3D( HWND hWnd ) { HRESULT hr; g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( g_pD3D == NULL ) { return E_FAIL; } D3DPRESENT_PARAMETERS d3dpp; d3dpp.BackBufferWidth = 0; d3dpp.BackBufferHeight = 0; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 0; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = NULL; d3dpp.Windowed = TRUE; d3dpp.EnableAutoDepthStencil = 0; d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = 0; hr = g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ); if( FAILED( hr ) ) { return E_FAIL; } return S_OK; } HRESULT InitFont() { HRESULT hr; D3DXFONT_DESC lf; lf.Height = 16; lf.Width = 0; lf.Weight = 0; lf.MipLevels = 1; lf.Italic = 0; lf.CharSet = SHIFTJIS_CHARSET; lf.OutputPrecision = OUT_TT_ONLY_PRECIS; lf.Quality = PROOF_QUALITY; lf.PitchAndFamily = FIXED_PITCH | FF_MODERN; lstrcpy( lf.FaceName, _T("MS ゴシック") ); hr = D3DXCreateFontIndirect(g_pd3dDevice, &lf, &g_pd3dFont ); if ( FAILED( hr ) ) { Cleanup(); return hr; } hr = g_pd3dFont->DrawText( NULL, _T("Hello, DirectX(C++) World!"), -1, &g_rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE, 0xffffffff ); if ( FAILED( hr ) ) { Cleanup(); return hr; } return hr; } VOID Cleanup() { if ( g_pd3dFont != NULL ) { g_pd3dFont->Release(); } if( g_pd3dDevice != NULL ) { g_pd3dDevice->Release(); } if( g_pD3D != NULL ) { g_pD3D->Release(); } } VOID Render() { if( g_pd3dDevice == NULL ) { return; } if ( g_pd3dFont == NULL ) { return; } g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { g_pd3dFont->DrawText( NULL, _T("Hello, DirectX(C++) World!"), -1, &g_rect, DT_LEFT | DT_SINGLELINE, 0xffffffff ); g_pd3dDevice->EndScene(); } g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch( message ) { case WM_DESTROY: Cleanup(); PostQuitMessage( 0 ); return 0; case WM_PAINT: Render(); ValidateRect( hWnd, NULL ); return 0; } return DefWindowProc( hWnd, message, wParam, lParam ); } int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR 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(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); RegisterClassEx(&wcex); HWND hWnd = CreateWindow( lpszClassName, lpszWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL ); InitD3D( hWnd ); InitFont(); ShowWindow( hWnd, SW_SHOWDEFAULT ); UpdateWindow( hWnd ); MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return 0; }
コンパイル方法
C:¥> SET INCLUDE=%DXSDK_DIR%INCLUDE;%INCLUDE% C:¥> SET LIB=%DXSDK_DIR%Libx86;%LIB% C:¥> cl hello.cpp ^ /link ^ user32.lib ^ dxguid.lib ^ d3d9.lib ^ d3dx9.lib ^ /SUBSYSTEM:WINDOWS実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, DirectX(C++) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, DirectX(C言語) World!
Posted on 7月 22nd, 2012 by cx20
Win32 DirectX(C言語)
DirectX はマイクロソフトが Wnidows 用に開発したマルチメディア処理用 API である。
以下は C++ における DirectX アプリケーション の例となっている。ソースコード
#include <windows.h> #include <tchar.h> #include <d3d9.h> #include <d3dx9.h> LPDIRECT3D9 g_pD3D = NULL; LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; LPD3DXFONT g_pd3dFont = NULL; RECT g_rect = { 0, 0, 0, 0 }; HRESULT InitD3D( HWND hWnd ); HRESULT InitFont(); VOID Cleanup(); VOID Render(); HRESULT InitD3D( HWND hWnd ) { HRESULT hr; D3DPRESENT_PARAMETERS d3dpp; g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( g_pD3D == NULL ) { return E_FAIL; } d3dpp.BackBufferWidth = 0; d3dpp.BackBufferHeight = 0; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 0; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = NULL; d3dpp.Windowed = TRUE; d3dpp.EnableAutoDepthStencil = 0; d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = 0; hr = g_pD3D->lpVtbl->CreateDevice( g_pD3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ); if( FAILED( hr ) ) { return E_FAIL; } return S_OK; } HRESULT InitFont() { HRESULT hr; D3DXFONT_DESC lf; lf.Height = 16; lf.Width = 0; lf.Weight = 0; lf.MipLevels = 1; lf.Italic = 0; lf.CharSet = SHIFTJIS_CHARSET; lf.OutputPrecision = OUT_TT_ONLY_PRECIS; lf.Quality = PROOF_QUALITY; lf.PitchAndFamily = FIXED_PITCH | FF_MODERN; lstrcpy( lf.FaceName, _T("MS ゴシック") ); hr = D3DXCreateFontIndirect( g_pd3dDevice, &lf, &g_pd3dFont ); if ( FAILED( hr ) ) { Cleanup(); return hr; } hr = g_pd3dFont->lpVtbl->DrawText( g_pd3dFont, NULL, _T("Hello, DirectX World!"), -1, &g_rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE, 0xffffffff ); if ( FAILED( hr ) ) { Cleanup(); return hr; } return hr; } VOID Cleanup() { if ( g_pd3dFont != NULL ) { g_pd3dFont->lpVtbl->Release( g_pd3dFont ); } if( g_pd3dDevice != NULL ) { g_pd3dDevice->lpVtbl->Release( g_pd3dDevice ); } if( g_pD3D != NULL ) { g_pD3D->lpVtbl->Release( g_pD3D ); } } VOID Render() { if( g_pd3dDevice == NULL ) { return; } if ( g_pd3dFont == NULL ) { return; } g_pd3dDevice->lpVtbl->Clear( g_pd3dDevice, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); if( SUCCEEDED( g_pd3dDevice->lpVtbl->BeginScene( g_pd3dDevice ) ) ) { g_pd3dFont->lpVtbl->DrawText( g_pd3dFont, NULL, _T("Hello, DirectX World!"), -1, &g_rect, DT_LEFT | DT_SINGLELINE, 0xffffffff ); g_pd3dDevice->lpVtbl->EndScene( g_pd3dDevice ); } g_pd3dDevice->lpVtbl->Present( g_pd3dDevice, NULL, NULL, NULL, NULL ); } LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_DESTROY: Cleanup(); PostQuitMessage( 0 ); return 0; case WM_PAINT: Render(); ValidateRect( hWnd, NULL ); return 0; } return DefWindowProc( hWnd, message, wParam, lParam ); } int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { LPCTSTR lpszClassName = _T("helloWindow"); LPCTSTR lpszWindowName = _T("Hello, World!"); MSG msg; HWND hWnd; 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(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); RegisterClassEx(&wcex); hWnd = CreateWindow( lpszClassName, lpszWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL ); InitD3D( hWnd ); InitFont(); ShowWindow( hWnd, SW_SHOWDEFAULT ); UpdateWindow( hWnd ); while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return 0; }
コンパイル方法
C:¥> SET INCLUDE=%DXSDK_DIR%INCLUDE;%INCLUDE% C:¥> SET LIB=%DXSDK_DIR%Libx86;%LIB% C:¥> cl hello.c ^ /link ^ user32.lib ^ dxguid.lib ^ d3d9.lib ^ d3dx9.lib ^ /SUBSYSTEM:WINDOWS実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, DirectX World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Win32 GUI(Go) World!
Posted on 7月 21st, 2012 by cx20
Win32 GUI(Go)
Win32 アプリケーションは Windows 標準 API である Win32 API を使用した Windows アプリケーションである。
以下は Go言語 における Win32 GUI アプリケーション の例となっている。ソースコード
package main import ( "syscall" "unsafe" ) const ( WS_OVERLAPPED = 0x00000000 WS_POPUP = 0x80000000 WS_CHILD = 0x40000000 WS_MINIMIZE = 0x20000000 WS_VISIBLE = 0x10000000 WS_DISABLED = 0x08000000 WS_CLIPSIBLINGS = 0x04000000 WS_CLIPCHILDREN = 0x02000000 WS_MAXIMIZE = 0x01000000 WS_CAPTION = 0x00C00000 // WS_BORDER | WS_DLGFRAME WS_BORDER = 0x00800000 WS_DLGFRAME = 0x00400000 WS_VSCROLL = 0x00200000 WS_HSCROLL = 0x00100000 WS_SYSMENU = 0x00080000 WS_THICKFRAME = 0x00040000 WS_GROUP = 0x00020000 WS_TABSTOP = 0x00010000 WS_MINIMIZEBOX = 0x00020000 WS_MAXIMIZEBOX = 0x00010000 WS_TILED = WS_OVERLAPPED WS_ICONIC = WS_MINIMIZE WS_SIZEBOX = WS_THICKFRAME WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU WS_CHILDWINDOW = WS_CHILD WM_CREATE = 0x0001 WM_DESTROY = 0x0002 WM_PAINT = 0x000F WM_CLOSE = 0x0010 WM_COMMAND = 0x0111 COLOR_WINDOW = 5 COLOR_BTNFACE = 15 CS_VREDRAW = 0x0001 CS_HREDRAW = 0x0002 CW_USEDEFAULT = -2147483648 // ((int)0x80000000) SW_SHOWDEFAULT = 10 ) type WNDCLASSEX struct { cbSize uint32 style uint32 lpfnWndProc uintptr cbClsExtra int32 cbWndExtra int32 hInstance syscall.Handle hIcon syscall.Handle hCursor syscall.Handle hbrBackground syscall.Handle lpszMenuName *uint16 lpszClassName *uint16 hIconSm syscall.Handle } type POINT struct { x uintptr y uintptr } type MSG struct { hWnd syscall.Handle message uint32 wParam uintptr lParam uintptr time uint32 pt POINT } type RECT struct { Left int32 Top int32 Right int32 Bottom int32 } type PAINTSTRUCT struct { hdc syscall.Handle fErace uint32 rcPaint RECT fRestore uint32 fIncUpdate uint32 rgbReserved byte } var ( kernel32, _ = syscall.LoadLibrary("kernel32.dll") user32, _ = syscall.LoadLibrary("user32.dll") gdi32, _ = syscall.LoadLibrary("gdi32.dll") procGetModuleHandleW, _ = syscall.GetProcAddress(kernel32, "GetModuleHandleW") procLoadIconW, _ = syscall.GetProcAddress(user32, "LoadIconW") procLoadCursorW, _ = syscall.GetProcAddress(user32, "LoadCursorW") procRegisterClassExW, _ = syscall.GetProcAddress(user32, "RegisterClassExW") procCreateWindowExW, _ = syscall.GetProcAddress(user32, "CreateWindowExW") procDefWindowProcW, _ = syscall.GetProcAddress(user32, "DefWindowProcW") procDestroyWindow, _ = syscall.GetProcAddress(user32, "DestroyWindow") procPostQuitMessage, _ = syscall.GetProcAddress(user32, "PostQuitMessage") procShowWindow, _ = syscall.GetProcAddress(user32, "ShowWindow") procUpdateWindow, _ = syscall.GetProcAddress(user32, "UpdateWindow") procGetMessageW, _ = syscall.GetProcAddress(user32, "GetMessageW") procTranslateMessage, _ = syscall.GetProcAddress(user32, "TranslateMessage") procDispatchMessageW, _ = syscall.GetProcAddress(user32, "DispatchMessageW") procSendMessageW, _ = syscall.GetProcAddress(user32, "SendMessageW") procPostMessageW, _ = syscall.GetProcAddress(user32, "PostMessageW") procBeginPaint, _ = syscall.GetProcAddress(user32, "BeginPaint") procEndPaint, _ = syscall.GetProcAddress(user32, "EndPaint") procTextOutW, _ = syscall.GetProcAddress(gdi32, "TextOutW") IDC_ARROW = MakeIntResource(32512) IDI_APPLICATION = MakeIntResource(32512) ) func GetModuleHandle(lpModuleName *uint16) (syscall.Handle) { ret, _, _ := syscall.Syscall(uintptr(procGetModuleHandleW), 1, uintptr(unsafe.Pointer(lpModuleName)), 0, 0) return syscall.Handle(ret) } func LoadIcon(instance syscall.Handle, iconname *uint16) (syscall.Handle) { ret, _, _ := syscall.Syscall(uintptr(procLoadIconW), 2, uintptr(instance), uintptr(unsafe.Pointer(iconname)), 0) return syscall.Handle(ret) } func LoadCursor(instance syscall.Handle, cursorname *uint16) (syscall.Handle) { ret, _, _ := syscall.Syscall(uintptr(procLoadCursorW), 2, uintptr(instance), uintptr(unsafe.Pointer(cursorname)), 0) return syscall.Handle(ret) } func RegisterClassEx(lpwcx *WNDCLASSEX) (uint16) { ret, _, _ := syscall.Syscall(uintptr(procRegisterClassExW), 1, uintptr(unsafe.Pointer(lpwcx)), 0, 0) return uint16(ret) } func CreateWindowEx(dwExStyle uint32, lpClassName *uint16, lpWindowName *uint16, dwStyle uint32, x int32, y int32, nWidth int32, nHeight int32, hWndParent syscall.Handle, hMenu syscall.Handle, hInstance syscall.Handle, lpParam uintptr) (syscall.Handle) { ret, _, _ := syscall.Syscall12(uintptr(procCreateWindowExW), 12, uintptr(dwExStyle), uintptr(unsafe.Pointer(lpClassName)), uintptr(unsafe.Pointer(lpWindowName)), uintptr(dwStyle), uintptr(x), uintptr(y), uintptr(nWidth), uintptr(nHeight), uintptr(hWndParent), uintptr(hMenu), uintptr(hInstance), uintptr(lpParam)) return syscall.Handle(ret) } func DefWindowProc(hWnd syscall.Handle, Msg uint32, wParam uintptr, lParam uintptr) (uintptr) { ret, _, _ := syscall.Syscall6(uintptr(procDefWindowProcW), 4, uintptr(hWnd), uintptr(Msg), uintptr(wParam), uintptr(lParam), 0, 0) return uintptr(ret) } func DestroyWindow(hWnd syscall.Handle) { syscall.Syscall(uintptr(procDestroyWindow), 1, uintptr(hWnd), 0, 0) return } func PostQuitMessage(nExitCode int32) { syscall.Syscall(uintptr(procPostQuitMessage), 1, uintptr(nExitCode), 0, 0) return } func ShowWindow(hWnd syscall.Handle, nCmdShow int32) (bool) { ret, _, _ := syscall.Syscall(uintptr(procShowWindow), 2, uintptr(hWnd), uintptr(nCmdShow), 0) return bool(ret != 0) } func UpdateWindow(hWnd syscall.Handle) { syscall.Syscall(uintptr(procUpdateWindow), 1, uintptr(hWnd), 0, 0) return } func GetMessage(lpMsg *MSG, hWnd syscall.Handle, wMsgFilterMin uint32, wMsgFilterMax uint32) (int32) { ret, _, _ := syscall.Syscall6(uintptr(procGetMessageW), 4, uintptr(unsafe.Pointer(lpMsg)), uintptr(hWnd), uintptr(wMsgFilterMin), uintptr(wMsgFilterMax), 0, 0) return int32(ret) } func TranslateMessage(lpMsg *MSG) (bool) { r, _, _ := syscall.Syscall(uintptr(procTranslateMessage), 1, uintptr(unsafe.Pointer(lpMsg)), 0, 0) return bool(r != 0) } func DispatchMessage(lpMsg *MSG) (int32) { ret, _, _ := syscall.Syscall(uintptr(procDispatchMessageW), 1, uintptr(unsafe.Pointer(lpMsg)), 0, 0) return int32(ret) } func SendMessage(hWnd syscall.Handle, Msg uint32, wParam uintptr, lParam uintptr) (uintptr) { ret, _, _ := syscall.Syscall6(uintptr(procSendMessageW), 4, uintptr(hWnd), uintptr(Msg), uintptr(wParam), uintptr(lParam), 0, 0) return uintptr(ret) } func PostMessage(hWnd syscall.Handle, Msg uint32, wParam uintptr, lParam uintptr) { syscall.Syscall6(uintptr(procPostMessageW), 4, uintptr(hWnd), uintptr(Msg), uintptr(wParam), uintptr(lParam), 0, 0) return } func BeginPaint(hDC syscall.Handle, lpPaint *PAINTSTRUCT ) (syscall.Handle) { ret, _, _ := syscall.Syscall(uintptr(procBeginPaint), 2, uintptr(hDC), uintptr(unsafe.Pointer(lpPaint)), 0) return syscall.Handle(ret) } func EndPaint(hDC syscall.Handle, lpPaint *PAINTSTRUCT ) (syscall.Handle) { ret, _, _ := syscall.Syscall(uintptr(procEndPaint), 2, uintptr(hDC), uintptr(unsafe.Pointer(lpPaint)), 0) return syscall.Handle(ret) } func TextOut(hDC syscall.Handle, x int32, y int32, text string, cbString int32 ) (bool) { ret, _, _ := syscall.Syscall6(uintptr(procTextOutW), 5, uintptr(hDC), uintptr(x), uintptr(y), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))), uintptr(cbString), 0) return bool(ret != 0) } func MakeIntResource(id uint16) (*uint16) { return (*uint16)(unsafe.Pointer(uintptr(id))) } func WndProc(hWnd syscall.Handle, msg uint32, wParam, lParam uintptr) (uintptr) { switch msg { case WM_PAINT: var strMessage = "Hello, Win32 GUI(Go) World!" var ps PAINTSTRUCT hdc := BeginPaint(hWnd, &ps) TextOut( hdc, 0, 0, strMessage, int32(len(strMessage)) ) EndPaint( hWnd, &ps ) case WM_DESTROY: PostQuitMessage(0) default: return DefWindowProc(hWnd, msg, wParam, lParam) } return 0 } func WinMain() int { hInstance := GetModuleHandle(nil) lpszClassName := syscall.StringToUTF16Ptr("helloWindow") lpszWindowName := syscall.StringToUTF16Ptr("Hello, World!") var wcex WNDCLASSEX wcex.cbSize = uint32(unsafe.Sizeof(wcex)) wcex.style = CS_HREDRAW | CS_VREDRAW wcex.lpfnWndProc = syscall.NewCallback(WndProc) wcex.cbClsExtra = 0 wcex.cbWndExtra = 0 wcex.hInstance = hInstance wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION) wcex.hCursor = LoadCursor(0, IDC_ARROW) wcex.hbrBackground = COLOR_WINDOW + 1 wcex.lpszMenuName = nil wcex.lpszClassName = lpszClassName wcex.hIconSm = LoadIcon(hInstance, IDI_APPLICATION) RegisterClassEx(&wcex) hWnd := CreateWindowEx( 0, lpszClassName, lpszWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, 0, 0, hInstance, 0) ShowWindow(hWnd, SW_SHOWDEFAULT) UpdateWindow(hWnd) var msg MSG for { if GetMessage(&msg, 0, 0, 0) == 0 { break } TranslateMessage(&msg) DispatchMessage(&msg) } return int(msg.wParam) } func main() { WinMain() return }
コンパイル方法
C:¥> SET GOROOT=C:go C:¥> go build -ldflags -Hwindowsgui hello.go
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Win32 GUI(Go) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Win32 GUI(Delphi) World!
Posted on 7月 20th, 2012 by cx20
Win32 GUI(Delphi)
Win32 アプリケーションは Windows 標準 API である Win32 API を使用した Windows アプリケーションである。
以下は Delphi における Win32 GUI アプリケーション の例となっている。ソースコード
program hello; uses Windows, Messages; function WndProc(hWindow:HWnd; message:Cardinal; wParam:Word; lParam:Longint):LongWord; stdcall; var hdc: THandle; ps: TPaintStruct; const strMessage = 'Hello, Win32 GUI(Delphi) World!'; begin case message of WM_PAINT: begin hdc := BeginPaint(hWindow, ps ); TextOut( hdc, 0, 0, strMessage, Length(strMessage) ); EndPaint( hWindow, ps ); end; WM_DESTROY: PostQuitMessage(0); else Result := DefWindowProc(hWindow, message, wParam, lParam); exit; end; Result := 0; end; function WinMain(hInstance, hPrevInstance:THandle; lpCmdLine:PAnsiChar; nCmdShow:Integer):Integer; stdcall; var wcex: TWndClassEx; hWindow: HWnd; msg: TMsg; const ClassName = 'helloWindow'; WindowName = 'Hello, World!'; begin wcex.cbSize := SizeOf(TWndclassEx); wcex.style := CS_HREDRAW or CS_VREDRAW; wcex.lpfnWndProc := @WndProc; wcex.cbClsExtra := 0; wcex.cbWndExtra := 0; wcex.hInstance := hInstance; wcex.hIcon := LoadIcon(0, IDI_APPLICATION); wcex.hCursor := LoadCursor(0, IDC_ARROW); wcex.hbrBackground := COLOR_WINDOW +1; wcex.lpszMenuName := nil; wcex.lpszClassName := ClassName; RegisterClassEx(wcex); hWindow := CreateWindowEX( 0, ClassName, WindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, 0, 0, hInstance, nil ); ShowWindow(hWindow, SW_SHOWDEFAULT); UpdateWindow(hWindow); while GetMessage(msg, 0, 0, 0) do begin TranslateMessage(msg); DispatchMessage(msg); end; Result := msg.wParam; end; begin WinMain( hInstance, 0, nil, cmdShow ); end.
コンパイル方法
C:¥> dcc32 hello.pas
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Win32 GUI(Delphi) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Win32 GUI(Pascal) World!
Posted on 7月 20th, 2012 by cx20
Win32 GUI(Pascal)
Win32 アプリケーションは Windows 標準 API である Win32 API を使用した Windows アプリケーションである。
以下は Free Pascal における Win32 GUI アプリケーション の例となっている。ソースコード
{$APPTYPE GUI} {$MODE DELPHI} program hello; uses Windows, Messages; function WindowProc(hWindow:HWnd; message:Cardinal; wParam:Word; lParam:Longint):LongWord; stdcall; var hdc: THandle; ps: TPaintStruct; const strMessage = 'Hello, Win32 GUI(Pascal) World!'; begin case message of WM_PAINT: begin hdc := BeginPaint(hWindow, ps ); TextOut( hdc, 0, 0, strMessage, Length(strMessage) ); EndPaint( hWindow, ps ); end; WM_DESTROY: PostQuitMessage(0); else WindowProc := DefWindowProc(hWindow, message, wParam, lParam); exit; end; WindowProc := 0; end; function WinMain(hInstance, hPrevInstance:THandle; lpCmdLine:PAnsiChar; nCmdShow:Integer):Integer; stdcall; var wcex: TWndClassEx; hWindow: HWnd; msg: TMsg; const ClassName = 'helloWindow'; WindowName = 'Hello, World!'; begin wcex.cbSize := SizeOf(TWndclassEx); wcex.style := CS_HREDRAW or CS_VREDRAW; wcex.lpfnWndProc := WndProc(@WindowProc); wcex.cbClsExtra := 0; wcex.cbWndExtra := 0; wcex.hInstance := hInstance; wcex.hIcon := LoadIcon(0, IDI_APPLICATION); wcex.hCursor := LoadCursor(0, IDC_ARROW); wcex.hbrBackground := COLOR_WINDOW +1; wcex.lpszMenuName := nil; wcex.lpszClassName := ClassName; RegisterClassEx(wcex); hWindow := CreateWindowEX( 0, ClassName, WindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, 0, 0, hInstance, nil ); ShowWindow(hWindow, SW_SHOWDEFAULT); UpdateWindow(hWindow); while GetMessage(msg, 0, 0, 0) do begin TranslateMessage(msg); DispatchMessage(msg); end; WinMain := msg.wParam; end; begin WinMain( hInstance, 0, nil, cmdShow ); end.
コンパイル方法
C:¥> fpc hello.pas
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Win32 GUI(Pascal) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+
-
Hello, Win32 GUI(D言語) World!
Posted on 7月 19th, 2012 by cx20
Win32 GUI(D言語)
Win32 アプリケーションは Windows 標準 API である Win32 API を使用した Windows アプリケーションである。
以下は D言語 における Win32 GUI アプリケーション の例となっている。ソースコード
import core.runtime; import std.c.windows.windows; import std.string; extern(Windows) LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_PAINT: PAINTSTRUCT ps; HDC hdc = BeginPaint( hWnd, &ps ); enum text = "Hello, Win32 GUI(D) World!"; TextOutA( hdc, 0, 0, text, text.length ); EndPaint( hWnd, &ps ); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProcA(hWnd, message, wParam, lParam); break; } return 0; } extern(Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { string className = "helloWindow"; string windowName = "Hello, World!"; HWND hWnd; MSG msg; WNDCLASSA wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = &WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIconA(null, IDI_APPLICATION); wc.hCursor = LoadCursorA(null, IDC_ARROW); wc.hbrBackground = cast(HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = null; wc.lpszClassName = className.toStringz; RegisterClassA(&wc); hWnd = CreateWindowA(className.toStringz, windowName.toStringz, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, null, null, hInstance, null); ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); while (GetMessageA(&msg, null, 0, 0)) { TranslateMessage(&msg); DispatchMessageA(&msg); } return msg.wParam; }
コンパイル方法
C:¥> dmd -L/subsystem:windows gdi32.lib hello.d
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, Win32 GUI(D) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+