ABOUT.C 4.01 KB
/*-----------------------------------------------------------------------------

    This is a part of the Microsoft Source Code Samples. 
    Copyright (C) 1995 Microsoft Corporation.
    All rights reserved. 
    This source code is only intended as a supplement to 
    Microsoft Development Tools and/or WinHelp documentation.
    See these sources for detailed information regarding the 
    Microsoft samples programs.

    MODULE:   About.c

    PURPOSE:  Implement the About dialog box for the program.

    FUNCTIONS:
        CmdAbout     - 创建About对话框以响应菜单选择
        AboutDlgProc - 处理关于对话框的消息
        InitAboutDlg - 初始化about对话框控件

-----------------------------------------------------------------------------*/


#include <windows.h>
#include "mttty.h"

/*
	仅在此文件中调用的函数原型
*/
BOOL CALLBACK AboutDlgProc( HWND, UINT, WPARAM, LPARAM );
UINT InitAboutDlg( HWND );

/*-----------------------------------------------------------------------------

FUNCTION: CmdAbout( HWND )

参数:
hwnd -窗口的所有者

创建模态About对话框

-----------------------------------------------------------------------------*/
BOOL CmdAbout(HWND hwnd)
{
    DialogBox(ghInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
    return 0;
}

/*-----------------------------------------------------------------------------

FUNCTION: InitAboutDlg( HWND )

初始化modal About对话框
PARMATETERS:
    hDlg - Dialog window handle
设置图标动画计时器和版本信息。

HISTORY:   Date:      Author:     Comment:
           10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
UINT InitAboutDlg(HWND hDlg)
{
    UINT uTimer;
    char * szFormat = "Microsoft Windows %s\r\nVersion %d.%d\r\nBuild %d ";
    char szVersion[256];
    
    /*    
        create timer and set initial icon id
    */
    uTimer = SetTimer(hDlg, 1, 100, NULL);
    if (uTimer == 0)
        ErrorReporter("SetTimer");
    wsprintf(szVersion, szFormat, 
                    gOSV.dwPlatformId == VER_PLATFORM_WIN32_NT ? "NT" : "95",
                    gOSV.dwMajorVersion, 
                    gOSV.dwMinorVersion, 
                    LOWORD( gOSV.dwBuildNumber ) );

    if (strlen(gOSV.szCSDVersion))
        strcat(szVersion, gOSV.szCSDVersion);
                            
    SetDlgItemText(hDlg, IDC_OSVERSIONINFO, szVersion);

    return uTimer;
}

/*-----------------------------------------------------------------------------

FUNCTION: AboutDlgProc(HWND, UINT, WPARAM, LPARAM)
关于对话框的对话程序
PARAMETERS:
hdlg	对话框窗口句柄
uMessage	窗口消息
wparam	消息参数(取决于消息值)
lparam	消息参数(取决于消息值)
HISTORY:    Date:      Author:     Comment:
            10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
BOOL CALLBACK AboutDlgProc(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
    static UINT uTimer;
    static WORD wCurrentIconId;

    switch(uMessage)
    {
        case WM_INITDIALOG:
            uTimer = InitAboutDlg(hdlg);
            wCurrentIconId = IDI_APPICON;
            break;

        case WM_TIMER:
            /*
				当计时器停止,然后改变到下一个图标
            */
            {
                HICON hIcon;

                switch(wCurrentIconId)
                {
                    case IDI_APPICON:   wCurrentIconId = IDI_APPICON2;  break;
                    case IDI_APPICON2:  wCurrentIconId = IDI_APPICON3;  break;
                    case IDI_APPICON3:  wCurrentIconId = IDI_APPICON4;  break;
                    case IDI_APPICON4:  wCurrentIconId = IDI_APPICON;   break;
                }
            
                hIcon = LoadIcon(ghInst, MAKEINTRESOURCE(wCurrentIconId));
                SendMessage(GetDlgItem(hdlg, IDC_PICTURE), STM_SETICON, (WPARAM) hIcon, 0);
            }
            break;

        case WM_COMMAND:
            if (LOWORD(wparam) == IDOK) {
                KillTimer(hdlg, uTimer);
                EndDialog(hdlg, TRUE);
                return TRUE;
            }
            break;
    }

    return FALSE;
}