開発環境 |
Microsoft Visual C++ 2010 Express (SP1) |
実行環境 |
Microsoft Windows XP Home Edition (SP3) |
プロジェクトの種類 |
Win32 プロジェクト |
プロジェクト名 |
gdi+test |
アプリケーションの種類 |
Windows アプリケーション |
追加のオプション |
空のプロジェクト |
文字セット |
Unicode |
gdi+test.cpp
// GDI+
// Image: BMP, ICON, GIF, JPEG, Exif, PNG, TIFF, WMF, and EMF
#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("gdi+test");
TCHAR g_szWindowName[] = TEXT("gdi+test");
Image *g_image = NULL;
//==============================================================================
int APIENTRY wWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wcx;
HWND hWnd;
MSG msg;
ULONG token;
GdiplusStartupInput input;
// 初期処理
GdiplusStartup(&token, &input, NULL);
g_image = new Image(lpCmdLine);
// g_image = Image::FromFile(lpCmdLine);
// ウィンドウクラスの登録
wcx.cbSize = sizeof (WNDCLASSEX);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = WindowProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInstance;
wcx.hIcon = NULL;
wcx.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcx.lpszMenuName = NULL;
wcx.lpszClassName = g_szClassName;
wcx.hIconSm = NULL;
if (RegisterClassEx(&wcx) == 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);
}
// 終了処理
delete g_image;
GdiplusShutdown(token);
return msg.wParam;
}
//------------------------------------------------------------------------------
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
Graphics g(hdc);
g.DrawImage(g_image, 0, 0);
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
最終更新:2012年09月09日 08:36