进入旧版 | 服务项目 | 成功案例 | 联系方式 | 过客留言 | 友情链接
   
设为首页
加入收藏
联系我们
网站首页 | 新闻资讯 | 操作系统 | 办公软件 | 网络软件 | 工具软件 | 媒体动画 | 网页制作 | 网站开发 | 程序开发 | 平面设计
Photoshop视频教程 | Word入门 | Flash入门 | JScript | VBScript | ASP | PHP | ADO | 网页特效 | 3DS MAX6.0命令 | 系统进程
您当前的位置:GOODSGY电脑学习网 -> 程序开发 -> VC -> 文章内容  
用Visual C++编写完整的屏幕保护程序

屏幕保护程序是一个Win32应用程序,与一般的Win32应用程序不同之处在于:1、扩展名要求为 SCR ;2、命令行要有一定的格式,以便操作系统向其传递信息,如 运行模式,父窗口句柄(Handle to Parent Window)等 ;3、其他一些消息相应方面的要求。本文将首先介绍屏幕保护程序的命令行格式及实现的方法,然后介绍各个相应函数,并通过Window主函数WinMin()勾画出屏幕保护程序的主框架,最后介绍编译步骤和注意事项

  屏幕保护程序的命令行格式 :文件名 \ [运行模式] \[窗口句柄]。

  其中运行模式有五种选择:

  1. “运行模式”= ‘c’ 或 ‘C ’, 句柄为一串数字, 或文件名后没有任何参数。

  屏保程序设置方式,Window 显示属性_屏幕保护程序_设置按钮调用,数字为调用函数的窗口句柄(Handle to Parent Window)(十进制),如果没有数字,句柄为NULL。

  2. “运行模式”=‘t’或‘T’。

  测试方式,忽略句柄数字。

  3. “运行模式”=‘p’或‘P’。

  预览方式,Window 显示属性_屏幕保护程序_预览按钮调用,句柄为调用函数的窗口句柄。

  4. “运行模式”=‘a’或‘A’。

  密码设置方式, Window 显示属性_屏幕保护程序_密码保护_更改按钮调用。句柄为调用函数的Window 句柄。

  5. 其它(通常“运行模式”=‘s’)

  屏幕保护程序正常运行模式。

  因此,编写屏幕保护程序的首要任务是过滤命令行,提取对应的系统调用方式和其他信息,本文用自定义函数ParseCommandline( )实现:

//用enum定义五种调用方式:
enum SaverMode
{
 sm_config,
 sm_preview,
 sm_full,
 sm_test,
 sm_passwordchange
};

//命令行过滤函数,命令行获得函数是用API GetCommandLine( )。
SaverMode ParseCommandLine( TCHAR* pstrCommandLine )
{
 g_hWndParent = NULL; //全局变量(global varibale) 在头函数或主文件开始处定义。

 // 跳过长文件名中的路径和空格。
 if (*pstrCommandLine == TEXT('\"'))
 {
  pstrCommandLine++;
  while (*pstrCommandLine != TEXT('\0') && *pstrCommandLine != TEXT('\"'))
   pstrCommandLine++;
   If( *pstrCommandLine == TEXT('\"') )
    pstrCommandLine++;
 }
 else
 {
  while (*pstrCommandLine != TEXT('\0') && *pstrCommandLine != TEXT(' '))
   pstrCommandLine++;
   if( *pstrCommandLine == TEXT(' ') )
    pstrCommandLine++;
 }

 // 跳过"/" 或 "-"
 while ( *pstrCommandLine != TEXT('\0') && *pstrCommandLine != TEXT('/') && *pstrCommandLine != TEXT('-') )
  pstrCommandLine++;

 // 如果没有任何参数,为设置模式。
 if ( *pstrCommandLine == TEXT('\0') )
  return sm_config;

 // 如果有参数,查看参数内容。
 switch ( *(++pstrCommandLine) )
 {
  case 'c':
  case 'C':
   pstrCommandLine++;
   while ( *pstrCommandLine && !isdigit(*pstrCommandLine) )
    pstrCommandLine++;
   if ( isdigit(*pstrCommandLine) )
   {
    #ifdef _WIN64 //考虑64位编译情况。
     CHAR strCommandLine[2048];
     DXUtil_ConvertGenericStringToAnsiCb( strCommandLine, pstrCommandLine, sizeof(strCommandLine));
     //该函数仅在64位编译情况下使用。
     g_hWndParent = (HWND)(_atoi64(strCommandLine));
    #else
     g_hWndParent = (HWND)LongToHandle(_ttol(pstrCommandLine)); //数字串变为        /Window句柄
    #endif
   }
  else
  {
   g_hWndParent = NULL;
 }
 return sm_config;

 case 't':
 case 'T':
  return sm_test;

 case 'p':
 case 'P':
  //预览模式,后面有Window句柄,为十进制数字
  pstrCommandLine++;
  while ( *pstrCommandLine && !isdigit(*pstrCommandLine) )
   pstrCommandLine++;
  if ( isdigit(*pstrCommandLine) )
  {
   #ifdef _WIN64
    CHAR strCommandLine[2048];
    DXUtil_ConvertGenericStringToAnsiCb(strCommandLine, pstrCommandLine,   sizeof(strCommandLine));
    g_hWndParent = (HWND)(_atoi64(strCommandLine));
   #else
    g_hWndParent = (HWND)LongToHandle(_ttol(pstrCommandLine));
   #endif
  }
  return sm_preview;

  case 'a':
  case 'A':
   //密码设置模式,后面有Window句柄,为十进制数字
   pstrCommandLine++;
   while ( *pstrCommandLine && !isdigit(*pstrCommandLine) )
    pstrCommandLine++;
   if ( isdigit(*pstrCommandLine) )
   {
    #ifdef _WIN64
     CHAR strCommandLine[2048];
     DXUtil_ConvertGenericStringToAnsiCb(strCommandLine, pstrCommandLine,   sizeof(strCommandLine));
     g_hWndParent = (HWND)(_atoi64(strCommandLine));
    #else
     g_hWndParent = (HWND)LongToHandle(_ttol(pstrCommandLine));
    #endif
   }
   return sm_passwordchange;

  default:
   //其他选项,屏保实际运行模式(通常/s)
   return sm_full;
 }
}
///////////////////////

 www.goodsgy.com

www.goodsgy.com

[1] [2] [3] [4]  下一页

在百度中搜索:用Visual C++编写完整的屏幕保护程序
在Google中搜索:用Visual C++编写完整的屏幕保护程序
在Yahoo中搜索:用Visual C++编写完整的屏幕保护程序

收藏到网摘:新浪VIVI 365key 我摘 POCO网摘 博采中心 YouNote 和讯网摘 天天收藏
[] [返回上一页] [打 印] [收 藏]

 相关文章    最新文章
· PowerPoint不用VBA也制作交互课件
· [图文] PowerPoint中用VBA制作课堂小测验
· 在Excel中利用VBA创建多级选单
· 普通用户Excel使用VBA的几个误区
· Excel中调用VBA选择目标文件夹
· 在Excel中用VBA实现定时提醒功能
· 如何启用/禁用Vista内置管理员帐号
· [图文] PowerPoint做交互课件 不用VBA
· 给Vista初学者的建议 如何正确用Vista
· 用VB.NET 2005编写定时关机程序
 
· VC实现系统热键激活后台服务程序
· SEO:关于baidu一些排名规则的讨论
· More Effective C++:不要重载的操作符
· VC利用boost库解析正则表达式
· [图文] 用VC实现对超长数据库字段的操作
· More Effective C++:防止资源泄漏
· 用VC#2005解析含有多种格式的文本文件
· C++中禁止异常信息传递到析构函数外
· [图文] Visual C# 2005实现控件中捕获按键..
· C++中理解“传递参数”和异常之间的差异

∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论…]
站内搜索

精彩图文
  网站导航  
操作系统 办公软件 网络软件
Vista Windows2003 WindowsXP Windows2000/NT Windows9X/ME Linux 其他 Word Excel Powerpoint Outlook 金山系列 其他 网页浏览 上传下载 联络聊天 邮件工具 服务器软件 网络辅助
工具软件 媒体动画 网页制作
系统工具 媒体工具 压缩工具 图文处理 文件管理 其他 3DMAX Authorware Director Maya 视频处理 其他 Flash Dreamweaver FireWorks FrontPage LiveMotion Golive HTML/CSS 其它
网站开发 平面设计 程序设计
ASP JSP PHP CGI JavaScript VBScript XML/SOAP Web服务器 Photoshop PhotoImpact CorelDraw Illustrator Freehand 设计欣赏 其他 VB VC .NET C/C++ DELPHI JAVA

冀ICP备05019428号
Copyright © 2004-2008 电脑学习网 Inc.All rights reserved.
TEL:13832340607
QQ:39873155
E_Mail:goodsgy(#)hotmail.com   (把(#)替换成@)
MSN:goodsgy(#)hotmail.com   (把(#)替换成@)