#include <stdAfx.h>
BOOL InitWindow(HINSTANCE hInstance, int nCmdShow);
LRESULT CALLBACK WinProc(HWND hWnd,
UINT message,
WPARAM wParam, LPARAM lParam );
HWND hWnd; //窗口句柄
int x,y,x1,y1;//窗口宽与高
HBITMAP hBm;
BITMAP bm;
int PASCAL WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if ( !InitWindow( hInstance, nCmdShow ) ) return FALSE;
MSG msg;
hBm=LoadBitmap(hInstance,"IDB_BITMAP2");
for (;;)//消息循环1
{
if(PeekMessage(&msg,NULL, 0, 0, PM_REMOVE))
{
if(msg.message== WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}//消息循环1
return msg.wParam;
}
static BOOL InitWindow(HINSTANCE hInstance, int nCmdShow )
{
WNDCLASS wc;
wc.style=NULL;
wc.lpfnWndProc=(WNDPROC)WinProc;
wc.cbClsExtra=0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = CreateSolidBrush (RGB(192,192,192)); //暗红色的背景
wc.lpszMenuName = NULL;
wc.lpszClassName = "My_Test";
RegisterClass(&wc);//注册窗口
//按所给参数创造窗口
hWnd = CreateWindow("My_Test",
"My first program",
WS_POPUP|WS_MAXIMIZE,
0,0,
x=400, //GetSystemMetrics( SM_CXSCREEN )此函数返回屏幕宽度
y=400, //GetSystemMetrics( SM_CYSCREEN )此函数返回屏幕高度
NULL,NULL,hInstance,NULL);
if( !hWnd ) return FALSE;
ShowWindow(hWnd,nCmdShow);//显示窗口
UpdateWindow(hWnd);//刷新窗口
return TRUE;
}//end initWindows
LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc,hdcmem,hdcWindow;
HBRUSH hb1,hb2;
HPEN hPen;
LPPOINT lpPoint;
PAINTSTRUCT ps;
switch( message )
{
case WM_CREATE:
hdc=GetDC(hWnd);
hdcmem=CreateCompatibleDC(hdc);
ReleaseDC(hWnd,hdc);
break;
case WM_KEYDOWN://击键消息
switch( wParam )
{
case VK_ESCAPE:
MessageBox(hWnd,"ESC键按下了! 确定后退出!","Keyboard",MB_OK);
PostMessage(hWnd, WM_CLOSE, 0, 0);//给窗口发送WM_CLOSE消息
break;
}
return 0; //处理完一个消息后返回0
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
MoveToEx(hdc,x/10,y/10,NULL);
LineTo(hdc,(int)(x*0.9),(int)(y/10));
LineTo(hdc,(int)(x*0.9),(int)(y*0.9));
LineTo(hdc,(int) x/10,(int) (y*0.9));
LineTo(hdc,(int) x/10,(int) y/10);
MoveToEx(hdc,(int) (x/10+x*0.8/3),(int) y/10,NULL);
LineTo(hdc,(int) (x/10+x*0.8/3),(int)(y*0.9));
MoveToEx(hdc,(int) (x/10+x*0.8/3*2),(int) y/10,NULL);
LineTo(hdc,(int) (x/10+x*0.8/3*2),(int)( y*0.9));
MoveToEx(hdc,(int) x/10,(int) (y/10+y*0.8/3),NULL);
LineTo(hdc,(int)( x*0.9),(int) (y/10+y*0.8/3));
MoveToEx(hdc,(int) (x/10),(int)(y/10+y*0.8/3*2),NULL);
LineTo(hdc,(int )(x*0.9),(int)(y/10+y*0.8/3*2));
//TextOut(hdc,120,30,"一些线",6);
SelectObject(hdcmem,hBm);
BitBlt(hdc,x/10,y/10,21,22,hdcmem,0,0,SRCCOPY);//这个图片无法显示
ValidateRect(hWnd,NULL);
EndPaint(hWnd,&ps);
break;
case WM_CLOSE: //准备退出
DestroyWindow( hWnd ); //释放窗口
return 0;
case WM_RBUTTONDOWN:
MessageBox(hWnd,"鼠标右键按下了!","Mouse",MB_OK);
return 0;
case WM_DESTROY: //如果窗口被人释放…
PostQuitMessage( 0 ); //给窗口发送WM_QUIT消息
return 0;
}
//调用缺省消息处理过程
return DefWindowProc(hWnd,message,wParam,lParam);
}