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

📄 wndproc.c

📁 DBVIEW is a small Windows application that highlights the use of the builtin database functions:
💻 C
📖 第 1 页 / 共 2 页
字号:
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (C) 1993-1997  Microsoft Corporation.  All Rights Reserved.
//
//  MODULE:     wndproc.c
//
//  PURPOSE:    Contains window procedures for the main application windows.
//
//  PLATFORMS:  Windows CE
//
//  FUNCTIONS:
//      MainWndProc()       - Message handler for the main application window
//      Main_OnCommand()    - Processes WM_COMMAND messages
//      Main_OnDestroy()    - Handles the WM_DESTROY message
//      AboutDlgProc()      - Message handler for the application's about
//                            dialog.
//
//  COMMENTS:
//
//

#include <windows.h>
#include <windowsx.h>
#if !defined(_WIN_CE_EMULATION)
    #include <memory.h>
#endif
#include <commctrl.h>
#include <tchar.h>
#include "resource.h"
#include "globals.h"
#include "platdetect.h" //platform detector unit
#include "WINDBASE.H"

//----------------------------------------------------------------------------
// Local prototypes




static TBBUTTON tbVIEWButton[] = {
    {DB_NEXT_REC, DB_NEXT_REC, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
    {DB_PREV_REC, DB_PREV_REC, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 1},
    {DB_ADD_REC,  DB_ADD_REC,  TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 2}
};

//----------------------------------------------------------------------------

//
//  FUNCTION:   MainWndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:    Processes messages for the main application window.
//
//  PARAMETERS:
//      hwnd        - handle the the window receiving the message
//      uMsg        - identifier of the message
//      wParam      - additional info associated with the message
//      lParam      - additional info associated with the message
//
//  RETURN VALUE:
//      (LRESULT) Returns 0 by default if the message is handled by this
//                procedure.
//
//  COMMENTS:
//

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
                 LPARAM lParam)
{
    switch(uMsg)
    {
    HANDLE_MSG(hwnd, WM_COMMAND,            Main_OnCommand);
    HANDLE_MSG(hwnd, WM_DESTROY,            Main_OnDestroy);
    HANDLE_MSG(hwnd, WM_CREATE,             Main_OnCreate );
    HANDLE_MSG(hwnd, WM_NOTIFY,             Main_OnNotify );
    default:                // Pass message on for default proccessing
        return DefWindowProc( hwnd, uMsg, wParam, lParam );
    }

    // If we performed non-default processing on the message, return FALSE
    return FALSE;
}




//
//  FUNCTION:   Main_OnCommand(HWND, int, HWND, UINT)
//
//  PURPOSE:    Handles the WM_COMMAND messages for the Win32Generic window
//              class
//
//  PARAMETERS:
//      hwnd        - handle of the window receiving the message
//      id          - identifier of the command
//      hwndCtl     - handle of the control sending the message)
//      codeNotify  - specifies the notification code if the message is from
//                    a control
//
//  RETURN VALUE:
//      none
//
//  COMMENTS:
//      codeNotify is 1 if from an accelerator, 0 if from a menu.
//      If the message is not from a control hwndCtl is NULL.
//

LRESULT WINAPI Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
    switch (id)
    {
        case IDM_FILE_EXIT:
            // The user wants to exit, so send our window a close message
            SendMessage(hwnd, WM_CLOSE, 0, 0L);
            break;

        case IDM_HELP_ABOUT:
            // Display the "About" dialog
            if (GuessPlatform() == PLAT_PPC)
            {   
                DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_SMALL_ABOUTBOX), hwnd, AboutDlgProc);
            }
            else
            {
                DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutDlgProc);
            }
            break;

        case ID_OBJECTSTORE_STORAGESPACE:
            DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_WCEMEMORY), hwnd, (WNDPROC)MemoryDlgProc);
            break;
        case IDM_CREATEDB:
            DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_NEWDBNAME), hwnd, (WNDPROC)NewDBDlgProc);
            break;
        case IDM_DELETEDB:
            DeleteCurrentDB(hwnd);
            break;

        case DB_NEXT_REC:
            SeekNextRecord(hwnd, 1);
            break;

        case DB_PREV_REC:
            SeekNextRecord(hwnd, (DWORD) -1);
            break;

        case DB_ADD_REC:
            AddRecToCurrentDB(hwnd);
            break;

        case IDM_INDEXDB:
            ModifyIndex(hwnd);
            break;
        case IDM_USEINDEXES:
            OpenIndex(hwnd);
            break;

        default:
            return 1L;

    }
    return 0L;
}


//
//  FUNCTION:   Main_OnDestroy(HWND)
//
//  PURPOSE:    Handle any clean up and post the quit message to exit the
//              message loop.
//
//  PARAMETERS:
//      hwnd    - handle of the window receiving this message
//
//  RETURN VALUE:
//      none
//

void WINAPI Main_OnDestroy(HWND hwnd)
{
    // Indicate that the message loop should exit since the main window
    // is being destroyed.
    CommandBar_Destroy(hwndCB);
    if ( himl )
        ImageList_Destroy(himl);

    PostQuitMessage(0);
}


//
//  FUNCTION:   Main_OnCreate(HWND, LPCREATESTRUCT)
//
//  PURPOSE:    Create the treeview control and initialize the data
//
//  PARAMETERS:
//      hwnd                    - handle of the window receiving this message
//              lpCreateStruct  - points to a CREATESTRUCT containing information
//                                                about the window creation
//
//  RETURN VALUE:
//      returns TRUE if the window should be created, FALSE otherwise
//
//  COMMENTS:
//

BOOL WINAPI Main_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
    HWND hwndTV;
    RECT rcClient;
    int  nCommandHeight;
    BOOL bButton;

    // Start by initializing the common control libraries
    InitCommonControls();

    // Get the client area rect to put the treeview in
    GetClientRect(hwnd, &rcClient);
    
    hwndCB = CommandBar_Create(g_hInstance, hwnd, 1);
    CommandBar_AddBitmap(hwndCB, g_hInstance, IDB_BUTTONS, 3, 16, 16);

    
    bButton = CommandBar_AddButtons(hwndCB, 3, tbVIEWButton);

    CommandBar_InsertMenubar(hwndCB, g_hInstance, IDM_MAIN, 0);


    CommandBar_AddAdornments(hwndCB, 0, 0);

    nCommandHeight = CommandBar_Height(hwndCB);

    if (GuessPlatform() == PLAT_PPC)
    {
        hwndTV = CreateWindowEx(0, WC_TREEVIEW, TEXT("DB View Control"),
                                WS_VISIBLE | WS_CHILD | TVS_HASLINES |
                                TVS_LINESATROOT | TVS_HASBUTTONS, 0, nCommandHeight,
                                rcClient.right, rcClient.bottom/2-nCommandHeight, hwnd,
                                (HMENU) IDC_TREEVIEW, g_hInstance, NULL);

        hEdit = CreateWindow(TEXT("EDIT"), TEXT("Property Information"),
                                WS_VISIBLE | WS_CHILD | ES_MULTILINE |  ES_READONLY | WS_VSCROLL,
                                0, rcClient.bottom/2,
                                rcClient.right, rcClient.bottom/2, hwnd,
                                (HMENU) IDC_EDITCONTROL, g_hInstance, NULL);

    }
    else
    {

        hwndTV = CreateWindowEx(0, WC_TREEVIEW, TEXT("DB View Control"),
                                WS_VISIBLE | WS_CHILD | TVS_HASLINES |
                                TVS_LINESATROOT | TVS_HASBUTTONS, 0, nCommandHeight,
                                rcClient.right/2, rcClient.bottom-nCommandHeight, hwnd,
                                (HMENU) IDC_TREEVIEW, g_hInstance, NULL);

        hEdit = CreateWindow(TEXT("EDIT"), TEXT("Property Information"),
                                WS_VISIBLE | WS_CHILD | ES_MULTILINE |  ES_READONLY | WS_VSCROLL,
                                rcClient.right/2, nCommandHeight,
                                rcClient.right/2, rcClient.bottom-nCommandHeight, hwnd,
                                (HMENU) IDC_EDITCONTROL, g_hInstance, NULL);
    }

    // Make sure the treeview was actually created
    if (!hwndTV)
    {
        ErrorHandler();
        return FALSE;
    }


    // Initialize the image list, and add items to the control.
    // InitTreeViewImageLists() and InitTreeViewItems() are defined in treeview.c.
    if (!InitDBViewImageLists(hwndTV) || !InitDBViewItems(hwndTV))
    {
        DestroyWindow(hwndTV);
        return FALSE;
    }

    // Everything is set up correctly, now set the global handle to the treeview
    // and finish window creation.
    g_hwndTreeView = hwndTV;

    return TRUE;
}


//
//  FUNCTION:   AboutDlgProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:    Processes messages for the About dialog box
//
//  PARAMETERS:
//      hwnd    - window handle of the dialog box
//      uMsg    - identifier of the message being handled
//      wParam  - additional info associated with the message
//      lParam  - additional info associated with the message
//
//  RETURN VALUE:
//      Except in response to the WM_INITDIALOG message, the dialog box
//      procedure should return nonzero if it processes the message, and zero
//      if it does not.
//
//  COMMENTS:
//

LRESULT CALLBACK AboutDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,
                  LPARAM lParam)
{

    switch(uMsg)
    {
    case WM_INITDIALOG:
    {
        // Should return nonzero to set focus to the first control in the
        // dialog, or zero if this routine sets the focus manually.

        return (TRUE);
    }
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
            case IDOK:
            {
                EndDialog(hwnd, 0);
                break;

⌨️ 快捷键说明

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