// gdi007.cpp
//
// 多角形の描画
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
ATOM InitApp(HINSTANCE);
HWND InitInstance(HINSTANCE, int);
WCHAR szClassName[] = _T("gdi007"); // ウィンドウクラス。UNICODEとしての文字列定数
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,int nShowCmd)
{
MSG msg;
BOOL bRet;
HWND hWnd;
if (!InitApp(hInstance))
return FALSE;
if (!(hWnd = InitInstance(hInstance,nShowCmd)))
return FALSE;
while((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) {
if (bRet == -1){
break;
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
// ウィンドウクラスの登録
ATOM InitApp(HINSTANCE hInst)
{
WNDCLASS wc;
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = WndProc; // プロシージャ名
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = NULL; // 未サポート
wc.hCursor = NULL; // 未サポート
wc.hbrBackground= (HBRUSH) COLOR_WINDOW;
wc.lpszMenuName = NULL; // 未サポート
wc.lpszClassName=(LPCTSTR) szClassName;
return (RegisterClass(&wc));
}
// ウィンドウの生成
HWND InitInstance(HINSTANCE hInst, int nShowCmd)
{
HWND hWnd;
hWnd = CreateWindow(szClassName,_T("Window Title"),
WS_CLIPCHILDREN, // ウィンドウの種類
CW_USEDEFAULT, // x座標
CW_USEDEFAULT, // y座標
CW_USEDEFAULT, // 幅
CW_USEDEFAULT, // 高さ
NULL, // 親ウィンドウのハンドル。親を作るのでNULL
NULL, // メニューハンドルまたは子ウィンドウID
hInst, // インスタンスハンドル
NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
return hWnd;
}
// ウィンドウプロシージャ
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
PAINTSTRUCT ps;
HDC hdc;
HGDIOBJ hPen,hOldPen,hBrush,hOldBrush;
static POINT lpPoint[5]={
{120, 5}, {195, 225}, {5, 90}, {240, 90}, {50, 225}
};
switch (msg){
case WM_PAINT:
hdc = BeginPaint(hWnd,&ps); // 描画処理を開始します。
hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); // 赤色のペンを作成
hOldPen = SelectObject(hdc, hPen); // 作成したペンを選択する
hBrush = CreateSolidBrush(RGB(0, 255, 0)); // 緑色のブラシを作成
hOldBrush = SelectObject(hdc, hBrush); // 作成したペンを選択する
Polygon(hdc, lpPoint, 5);
SelectObject(hdc, hOldPen); // ペンを元に戻す
SelectObject(hdc, hOldBrush); // ブラシを元に戻す
DeleteObject(hPen); // 作成したペンを削除
DeleteObject(hBrush); // 作成したブラシを削除
EndPaint(hWnd,&ps); // 描画処理を終了します。
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, msg, wp, lp));
}
return 0;
}
テーマ:Windows Mobile - ジャンル:コンピュータ
BOOL Ellipse( HDC hdc, // デバイスコンテキストのハンドル int nLeftRect, // 長方形の左上隅の x 座標 int nTopRect, // 長方形の左上隅の y 座標 int nRightRect, // 長方形の右下隅の x 座標 int nBottomRect // 長方形の右下隅の y 座標 );
// gdi005.cpp
//
// 楕円を描く
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
ATOM InitApp(HINSTANCE);
HWND InitInstance(HINSTANCE, int);
WCHAR szClassName[] = _T("gdi005"); // ウィンドウクラス。UNICODEとしての文字列定数
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,int nShowCmd)
{
MSG msg;
BOOL bRet;
HWND hWnd;
if (!InitApp(hInstance))
return FALSE;
if (!(hWnd = InitInstance(hInstance,nShowCmd)))
return FALSE;
while((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) {
if (bRet == -1){
break;
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
// ウィンドウクラスの登録
ATOM InitApp(HINSTANCE hInst)
{
WNDCLASS wc;
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = WndProc; // プロシージャ名
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = NULL; // 未サポート
wc.hCursor = NULL; // 未サポート
wc.hbrBackground= (HBRUSH) COLOR_WINDOW;
wc.lpszMenuName = NULL; // 未サポート
wc.lpszClassName=(LPCTSTR) szClassName;
return (RegisterClass(&wc));
}
// ウィンドウの生成
HWND InitInstance(HINSTANCE hInst, int nShowCmd)
{
HWND hWnd;
hWnd = CreateWindow(szClassName,_T("Window Title"),
WS_CLIPCHILDREN, // ウィンドウの種類
CW_USEDEFAULT, // x座標
CW_USEDEFAULT, // y座標
CW_USEDEFAULT, // 幅
CW_USEDEFAULT, // 高さ
NULL, // 親ウィンドウのハンドル。親を作るのでNULL
NULL, // メニューハンドルまたは子ウィンドウID
hInst, // インスタンスハンドル
NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
return hWnd;
}
// ウィンドウプロシージャ
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
PAINTSTRUCT ps;
HDC hdc;
HGDIOBJ hPen,hOldPen,hBrush,hOldBrush;
static POINT lpPoint[4];
switch (msg){
case WM_PAINT:
hdc = BeginPaint(hWnd,&ps); // 描画処理を開始します。
hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); // 赤色のペンを作成
hOldPen = SelectObject(hdc, hPen); // 作成したペンを選択する
hBrush = CreateSolidBrush(RGB(0, 255, 0)); // 緑色のブラシを作成
hOldBrush = SelectObject(hdc, hBrush); // 作成したペンを選択する
Ellipse(hdc, 0, 0, 100, 100);
Ellipse(hdc, 0, 100, 100, 250);
SelectObject(hdc, hOldPen); // ペンを元に戻す
SelectObject(hdc, hOldBrush); // ブラシを元に戻す
DeleteObject(hPen); // 作成したペンを削除
DeleteObject(hBrush); // 作成したブラシを削除
EndPaint(hWnd,&ps); // 描画処理を終了します。
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, msg, wp, lp));
}
return 0;
}
今日はここまでです。
テーマ:Windows Mobile - ジャンル:コンピュータ
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |