#include <windows.h>
#include <aygshell.h>
#pragma comment(lib,"aygshell.lib")
//関数の宣言
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
ATOM InitApp(HINSTANCE);
BOOL InitInstance(HINSTANCE,int,LPTSTR);
BOOL GetWorkArea(int*,int*,int*,int*);
void Paint();
//変数の宣言
HDC hdc=NULL;
//メイン
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,int nShowCmd) {
MSG msg;
BOOL bRet;
//ウィンドウの生成
if (!InitApp(hInstance)) return FALSE;
if (!InitInstance(hInstance,nShowCmd,
_T("HelloWorld"))) 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) {
WNDCLASSW 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=_T("win01");
return (RegisterClassW(&wc));
}
//ウィンドウの生成
BOOL InitInstance(HINSTANCE hInst,int nShowCmd,
LPTSTR title) {
HWND hWnd;
int x,y,w,h;
GetWorkArea(&x,&y,&w,&h);
hWnd=CreateWindowW(_T("win01"),title,
WS_CLIPCHILDREN,
x,y,w,h,
NULL,
NULL,
hInst,
NULL);
SHMENUBARINFO smi={sizeof(SHMENUBARINFO),hWnd,SHCMBF_EMPTYBAR};
SHCreateMenuBar(&smi);
ShowWindow(hWnd,nShowCmd);
UpdateWindow(hWnd);
return TRUE;
}
//ワークエリアの計算
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;
}
//ウィンドウのイベント処理
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wp,LPARAM lp) {
PAINTSTRUCT ps;
switch (uMsg){
//画面サイズの調整
case WM_SETTINGCHANGE:
if (wp==SPI_SETSIPINFO) {
int x,y,w,h;
GetWorkArea(&x,&y,&w,&h);
MoveWindow(hWnd,x,y,w,h,FALSE);
}
break;
//描画
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
Paint();
EndPaint(hWnd,&ps);
break;
//破棄
case WM_DESTROY:
PostQuitMessage(0);
break;
//その他
default:
return (DefWindowProc(hWnd,uMsg,wp,lp));
}
return 0;
}
//描画
void Paint() {
LPTSTR str;
size_t size;
//文字列の描画
str=_T("Hello, World!");
StringCchLength(str,STRSAFE_MAX_CCH,&size);
ExtTextOut(hdc,0,0,NULL,NULL,str,size,NULL);
} |