扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:blog 2007年10月16日
关键字:
HWND CreateSaverWindow(SaverMode mode, HWND hWndParent,HINSTANCE hInstance) { HWND hWnd; RECT rc; DWORD dwStyle; hWnd=NULL; switch ( mode ) { case sm_preview: GetClientRect(hWndParent, &rc ); dwStyle = WS_VISIBLE | WS_CHILD; AdjustWindowRect( &rc, dwStyle, FALSE ); hWnd = CreateWindow( TEXT("SaverWndClass"), TEXT("SaverWindow"), dwStyle, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hWndParent, NULL, hInstance, NULL); break; case sm_test: rc.left = rc.top = 50; rc.right = rc.left+600; rc.bottom = rc.top+400; dwStyle = WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; AdjustWindowRect( &rc, dwStyle, FALSE ); hWnd = CreateWindow( TEXT("SaverWndClass"), TEXT("SaverWindow"), dwStyle, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, NULL, NULL, hInstance, NULL); break; case sm_full: rc.left=rc.top=0; rc.bottom=GetSystemMetrics(SM_CYSCREEN); rc.right=GetSystemMetrics(SM_CXSCREEN); dwStyle = WS_VISIBLE | WS_POPUP; hWnd = CreateWindowEx( WS_EX_TOPMOST, TEXT("SaverWndClass"), TEXT("SaverWindow"), dwStyle, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL); } if(mode == sm_preview ) { // 开始预览时,进入一个短暂的循环以使系统显示控制面板有足够的时间初始化 g_bWaitForInputIdle = TRUE; // 开始循环 PostMessage( g_hWnd, WM_USER, 0, 0 ); MSG msg; while( g_bWaitForInputIdle ) { // 如果If 返回 FALSE, 结束循环 if( !GetMessage( &msg, g_hWnd, 0, 0 ) ) { // 结束循环 PostQuitMessage(0); break; } TranslateMessage( &msg); DispatchMessage( &msg); } } return hWnd; } |
LRESULT CALLBACK SaverProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch ( uMsg ) { case WM_USER: //预览开始循环,500ms空闲时间用于控制面板的初始化。 SetTimer( hWnd, 1, 500, NULL ); break; case WM_TIMER: // 500ms时间到,预览循环结束。 g_bWaitForInputIdle = FALSE; KillTimer( hWnd, 1 ); break; case WM_DESTROY: ShutdownSaver(); break; case WM_SETCURSOR: if ( g_SaverMode == sm_full && !g_bCheckingSaverPassword ) { //隐藏鼠标指针 SetCursor( NULL ); return TRUE; } break; case WM_PAINT: { PAINTSTRUCT ps; BeginPaint( hWnd, &ps ); RECT rc; GetClientRect(hWnd,&rc); FillRect(ps.hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH) ); //黑屏 EndPaint( hWnd, &ps ); return 0; } case WM_ERASEBKGND: // 输入密码时对屏幕刷新 if( !g_bCheckingSaverPassword ) return TRUE; break; case WM_MOUSEMOVE: if( g_SaverMode != sm_test ) { static INT xPrev = -1; static INT yPrev = -1; INT xCur = GET_X_LPARAM(lParam); INT yCur = GET_Y_LPARAM(lParam); if( xCur != xPrev || yCur != yPrev ) { xPrev = xCur; yPrev = yCur; g_dwSaverMouseMoveCount++; if ( g_dwSaverMouseMoveCount > 5 ) InterruptSaver(); } } break; case WM_KEYDOWN: case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: if( g_SaverMode != sm_test ) InterruptSaver(); break; case WM_ACTIVATEAPP: if( wParam == FALSE && g_SaverMode != sm_test ) InterruptSaver(); break; case WM_POWERBROADCAST: if( wParam == PBT_APMSUSPEND && g_VerifySaverPassword == NULL ) InterruptSaver(); break; case WM_SYSCOMMAND: if ( g_SaverMode == sm_full ) { switch ( wParam ) { case SC_NEXTWINDOW: case SC_PREVWINDOW: case SC_SCREENSAVE: case SC_CLOSE: return FALSE; }; } break; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); } |
VOID ChangePassword() { // 载入密码更改函数动态链接库(Dynamic Linked Library) HINSTANCE mpr = LoadLibrary( TEXT("MPR.DLL") ); if ( mpr != NULL ) { // 从动态链接数据库中提取密码设置函数 typedef DWORD (PASCAL *PWCHGPROC)( LPCSTR, HWND, DWORD, LPVOID ); PWCHGPROC pwd = (PWCHGPROC)GetProcAddress( mpr, "PwdChangePasswordA" ); //运行密码设置函数 if ( pwd != NULL ) pwd( "SCRSAVE", g_hWndParent, 0, NULL ); //释放动态链接库 FreeLibrary( mpr ); } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者