⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iconpro.c

📁 ICon文件格式
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************\
*            
*     FILE:     ICONPRO.C
*
*     PURPOSE:  IconPro Project main C file
*
*     COMMENTS: This file contains the main window and instance handing
*               for this project.
*
*     FUNCTIONS:
*      EXPORTS: 
*               GetSaveIconFileName     - Get the name of the file to write
*               GetOpenIconFileName     - Get the name of a file to open
*      LOCALS:
*               WinMain                 - Program entry point
*               InitApplication         - Register classes
*               InitInstance            - Create windows
*               WndProc                 - Main Window's 'Window Procedure'
*               OnCommand               - Handle command messages (menu items)
*               AboutDlgProc            - About Dialog Box's 'Window Procedure'
*               CreateNewMDIChildWindow - Creates a new child MDI window
*               UpdateMenuState         - Grays/enables appropriate menu items
*               QueryCloseAllChildren   - Close all children if possible
*
*     Copyright 1995 Microsoft Corp.
*
*
* History:
*                July '95 - Created
*
\****************************************************************************/
#include <Windows.H>
#include "Resource.h"
#include "Icons.H"
#include "IconPro.h"
#include "MDIChild.h"

/****************************************************************************/
/* Local Function Prototypes */
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow);
BOOL InitApplication( HANDLE hInstance );
BOOL InitInstance( HANDLE hInstance, int nCmdShow );
LRESULT CALLBACK WndProc( HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam );
LRESULT OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam );
BOOL CALLBACK AboutDlgProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
HWND CreateNewMDIChildWindow( LPSTR szTitle, LPVOID lpData );
BOOL UpdateMenuState( HWND hWnd, HMENU hMenu );
BOOL QueryCloseAllChildren( void );
/****************************************************************************/


/****************************************************************************/
/* Global Variables */
HINSTANCE	hInst;
HWND        hWndMain, hMDIClientWnd;
char        szAppName[] = TEXT("IconPro");
char        szTitle[] = TEXT("IconPro Icon Handler");
char        szChildClassName[] = TEXT("IconChildClass");
char        szHelpFileName[] = "IconPro.HLP";
/****************************************************************************/


/****************************************************************************
*
*     FUNCTION: WinMain
*
*     PURPOSE:  Main entry point for this app
*
*     PARAMS:   HANDLE hInstance     - This instance
*               HANDLE hPrevInstance - Previous instance
*               LPSTR  lpszCmdLine   - Command Line
*               int    nCmdShow      - Desired window status
*
*     RETURNS:  int - return code
*
* History:
*                July '95 - Created
*
\****************************************************************************/
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    MSG msg;

    // standard init stuff
    if( ! hPrevInstance )
    {
        if( ! InitApplication( hInstance ) )
        {
            return FALSE;
        }
    }
    if( ! InitInstance( hInstance, nCmdShow ) )
    {
        return FALSE;
    }

    // Standard message loop
    while (GetMessage(&msg, (HWND) NULL, 0, 0)) 
    {
        if( !TranslateMDISysAccel(hMDIClientWnd, &msg) )
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return msg.wParam;
}
/* End WinMain() ************************************************************/



/****************************************************************************
*
*     FUNCTION: InitApplication
*
*     PURPOSE:  Register classes
*
*     PARAMS:   HANDLE hInstance     - This instance
*
*     RETURNS:  BOOL - TRUE for success, FALSE for failure
*
* History:
*                July '95 - Created
*
\****************************************************************************/
BOOL InitApplication( HANDLE hInstance )
{
    WNDCLASS    wc;
    BOOL        bResult;

    wc.style         = 0;
    wc.lpfnWndProc   = (WNDPROC)WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon( hInstance, MAKEINTRESOURCE(ICONPRO_ICON) );
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = NULL;
    wc.lpszMenuName  = MAKEINTRESOURCE(ICONPRO_MENU);
    wc.lpszClassName = szAppName;

    bResult = RegisterClass( &wc );

    wc.lpfnWndProc   = (WNDPROC)IconChildWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon( hInstance, MAKEINTRESOURCE(ICONPRO_ICON) );
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = CreateSolidBrush(COLOR_3DFACE);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = szChildClassName;

    return( bResult && RegisterClass( &wc ) );
}
/* End InitApplication() ***************************************************/



/****************************************************************************
*
*     FUNCTION: InitInstance
*
*     PURPOSE:  Create and show the main window
*
*     PARAMS:   HANDLE hInstance  - This instance
*               int    nCmdShow   - desired show state
*
*     RETURNS:  BOOL - TRUE for success, FALSE for failure
*
* History:
*                July '95 - Created
*
\****************************************************************************/
BOOL InitInstance( HANDLE hInstance, int nCmdShow )
{
    hInst = hInstance;
    hWndMain = CreateWindow(
        szAppName,
        szTitle,
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0,
        CW_USEDEFAULT, 0,
        NULL,
        NULL,
        hInstance,
        NULL );

    if( hWndMain == NULL )
    {
        return FALSE;
    }

    ShowWindow( hWndMain, nCmdShow );
    UpdateWindow( hWndMain );

    return TRUE;
}
/* End InitInstance() *****************************************************/



/****************************************************************************
*
*     FUNCTION: WndProc
*
*     PURPOSE:  Window Procedure for the main window.
*
*     PARAMS:   HWND   hWnd    - This window
*               UINT   Message - Which message?
*               WPARAM wParam  - message parameter
*               LPARAM lParam  - message parameter
*
*     RETURNS:  LRESULT - depends on message
*
* History:
*                July '95 - Created
*
\****************************************************************************/
LRESULT CALLBACK WndProc( HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam )
{
    // which message are we handling?
    switch( Message )
    {
        // Menu is coming up, initialize it
        case WM_INITMENU:
            UpdateMenuState( hWnd, (HMENU)wParam );
            return 1;
        break; // end WM_INITMENU

        // Window is being created, create the MDI client also
        case WM_CREATE:
        {
            CLIENTCREATESTRUCT ccs;

            // Retrieve the handle of the Window menu and assign the
            // first child window identifier.
            ccs.hWindowMenu = GetSubMenu(GetMenu(hWnd), 2 );
            ccs.idFirstChild = IDM_WINDOWCHILD;

            // Create the MDI client window
            hMDIClientWnd = CreateWindow(	TEXT("MDICLIENT"), (LPCTSTR) NULL,
                                            WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
                                            0, 0, 0, 0, hWnd, (HMENU) 0xCAC, hInst, (LPSTR) &ccs );

            ShowWindow(hMDIClientWnd, SW_SHOW);
        }
        break; // End WM_CREATE

        // Command Messages (menu items, etc)
        case WM_COMMAND:
            OnCommand( hWnd, wParam, lParam );
            return DefFrameProc( hWnd, hMDIClientWnd, Message, wParam, lParam );
        break; // End WM_COMMAND

        // Time to close down now :(
        case WM_CLOSE:
        {
            // Will the children allow it? (Give 'em a chance to cancel)
            if( QueryCloseAllChildren() )
            {
                WinHelp( hWnd, szHelpFileName, HELP_QUIT, 0 );
                DestroyWindow( hWnd );
                PostQuitMessage( 0 );
                return DefFrameProc( hWnd, hMDIClientWnd, Message, wParam, lParam );
            }
            return 0;
        }
        break; // End WM_CLOSE

        // Pass it on to the default window procedure
        default:
            return DefFrameProc( hWnd, hMDIClientWnd, Message, wParam, lParam );
        break; // end default
    }
    return DefFrameProc( hWnd, hMDIClientWnd, Message, wParam, lParam );
}
/* End WndProc() ***********************************************************/



/****************************************************************************
*
*     FUNCTION: OnCommand
*
*     PURPOSE:  Handles command messages for main window
*
*     PARAMS:   HWND   hWnd    - This window
*               WPARAM wParam  - message parameter
*               LPARAM lParam  - message parameter
*
*     RETURNS:  LRESULT - depends on message
*
* History:
*                July '95 - Created
*
\****************************************************************************/
LRESULT OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam )
{
    // Which command is it?
    switch( LOWORD( wParam ) )
    {
        // File->New menu option - spawn a new child
        case ID_FILE_NEW:
        {
            HWND    hWndNew;

            hWndNew = CreateNewMDIChildWindow( TEXT("Untitled"), NULL );
            SendMessage( hMDIClientWnd, WM_MDIACTIVATE, (WPARAM)hWndNew, 0 );
        }
        break; // End ID_FILE_NEW

        // File->Open menu option - open an ICO file
        case ID_FILE_OPEN:
        {
            HWND            hWndNew;
            LPICONRESOURCE	lpIR;
            TCHAR        	szFileName[MAX_PATH];
            TCHAR        	szFileTitle[MAX_PATH];

            // Get the name of the file to open
            if( GetOpenIconFileName( szFileName, IDS_FILTERSTRING, "Open Icon File" ) )
            {
                // Read in the icon data
                if( (lpIR = ReadIconFromICOFile( szFileName )) == NULL )
                    break;
                // Get the name of the file for the window title
                if( GetFileTitle( szFileName, szFileTitle, MAX_PATH ) )
                    break;
                // Make a new child to handle this icon
                hWndNew = CreateNewMDIChildWindow( szFileTitle, lpIR );
                SendMessage( hMDIClientWnd, WM_MDIACTIVATE, (WPARAM)hWndNew, 0 );
            }
        }
        break; // End ID_FILE_OPEN

        // File->Extract menu option - extract icon data from a DLL or EXE
        case ID_FILE_EXTRACT:
        {
            HWND            hWndNew;
            LPICONRESOURCE	lpIR;
            TCHAR        	szFileName[MAX_PATH];

            // Get the name of the file from which to extract the icon
            if( GetOpenIconFileName( szFileName, IDS_EXEFILTERSTRING, "Extract Icon from File" ) )
            {
                // Extract the icon data
                if( (lpIR = ReadIconFromEXEFile( szFileName )) == NULL )
                    break;
                // Make a new child to handle this icon
                hWndNew = CreateNewMDIChildWindow( ("Untitled"), lpIR );
                SendMessage( hMDIClientWnd, WM_MDIACTIVATE, (WPARAM)hWndNew, 0 );
            }
        }
        break; // End ID_FILE_EXTRACT

        // File->Save and File->SaveAs menu options - save current ICO file to disk
        case ID_FILE_SAVEAS:
        case ID_FILE_SAVE:
        {
            HWND    hWndActive;
            
            // Get the active MDI child window
            if( (hWndActive = (HWND)SendMessage( hMDIClientWnd, WM_MDIGETACTIVE, 0, 0 )) != NULL )
            {
                // Tell it to write its icon to disk
                SendMessage( hWndActive, WM_COMMAND, wParam, 0 );
            }
            else
                MessageBox( hWnd, TEXT("Error Getting Active Window"), TEXT("Error"), MB_OK );
        }
        break; // End ID_FILE_SAVE/ID_FILE_SAVEAS

        // File->Close menu option - close the current MDI child window
        case ID_FILE_CLOSE:
        {
            HWND    hWndActive;

            // Get the active MDI child window and tell it to close itself

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -