扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:blog 2007年10月16日
关键字:
VOID InitSaver() { //检查操作系统版本 OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof(osvi); GetVersionEx( &osvi ); g_bIs9x = (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS); // 在运行模式下,如果操作系统是win9x,需要载入密码验证动态链接库。 if ( g_SaverMode == sm_full && g_bIs9x ) { // 检查注册表查看屏保是否设定了密码 HKEY hKey; if ( RegCreateKeyEx( HKEY_CURRENT_USER, REGSTR_PATH_SCREENSAVE, 0, NULL, 0, KEY_READ, NULL, &hKey, NULL ) == ERROR_SUCCESS ) { DWORD dwVal; DWORD dwSize = sizeof(dwVal); if ( (RegQueryValueEx( hKey, REGSTR_VALUE_USESCRPASSWORD, NULL, NULL, (BYTE *)&dwVal, &dwSize ) == ERROR_SUCCESS) && dwVal ) { g_hPasswordDLL = LoadLibrary( TEXT("PASSWORD.CPL") ); if ( g_hPasswordDLL ) g_VerifySaverPassword= (VERIFYPWDPROC)GetProcAddress( g_hPasswordDLL, "VerifyScreenSavePwd" ); RegCloseKey( hKey ); } } } if ( g_SaverMode == sm_full ) { BOOL bUnused; SystemParametersInfo( SPI_SCREENSAVERRUNNING, TRUE, &bUnused, 0 ); //通知操作系统屏幕保护程序开始运行。 } } |
VOID ShutdownSaver() { // 通知操作系统屏幕保护程序退出 if ( g_SaverMode == sm_full ) { BOOL bUnused; SystemParametersInfo( SPI_SCREENSAVERRUNNING, FALSE, &bUnused, 0 ); } if ( g_hPasswordDLL != NULL ) { FreeLibrary( g_hPasswordDLL ); g_hPasswordDLL = NULL; } PostQuitMessage( 0 ); } ///////////////////////////////// VOID InterruptSaver() { BOOL bPasswordOkay = FALSE; if( g_SaverMode == sm_test ||g_SaverMode == sm_full&&!g_bCheckingSaverPassword ) { if( g_bIs9x && g_SaverMode == sm_full ) { // Win9x下如果g_VerifySaverPassword==NULL,则没有设屏保密码。 if ( g_VerifySaverPassword != NULL ) { g_bCheckingSaverPassword = TRUE;//告诉消息响应函数正在验证密码 bPasswordOkay = g_VerifySaverPassword( g_hWnd ); g_bCheckingSaverPassword = FALSE; //密码验证结束。 if ( !bPasswordOkay ) { //屏保程序继续运行… SetCursor( NULL ); g_dwSaverMouseMoveCount = 0; return; } } } ShutdownSaver(); } } |
#include <windows.h> #include <windowsx.h> #include <tchar.h> #include <stdio.h> #include <stdlib.h> #include <regstr.h> #include "Saver.h" #include "resource.h" HINSTANCE g_hinstance; HWND g_hWndParent; BOOL g_bWaitForInputIdle; HWND g_hWnd; LRESULT CALLBACK SaverProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. MSG msg; g_bCheckingSaverPassword = FALSE; g_bIs9x = FALSE; g_dwSaverMouseMoveCount = 0; g_hWndParent = NULL; g_hPasswordDLL = NULL; g_hWnd = NULL; g_VerifySaverPassword = NULL; g_hinstance=hInstance; WNDCLASS cls; cls.hCursor = LoadCursor( NULL, IDC_ARROW ); cls.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_MAIN_ICON) ); cls.lpszMenuName = NULL; cls.lpszClassName = TEXT("SaverWndClass"); cls.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); cls.hInstance = hInstance; cls.style = CS_VREDRAW|CS_HREDRAW; cls.lpfnWndProc = SaverProc; cls.cbWndExtra = 0; cls.cbClsExtra = 0; if(!RegisterClass( &cls )) MessageBox(NULL,TEXT("Cant register window class"),TEXT("SaverWndClass"),MB_ICONERROR); SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_IDLE ); TCHAR* pstrCmdLine = GetCommandLine(); g_SaverMode = ParseCommandLine(pstrCmdLine); switch(g_SaverMode) { case sm_preview: case sm_full: case sm_test: g_hWnd=CreateSaverWindow(g_SaverMode,g_hWndParent,hInstance); if ( g_hWnd == NULL ) { MessageBox(NULL,TEXT("Can't Create Window"), TEXT("Create Window Terminated"),MB_ICONERROR); return 0; }else { ShowWindow(g_hWnd,nCmdShow); UpdateWindow(g_hWnd); } InitSaver(); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } break; case sm_config: Doconfig(); break; case sm_passwordchange: ChangePassword(); break; } return 0; } |
enum SaverMode { sm_config, sm_preview, sm_full, sm_test, sm_passwordchange }; typedef BOOL (PASCAL * VERIFYPWDPROC) (HWND); DWORD g_dwSaverMouseMoveCount; BOOL g_bIs9x; HINSTANCE g_hPasswordDLL; VERIFYPWDPROC g_VerifySaverPassword; BOOL g_bCheckingSaverPassword; SaverMode g_SaverMode; SaverMode ParseCommandLine( TCHAR* pstrCommandLine ); HWND CreateSaverWindow(SaverMode mode, HWND hWndParent,HINSTANCE hInstance); VOID InitSaver(); VOID ChangePassword(); VOID Doconfig( ); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者