为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

窗口指令

2013-11-15 4页 doc 34KB 23阅读

用户头像

is_302455

暂无简介

举报
窗口指令// character.cpp : Defines the entry point for the application. // #include "stdafx.h" #include #include #include long WINAPI WndProc(HWND hWnd, UINT iMessage, UINT wParam, LONG lParam); BOOL InitWindowsClass(HINSTANCE hInstance); BOOL InitWindows(HINSTAN...
窗口指令
// character.cpp : Defines the entry point for the application. // #include "stdafx.h" #include #include #include long WINAPI WndProc(HWND hWnd, UINT iMessage, UINT wParam, LONG lParam); BOOL InitWindowsClass(HINSTANCE hInstance); BOOL InitWindows(HINSTANCE hInstance, int nCmdShow); HWND hWndMain; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG Message; if(!InitWindowsClass(hInstance)) return FALSE; if(!InitWindows(hInstance, nCmdShow)) return FALSE; while(GetMessage(&Message, 0, 0, 0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return Message.wParam; } long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam) {HDC hDC; //定义设备环境句柄 PAINTSTRUCT ps; //定义包含绘图信息的结构体变量 HPEN hPen; //定义画笔句柄 HBRUSH hBrush; //定义画刷句柄 //以下定义输出的字符串 static char cUp[]="You had hitted the UP key"; static char cCtrl[]="You had hitted the Ctrl key"; static char cShift[]="You had hitted the SHIFT key"; static char cCtrl_A[]="You had hitted the CTRL A key"; static char cShift_B[]="You had hitted the SHIFT B key"; //下面定义并初始化按键标志变量 static BOOL nUpKeyDown=FALSE, nShiftKeyDown=FALSE, nCtrlKeyDown=FALSE, nCtrlAKeyDown=FALSE, nShiftBKeyDown=FALSE; switch(iMessage) { case WM_KEYDOWN: { switch(wParam) { case VK_UP: //当按上箭头键时,变量置为真 nUpKeyDown = TRUE; break; case VK_SHIFT: //当按Shift键时,变量置为真 nShiftKeyDown = TRUE; break; case VK_CONTROL: //当按Control键时,变量置为真 nCtrlKeyDown = TRUE; break; default: break; } } break; case WM_KEYUP: InvalidateRect(hWnd,NULL,FALSE); break; case WM_CHAR: if(wParam==(65&VK_CONTROL)) { if(nCtrlKeyDown == TRUE) { nCtrlAKeyDown = TRUE; nCtrlKeyDown = FALSE; } } else if(wParam==98||wParam==66) //当按下b键时 { if(nShiftKeyDown == TRUE) //检查Shift键是否处于按下状态。 {nShiftBKeyDown = TRUE; //当Shift键按下时,变量置为真 nShiftKeyDown = FALSE;} } break; case WM_PAINT: //处理绘图消息. hDC=BeginPaint(hWnd,&ps); hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH); //创建 白画刷。 hPen = (HPEN)GetStockObject(WHITE_PEN); //创建白画笔。 SelectObject(hDC,hPen); //选入白画刷 SelectObject(hDC,hBrush); //选入白画笔 SetTextColor(hDC,RGB(255,0,0)); //设置字体颜色为红色。 //输出信息。 if(nUpKeyDown == TRUE) { Rectangle(hDC,0,0,300,200); TextOut(hDC,0,0,cUp,strlen(cUp)); nUpKeyDown = FALSE; } else if(nCtrlAKeyDown == TRUE) { Rectangle(hDC,0,0,300,200); TextOut(hDC,0,100,cCtrl_A,strlen(cCtrl_A)); nCtrlAKeyDown = FALSE; nCtrlKeyDown = FALSE; } else if(nCtrlAKeyDown == TRUE) else if(nCtrlKeyDown == TRUE&&nCtrlAKeyDown == FALSE) { Rectangle(hDC,0,0,300,200); TextOut(hDC,0,60,cCtrl,strlen(cCtrl)); nCtrlKeyDown = FALSE; } else if(nShiftBKeyDown == TRUE) { Rectangle(hDC,0,0,300,200); TextOut(hDC,0,0,cShift_B,strlen(cShift_B)); nShiftBKeyDown = FALSE; nShiftKeyDown = FALSE; } else if(nShiftBKeyDown == FALSE&&nShiftKeyDown == TRUE) { Rectangle(hDC,0,0,300,200); TextOut(hDC,0,0,cShift,strlen(cShift)); nShiftKeyDown = FALSE; } else; //删除画笔和画刷 DeleteObject(hPen); DeleteObject(hBrush); EndPaint(hWnd,&ps); break; case WM_DESTROY: PostQuitMessage(0); return 0; default: return(DefWindowProc(hWnd,iMessage,wParam,lParam)); } return 0; } BOOL InitWindows(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hWnd = CreateWindow("WinFill", "Example", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if(!hWnd) return FALSE; hWndMain = hWnd; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } BOOL InitWindowsClass(HINSTANCE hInstance) { WNDCLASS WndClass; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hbrBackground = (HBRUSH__ *)(COLOR_WINDOWFRAME);//GetStockObject(WHITE_BRUSH); WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hIcon = LoadIcon(NULL, "END"); WndClass.hInstance = hInstance; WndClass.lpfnWndProc = WndProc; WndClass.lpszMenuName = NULL; WndClass.lpszClassName = "WinFill"; WndClass.style = CS_HREDRAW|CS_VREDRAW; return RegisterClass(&WndClass); }
/
本文档为【窗口指令】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索