「C言語/C++/DIBSection」の編集履歴(バックアップ)一覧はこちら

C言語/C++/DIBSection - (2019/09/04 (水) 11:16:10) の1つ前との変更点

追加された行は緑色になります。

削除された行は赤色になります。

|開発環境|Microsoft Visual Studio Community 2019 / Visual C++| |実行環境|Microsoft Windows 10 Home (64bit)| |プロジェクト テンプレート|Windows デスクトップ ウィザード| |プロジェクト名|DIBSection| |アプリケーションの種類|デスクトップ アプリケーション (.exe)| |追加のオプション|空のプロジェクト| DIBSection.cpp #highlight(cpp){{ #include <Windows.h> #define APP_NAME L"DIBSection" #define WND_SIZE 512 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void OnCreate(HWND hWnd); void OnDestroy(); void OnPaint(HWND hWnd); HDC hMemDC = NULL; HBITMAP hBmp = NULL; HBITMAP hBmpOld = NULL; int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int nCmdShow) { // ウィンドウクラスの登録 WNDCLASSEX wc = { sizeof WNDCLASSEX }; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = HBRUSH(COLOR_WINDOW + 1); wc.lpszClassName = APP_NAME; if (RegisterClassEx(&wc) == 0) { return 0; } // ウィンドウの作成 HWND hWnd = CreateWindow( APP_NAME, APP_NAME, WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (hWnd == NULL) { return 0; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); // メッセージループ MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_PAINT: OnPaint(hWnd); break; case WM_CREATE: OnCreate(hWnd); break; case WM_DESTROY: OnDestroy(); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } void OnCreate(HWND hWnd) { RECT rcw, rcc; GetWindowRect(hWnd, &rcw); GetClientRect(hWnd, &rcc); int cx = WND_SIZE + (rcw.right - rcw.left) - rcc.right; int cy = WND_SIZE + (rcw.bottom - rcw.top) - rcc.bottom; SetWindowPos(hWnd, NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE); BITMAPINFOHEADER bmih = { sizeof BITMAPINFOHEADER }; bmih.biWidth = WND_SIZE; bmih.biHeight = WND_SIZE; bmih.biPlanes = 1; bmih.biBitCount = 32; bmih.biCompression = BI_RGB; LPDWORD pixel; hBmp = CreateDIBSection(NULL, (BITMAPINFO*)& bmih, DIB_RGB_COLORS, (LPVOID*)& pixel, NULL, 0); if (!hBmp) return; HDC hdc = GetDC(hWnd); hMemDC = CreateCompatibleDC(hdc); // hBmp = CreateCompatibleBitmap(hdc, WND_SIZE, WND_SIZE); hBmpOld = (HBITMAP)SelectObject(hMemDC, hBmp); for (int y = 0; y < WND_SIZE; y++) { for (int x = 0; x < WND_SIZE; x++) { *pixel++ = ((x & 0xff) << 8) | (y & 0xff); // SetPixel(hMemDC, x, y, RGB(x & 0xff, y & 0xff, 0)); } } ReleaseDC(hWnd, hdc); } void OnDestroy() { SelectObject(hMemDC, hBmpOld); DeleteObject(hBmp); DeleteDC(hMemDC); } void OnPaint(HWND hWnd) { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); BitBlt(hdc, 0, 0, WND_SIZE, WND_SIZE, hMemDC, 0, 0, SRCCOPY); EndPaint(hWnd, &ps); } }} #image(DIBSection.jpg)

表示オプション

横に並べて表示:
変化行の前後のみ表示: