| 開発環境 |
Microsoft Visual C++ 2010 Express (SP1) |
| 実行環境 |
Microsoft Windows XP Home Edition (SP3) |
| プロジェクトの種類 |
Win32 プロジェクト |
| プロジェクト名 |
GdiTest |
| アプリケーションの種類 |
Windows アプリケーション |
| 追加のオプション |
空のプロジェクト |
| 文字セット |
Unicode |
参考
- 第336章 GDI+の基礎 その2
GdiTest.cpp
#pragma comment(lib, "gdiplus.lib")
#include <Windows.h>
#include <GdiPlus.h>
using namespace Gdiplus;
// 関数プロトタイプ宣言
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// グローバル変数
TCHAR g_szClassName[] = TEXT("GdiTest");
TCHAR g_szWindowName[] = TEXT("GDI+ Test");
Image *g_img = NULL;
//==============================================================================
int APIENTRY wWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wcex;
HWND hWnd;
MSG msg;
ULONG_PTR token;
GdiplusStartupInput input;
GdiplusStartup(&token, &input, NULL);
g_img = Image::FromFile(lpCmdLine);
wcex.cbSize = sizeof wcex;
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = g_szClassName;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (RegisterClassEx(&wcex) == 0) {
return 0;
}
hWnd = CreateWindow(
g_szClassName,
g_szWindowName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0,
CW_USEDEFAULT, 0,
NULL,
NULL,
hInstance,
NULL);
if (hWnd == NULL) {
return 0;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(token);
return msg.wParam;
}
//------------------------------------------------------------------------------
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (uMsg) {
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
{
Graphics g(hdc);
g.DrawImage(g_img, 0, 0);
}
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
最終更新:2012年09月01日 16:41