#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include <aygshell.h>
#pragma comment(lib,"aygshell.lib")
//システム関数の宣言
BOOL DlgProc(HWND,UINT,WPARAM,LPARAM);
BOOL GetWorkArea(int*,int*,int*,int*);
void Create();
void Paint();
void Destroy();
//描画関数の宣言
HDC G_CreateDC();
HBITMAP G_CreateBmp(HDC,int,int);
HBITMAP G_LoadBmp(WORD);
void G_SetColor(int,int,int);
void G_FillRect(int,int,int,int);
void G_DrawBmp(HBITMAP,int,int);
void G_DrawScaledBmp(HBITMAP,int,int,int,int,int,int,int,int);
void G_DrawBmp(HBITMAP,HBITMAP,int,int);
void G_DrawScaledBmp(HBITMAP,HBITMAP,int,int,int,int,int,int,int,int);
//システム変数の宣言
HINSTANCE hInst =NULL;
HWND hDlg =NULL;
int screenW=0;
int screenH=0;
//描画変数の宣言
HDC hdcOff =NULL;
HDC hdcMem1=NULL;
HDC hdcMem2=NULL;
HBITMAP hOff =NULL;
HGDIOBJ hPen =NULL;
HGDIOBJ hBrush =NULL;
//ビットマップ
HBITMAP hBmp1=NULL;
HBITMAP hBmp2=NULL;
//メイン
int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,int nShowCmd) {
//ダイアログの生成
hInst=hInstance;
DialogBoxW(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DlgProc);
return 0;
}
//ダイアログのイベント処理
BOOL DlgProc(HWND hDialog,UINT uMsg,WPARAM wp,LPARAM lp) {
switch(uMsg) {
//初期化
case WM_INITDIALOG:
{
//ダイアログの設定
SHINITDLGINFO sidi={
SHIDIM_FLAGS,hDialog,
SHIDIF_DONEBUTTON|SHIDIF_SIZEDLGFULLSCREEN|SHIDIF_EMPTYMENU};
SHInitDialog(&sidi);
//生成
hDlg=hDialog;
Create();
//描画処理
Paint();
}
break;
//コマンド
case WM_COMMAND:
switch(LOWORD(wp)) {
//OKボタン
case IDOK:
EndDialog(hDialog,LOWORD(wp));
break;
}
break;
//クローズ
case WM_CLOSE:
//解放
Destroy();
DestroyWindow(hDialog);
break;
}
return FALSE;
}
//ワークエリアの計算
BOOL GetWorkArea(int *x,int *y,int *w,int *h) {
SIPINFO si={sizeof(SIPINFO)};
if (!SipGetInfo(&si)) return FALSE;
*x=si.rcVisibleDesktop.left;
*y=si.rcVisibleDesktop.top;
*w=si.rcVisibleDesktop.right-*x;
if (si.fdwFlags&SIPF_ON) {
*h=si.rcSipRect.top-*y;
} else {
*h=si.rcSipRect.bottom-*y;
}
return TRUE;
}
//生成
void Create() {
//ワークエリアの計算
int x,y;
GetWorkArea(&x,&y,&screenW,&screenH);
//ピクチャの配置
MoveWindow(GetDlgItem(hDlg,IDC_STATIC1),
0,0,screenW,screenH,FALSE);
//オフスクリーンの生成
hdcOff =G_CreateDC();
hdcMem1=CreateCompatibleDC(hdcOff);
hdcMem2=CreateCompatibleDC(hdcOff);
hOff =G_CreateBmp(hdcOff,screenW,screenH);
//ビットマップの読み込み
hBmp1=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP1));
hBmp2=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP2));
}
//描画
void Paint() {
//前処理
HBITMAP hOffOld=(HBITMAP)SelectObject(hdcOff,hOff);
//背景の描画
G_SetColor(255,255,255);
G_FillRect(0,0,screenW,screenH);
//ビットマップの描画
G_DrawBmp(hBmp1,0,0);
//ビットマップの透過描画
G_DrawBmp(hBmp1,hBmp2,150,0);
G_DrawBmp(hBmp1,hBmp2,160,10);
//ビットマップの透過拡縮描画
G_DrawScaledBmp(hBmp1,hBmp2,
0,150,114*2,114*2,0,0,114,114);
//後処理
SelectObject(hdcOff,hOffOld);
//ピクチャの画像更新
SendMessage(GetDlgItem(hDlg,IDC_STATIC1),
STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hOff);
}
//解放
void Destroy() {
DeleteObject(hBmp1);
DeleteObject(hBmp2);
DeleteDC(hdcOff);
DeleteDC(hdcMem1);
DeleteDC(hdcMem2);
DeleteObject(hOff);
DeleteObject(hPen);
DeleteObject(hBrush);
}
//デバイスコンテキストの生成
HDC G_CreateDC() {
return CreateCompatibleDC(NULL);
}
//ビットマップの生成
HBITMAP G_CreateBmp(HDC hdcOff,int w,int h) {
BITMAPINFO bmi={0};
void *pv;
bmi.bmiHeader.biSize =sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth =w;
bmi.bmiHeader.biHeight =h;
bmi.bmiHeader.biPlanes =1;
bmi.bmiHeader.biBitCount =(SHORT)max(16,GetDeviceCaps(hdcOff,BITSPIXEL));
bmi.bmiHeader.biCompression=BI_RGB;
return CreateDIBSection(hdcOff,&bmi,DIB_RGB_COLORS,&pv,NULL,0);
}
//ビットマップのロード
HBITMAP G_LoadBmp(WORD id) {
return LoadBitmap(hInst,MAKEINTRESOURCE(id));
}
//色の指定
void G_SetColor(int r,int g,int b) {
//テキスト色の指定
SetBkMode(hdcOff,TRANSPARENT);
SetTextColor(hdcOff,RGB(r,g,b));
//ペン色とブラシ色の指定
DeleteObject(hPen);
DeleteObject(hBrush);
hPen=CreatePen(PS_SOLID,1,RGB(r,g,b));
SelectObject(hdcOff,hPen);
hBrush=CreateSolidBrush(RGB(r,g,b));
SelectObject(hdcOff,hBrush);
}
//矩形の塗り潰し
void G_FillRect(int x,int y,int w,int h) {
Rectangle(hdcOff,x,y,x+w,y+h);
}
//ビットマップの描画
void G_DrawBmp(HBITMAP hBmp,int x,int y) {
BITMAP info;
GetObject(hBmp,sizeof(BITMAP),&info);
(HBITMAP)SelectObject(hdcMem1,hBmp);
BitBlt(hdcOff,x,y,info.bmWidth,info.bmHeight,hdcMem1,0,0,SRCCOPY);
}
//ビットマップの拡縮描画
void G_DrawScaledBmp(HBITMAP hBmp,int x,int y,int w,int h,
int sx,int sy,int sw,int sh) {
(HBITMAP)SelectObject(hdcMem1,hBmp);
StretchBlt(hdcOff,x,y,w,h,hdcMem1,sx,sy,sw,sh,SRCCOPY);
}
//ビットマップの透過描画
void G_DrawBmp(HBITMAP hBmp,HBITMAP hBmpMask,int x,int y) {
BITMAP info;
GetObject(hBmp,sizeof(BITMAP),&info);
(HBITMAP)SelectObject(hdcMem2,hBmpMask);
BitBlt(hdcOff,x,y,info.bmWidth,info.bmHeight,hdcMem2,0,0,SRCAND);
(HBITMAP)SelectObject(hdcMem1,hBmp);
BitBlt(hdcOff,x,y,info.bmWidth,info.bmHeight,hdcMem1,0,0,SRCINVERT);
}
//ビットマップの拡縮透過描画
void G_DrawScaledBmp(HBITMAP hBmp,HBITMAP hBmpMask,
int x,int y,int w,int h,
int sx,int sy,int sw,int sh) {
(HBITMAP)SelectObject(hdcMem2,hBmpMask);
StretchBlt(hdcOff,x,y,w,h,hdcMem2,sx,sy,sw,sh,SRCAND);
(HBITMAP)SelectObject(hdcMem1,hBmp);
StretchBlt(hdcOff,x,y,w,h,hdcMem1,sx,sy,sw,sh,SRCINVERT);
} |