新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     >>计算机科学论坛<<     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 计算机科学论坛计算机技术与应用『 C/C++编程思想 』 → 常用的编程技巧! 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5186 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: 常用的编程技巧! 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 C/C++编程思想 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 常用的编程技巧!

    纯SDK实现的托盘类

    #include "StdAfx.h"
    #include <shellapi.h>
    #pragma comment(lib, "shell32.lib")

    #pragma once

    class CTrayIcon
    {
    public:
    CTrayIcon();
    ~CTrayIcon();
    // Set notify message window
    BOOL SetNotifyWnd(HWND hWnd, UINT nMessage);
    BOOL SetIcon(HICON hIcon);// Set tray icon
    BOOL SetIcon(UINT nID);// Set tray icon by resource
    HICON GetIcon() const;// Get tray icon handle

    BOOL SetToolTip(LPCTSTR lpszText);// Set tooltip text
    BOOL SetToolTip(UINT nID);// Set tooltip text by resource
    UINT GetToolTip(LPTSTR lpszText, int nLength) const;// Get tooltip text

    #if (_WIN32_IE >= 0x0500)
    BOOL SetBalloonTip(LPCTSTR lpszTitle, LPCTSTR lpszMsg, UINT nTimeout=3000);
    BOOL GetBalloonTip(LPTSTR lpszTitle, LPTSTR lpszMsg, UINT* pTimeout) const;
    #endif
    BOOL ShowTray(BOOL bShow);
    private:
    NOTIFYICONDATA m_nid;
    };

    CTrayIcon::CTrayIcon()
    {
    memset(&m_nid, 0, sizeof(NOTIFYICONDATA));
    m_nid.cbSize = sizeof(NOTIFYICONDATA);
    }

    CTrayIcon::~CTrayIcon()
    {
    ShowTray(FALSE);
    }

    BOOL CTrayIcon::SetNotifyWnd(HWND hWnd, UINT nMessage)
    {
    if(!::IsWindow(hWnd))
       return FALSE;
    m_nid.hWnd = hWnd;

    if(nMessage > 0)
    {
       m_nid.uCallbackMessage = nMessage;
       if(!(m_nid.uFlags & NIF_MESSAGE))
        m_nid.uFlags |= NIF_MESSAGE;
    }
    else
    {
       m_nid.uCallbackMessage = 0;
       if(m_nid.uFlags & NIF_MESSAGE)
        m_nid.uFlags &= ~NIF_MESSAGE;
    }
    return Shell_NotifyIcon(NIM_ADD, &m_nid);
    }

    BOOL CTrayIcon::SetIcon(HICON hIcon)
    {
    ASSERT(hIcon != NULL);

    if(!(m_nid.uFlags & NIF_ICON))
       m_nid.uFlags |= NIF_ICON;

    m_nid.hIcon = hIcon;

    return Shell_NotifyIcon(NIM_MODIFY, &m_nid);
    }

    BOOL CTrayIcon::SetIcon(UINT nID)
    {
    return SetIcon(::LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(nID)));
    }

    HICON CTrayIcon::GetIcon() const
    {
    return m_nid.hIcon;
    }

    BOOL CTrayIcon::SetToolTip(LPCTSTR lpszText)
    {
    if(!(m_nid.uFlags & NIF_TIP))
       m_nid.uFlags |= NIF_TIP;
    lstrcpy(m_nid.szTip, lpszText);

    return Shell_NotifyIcon(NIM_MODIFY,&m_nid);
    }

    BOOL CTrayIcon::SetToolTip(UINT nID)
    {
    TCHAR szText[128];
    ::LoadString(GetModuleHandle(NULL), nID, szText, 128);
    return SetToolTip(szText);
    }

    UINT CTrayIcon::GetToolTip(LPTSTR lpszText, int nLength) const
    {
    lstrcpy(lpszText, m_nid.szTip);
    return lstrlen(lpszText);
    }

    #if (_WIN32_IE >= 0x0500)
    BOOL CTrayIcon::SetBalloonTip(LPCTSTR lpszTitle, LPCTSTR lpszMsg, UINT nTimeout/*=3000*/);

    {
    if(!(m_nid.uFlags & NIF_INFO))
       m_nid.uFlags |= NIF_INFO;
    m_nid.uTimeout = nTimeout;
    lstrcpy(m_nid.szInfoTitle, lpszTitle);
    lstrcpy(m_nid.szInfo, lpszMsg);

    return Shell_NotifyIcon(NIM_MODIFY, &m_nid);
    }
    #endif

    #if (_WIN32_IE >= 0x0500)
    BOOL CTrayIcon::GetBalloonTip(LPTSTR lpszTitle, LPTSTR lpszMsg, UINT* pTimeout) const
    {
    lstrcpy(lpszTitle, m_nid.szInfoTitle);
    lstrcpy(lpszMsg, m_nid.szInfo);
    *pTimeout = m_nid.uTimeout;
    return TRUE;
    }
    #endif

    BOOL CTrayIcon::ShowTray(BOOL bShow)
    {
    return Shell_NotifyIcon( bShow ? NIM_ADD : NIM_DELETE, &m_nid );
    }
    1.改变CToolTipCtrl提示信息时间
    SendMessage(hWndTooltip,TTM_SETDELAYTIME,(WPARAM)(DWORD)TTDT_INITIAL,(LPARAM)(INT) MAKELONG(250,0));

    2.判断操作系统版本
    //console方式编译运行
    #include <windows.h>
    #include <stdio.h>

    BOOL DisplaySystemVersion()
    {
    OSVERSIONINFOEX osvi;
    BOOL bOsVersionInfoEx;

    // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
    //
    // If that fails, try using the OSVERSIONINFO structure.

    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

    if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
    {
       // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
      
       osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
       if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
        return FALSE;
    }

    switch (osvi.dwPlatformId)
    {
    case VER_PLATFORM_WIN32_NT:
      
       // Test for the product.
      
       if ( osvi.dwMajorVersion <= 4 )
                printf("Microsoft Windows NT ");
      
       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
                printf ("Microsoft Windows 2000 ");
      
       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
                printf ("Microsoft Windows XP ");
      
       // Test for product type.
      
       if( bOsVersionInfoEx )
       {
        if ( osvi.wProductType == VER_NT_WORKSTATION )
                   {
         if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
          printf ( "Personal " );
         else
          printf ( "Professional " );
        }
        else if ( osvi.wProductType == VER_NT_SERVER )
        {
         if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
          printf ( "DataCenter Server " );
         else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
          printf ( "Advanced Server " );
         else
          printf ( "Server " );}
        }
       else
       {
        HKEY hKey;
        char szProductType[80];
        DWORD dwBufLen;
       
        RegOpenKeyEx( HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",0, KEY_QUERY_VALUE, &hKey );
        RegQueryValueEx( hKey, "ProductType", NULL, NULL,(LPBYTE) szProductType, &dwBufLen);
        RegCloseKey( hKey );
        if ( lstrcmpi( "WINNT", szProductType) == 0 )
         printf( "Professional " );
        if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
         printf( "Server " );
        if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
         printf( "Advanced Server " );
       }
      
       // Display version, service pack (if any), and build number.
      
       if ( osvi.dwMajorVersion <= 4 )
       {
         printf ("version %d.%d %s (Build %d)\n",
         osvi.dwMajorVersion,
         osvi.dwMinorVersion,
         osvi.szCSDVersion,
         osvi.dwBuildNumber & 0xFFFF);
       }
       else
       {
                   printf ("%s (Build %d)\n",
         osvi.szCSDVersion,
         osvi.dwBuildNumber & 0xFFFF);
       }
       break;
      
    case VER_PLATFORM_WIN32_WINDOWS:
      
       if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
       {
        printf ("Microsoft Windows 95 ");
        if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
                    printf("OSR2 " );
       }
      
       if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
       {
        printf ("Microsoft Windows 98 ");
        if ( osvi.szCSDVersion[1] == 'A' )
                    printf("SE " );
       }
      
       if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
       {
        printf ("Microsoft Windows Me ");
       }
       break;
      
    case VER_PLATFORM_WIN32s:
      
       printf ("Microsoft Win32s ");
       break;
    }
    return TRUE;
    }

    int main()
    {
    DisplaySystemVersion();
    }

    3.更改系统日期格式
    char buff[]="yyyy-MM-dd";
    SetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SSHORTDATE ,buff);

    4.检测电脑最后一次输入
    BOOL GetLastInputInfo( PLASTINPUTINFO plii);


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/6/29 11:12:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/23 5:48:00

    本主题贴数2,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  常用的编程技巧!(6701字) - 卷积内核,2009年6月29日
        回复:  5.获得汉字字符串拼音首字母#include "stdio.h"#include "strin..(5043字) - 卷积内核,2009年6月29日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms