このページはゲームループの基礎講座シリーズの1つです。
今回は第7章の「キャラクタの描画」について説明します。(戻る)
マウスクリックで描画
CASE WM_LBUTTONUP: { LONG nFaceX = (LOWORD(lParam) - (nFaceW / 2)); LONG nFaceY = (HIWORD(lParam) - (nFaceH / 2)); HDC hDC; hDC = GetDC( hWnd ); BitBlt( hDC, nFaceX, nFaceY, nFaceW, nFaceH, hFaceChip, 0, 0, SRCCOPY ); ReleaseDC( hWnd, hDC ); }
プロシージャ関数に組み込む
//------------------------------------------------ // ウインドウのプロシージャ関数(OK) //------------------------------------------------ static LRESULT CALLBACK mainWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { static HDC hFaceChip; static LONG nFaceW; static LONG nFaceH; switch ( uMsg ){ CASE WM_CREATE: nFaceW = 32; nFaceH = 32; hFaceChip = funcCreateMemDC( hWnd, nFaceW, nFaceH ); funcFaceImage( hFaceChip, nFaceW, nFaceH ); CASE WM_CLOSE: DeleteDC( hFaceChip ); DestroyWindow( hWnd ); CASE WM_DESTROY: PostQuitMessage( 0 ); CASE WM_PAINT: { PAINTSTRUCT ps; HDC hDC; hDC = BeginPaint( hWnd, &ps ); /* 描画処理 */ EndPaint( hWnd, &ps ); }[←前へ] [目次] [次へ→]CASE WM_LBUTTONUP: { LONG nFaceX = (LOWORD(lParam) - (nFaceW / 2)); LONG nFaceY = (HIWORD(lParam) - (nFaceH / 2)); HDC hDC; hDC = GetDC( hWnd ); BitBlt( hDC, nFaceX, nFaceY, nFaceW, nFaceH, hFaceChip, 0, 0, SRCCOPY ); ReleaseDC( hWnd, hDC ); }CASE WM_ENDSESSION: PostMessage( hWnd, WM_CLOSE, 0, 0 );// CASE WM_LBUTTONDOWN: SendMessage( hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0 );CASE WM_LBUTTONDBLCLK: SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, (SWP_NOMOVE|SWP_NOSIZE) ); CASE WM_RBUTTONDBLCLK: SetWindowPos( hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, (SWP_NOMOVE|SWP_NOSIZE) ); DEFAULT: return DefWindowProc( hWnd, uMsg, wParam, lParam ); } return 0; }
※コメント投稿者のブログIDはブログ作成者のみに通知されます