Fwndproc.cpp
上传用户:wenliang_x
上传日期:2013-05-26
资源大小:19k
文件大小:2k
- #include "ScreenSave.h"
- TPassward pwd; //密码缓冲区对象(TPassward.h)
- const char* const PASSWARD = "lgsh"; //密码设置
- const char* const WRMSG = "呵呵,Wrong Passward,Input Again!!";
- static const int scrwth=GetSystemMetrics(SM_CXFULLSCREEN)-100; //窗口宽度
- static const int scrhgt=GetSystemMetrics(SM_CYFULLSCREEN); //窗口高度
- //窗口消息处理函数,程序自动调用
- LRESULT CALLBACK MainWndProc(HWND hWnd,UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- HDC hdc;
- switch (message)
- {
- case WM_KEYUP: //如果按下任一建
- {
- if (wParam == VK_RETURN) { //回车键
- if (pwd == PASSWARD){
- PostQuitMessage(0); //发出关闭程序的消息
- }
- else { //输出错误密码消息
- pwd.clear();
- hdc = GetDC(hWnd);
- SetTextColor( hdc, RGB(255,255,0) );
- SetBkMode(hdc, TRANSPARENT );
- TextOut( //Windows系统接口函数(Windows API)
- hdc, //窗口的设备环境
- scrwth*rand()/RAND_MAX, //起始的x坐标
- scrhgt*rand()/RAND_MAX, //起始的y坐标
- WRMSG, //输出的字符串
- strlen(WRMSG) //字符串长度
- );
- ReleaseDC(hWnd,hdc);
- }
- }
-
- // if (wParam == VK_ESCAPE) //ESC键
- // PostQuitMessage(0); //发出关闭程序的消息
- break;
- }
- case WM_CHAR:
- {
- if (wParam<'z' && wParam>'a')
- pwd = pwd + (char)wParam; //输入字符存入密码缓冲区(TPassward.h)
- break;
- }
- case WM_CLOSE:
- {
- break;
- }
- case WM_DESTROY: //如果按下关闭按钮
- {
- PostQuitMessage(0); //发出关闭程序的消息
- break;
- }
- default: //其他消息发给windows默认窗口处理函数
- return (DefWindowProc(hWnd,message,wParam,lParam));
- }
- return 0;
- }