Help us understand the problem. What is going on with this article?

WINAPIでダブルダブル・バッファリング

More than 5 years have passed since last update.

http://blog.goo.ne.jp/masaki_goo_2006/e/d3c18365234ffb3383f5c30e32c83cf5
コチラを参考にダブル・バッファリングの勉強をしています.
下記のコードが VisualStudio2010 ではコンパイルできましたが, MinGW ではエラーでコンパイルすることができませんでした.

原因は何でしょうか.

winmain.cpp
/**************************************************
* ダブル・バッファリング
**************************************************/
#include <windows.h>

/**
 * Macro
 */
#define SCREEN_WIDTH    640             // オフスクリーンの画面サイズ
#define SCREEN_HEIGHT   480             // 〃


/**
 * Prototype declaration
 */
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);


/**
 * Main
 */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow )
{
    HWND hwnd;
    WNDCLASSEX wc;
    MSG msg;
    static LPSTR lpClassName = "Sample";

    wc.cbSize           = sizeof(WNDCLASSEX);               // 構造体サイズ
    wc.style            = CS_HREDRAW | CS_VREDRAW;          // クラススタイル
    wc.lpfnWndProc      = (WNDPROC)WndProc;
    wc.cbClsExtra       = wc.cbWndExtra = 0;                // 補足メモリブロックのサイズ
    wc.hInstance        = hInstance;                        // インスタンス
    wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);  // アイコン
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);      // カーソル
    wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);         // 背景色
    wc.lpszMenuName     = NULL;                             // メニュー名
    wc.lpszClassName    = lpClassName;                      // クラス名
    wc.hIconSm          = NULL;                             // アイコン

    if (!RegisterClassEx(&wc)) { return FALSE; }    // 登録

    hwnd = CreateWindow(
            lpClassName, TEXT("TITLE"),
            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            CW_USEDEFAULT, CW_USEDEFAULT,
            SCREEN_WIDTH, SCREEN_HEIGHT,
            NULL, NULL,
            hInstance, NULL
    );

    if (hwnd == NULL) return -1;

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}


/**
 * @function WndProc()
 * ウィンドウプロシージャ
 */
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static HBITMAP  hBitmap;    // ビットマップ
    static HDC hMemDC;          // オフスクリーン
    static UINT saveX, saveY;

    switch (msg) {
        case WM_CREATE: {
            HDC hdc;

            // デバイスコンテキストの作成
            hdc     = GetDC(hWnd);
            hMemDC  = CreateCompatibleDC(hdc);
            hBitmap = CreateCompatibleBitmap(hdc, SCREEN_WIDTH, SCREEN_HEIGHT);
            SelectObject(hMemDC, hBitmap);
            SelectObject(hMemDC, GetStockObject(DC_PEN));
            SelectObject(hMemDC, GetStockObject(DC_BRUSH));
            ReleaseDC(hWnd, hdc);
            break;
        }
        case WM_CLOSE: {
            // デバイスコンテキストの破棄
            DeleteDC(hMemDC);
            DeleteObject(hMemDC);
            DestroyWindow(hWnd);
            break;
        }
        case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc;

            // デバイスコンテキストの描画
            hdc = BeginPaint(hWnd, &ps);
            BitBlt(hdc, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, hMemDC, 0, 0, SRCCOPY);
            EndPaint(hWnd, &ps);
            break;
        }
        case WM_DESTROY: {
            PostQuitMessage(0);
            break;
        }
        case WM_ERASEBKGND: {
            break;
        }
        case WM_LBUTTONDOWN: {
        case WM_LBUTTONDBLCLK: {
            UINT cx = (SHORT)LOWORD(lParam);
            UINT cy = (SHORT)HIWORD(lParam);

            if (GetKeyState(VK_SHIFT) < 0) {
                cx = saveX += 16;
                cy = saveY += 16;
            }
            SetDCPenColor(hMemDC, RGB(0xFF, 0xFF, 0x00));
            SetDCBrushColor(hMemDC, RGB(0x00, 0x00, 0xFF));
            Rectangle(hMemDC, cx, cy, (cx + 16*5), (cy + 16*3));
            InvalidateRect(hWnd, NULL, FALSE);
            break;
        }
        }
        case WM_RBUTTONUP: {
            saveX = saveY = 0;
            PatBlt(hMemDC, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, BLACKNESS);
            InvalidateRect(hWnd, NULL, FALSE);
            break;
        }
        default: {
            return DefWindowProc(hWnd, msg, wParam, lParam);
            break;
        }
    }
}

■コマンド
gcc winmain.cpp -mwindows

■エラー
winmain.cpp: 関数 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)' 内:
winmain.cpp:29:29: 警告: deprecated conversion from string constant to 'LPSTR
ka char*}' [-Wwrite-strings]
winmain.cpp: 関数 'LRESULT WndProc(HWND, UINT, WPARAM, LPARAM)' 内:
winmain.cpp:87:40: エラー: 'DC_PEN' was not declared in this scope
winmain.cpp:88:40: エラー: 'DC_BRUSH' was not declared in this scope
winmain.cpp:125:47: エラー: 'SetDCPenColor' was not declared in this scope
winmain.cpp:126:49: エラー: 'SetDCBrushColor' was not declared in this scope

kero_dgu
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away