菜单演示程序

Posted lhb666aboluo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了菜单演示程序相关的知识,希望对你有一定的参考价值。

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

#define ID_TIMER 1

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

TCHAR szAppName[] = TEXT("MenuDemo");

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) 
{
    HWND             hwnd; 
    MSG              msg; 
    WNDCLASS         wndclass;

    wndclass.style          = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc    = WndProc;
    wndclass.cbClsExtra     = 0;
    wndclass.cbWndExtra     = 0;
    wndclass.hInstance      = hInstance;
    wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName   = szAppName;
    wndclass.lpszClassName  = szAppName;

    if(!RegisterClass(&wndclass)) {
        MessageBox(NULL, TEXT("This program requires Windows NT !"), szAppName, MB_ICONERROR);
        return 0;
    }

    hwnd = CreateWindow(szAppName, TEXT("Menu Demonstration"),
                        WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, CW_USEDEFAULT,
                        CW_USEDEFAULT, CW_USEDEFAULT,
                        NULL, NULL, hInstance, NULL);

    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&msg, NULL, 0, 0))
    { 
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
{
    static int   idColor[5] = {WHITE_BRUSH, LTGRAY_BRUSH, GRAY_BRUSH,
                                DKGRAY_BRUSH, BLACK_BRUSH};
    static int   iSelection = IDM_BKGND_WHITE;
    HMENU        hMenu;

    switch(message) 
    {
    case WM_COMMAND:
        hMenu = GetMenu(hwnd);
        switch(LOWORD(wParam))
        {
        case IDM_FILE_NEW:
        case IDM_FILE_OPEN:
        case IDM_FILE_SAVE:
        case IDM_FILE_SAVE_AS:
            MessageBeep(0);
            return 0;
        
        case IDM_APP_EXIT:
            SendMessage(hwnd, WM_CLOSE, 0, 0);
            return 0;

        case IDM_EDIT_UNDO:
        case IDM_EDIT_CUT:
        case IDM_EDIT_COPY:
        case IDM_EDIT_PASTE:
        case IDM_EDIT_CLEAR:
            MessageBeep(0);
            return 0;

        case IDM_BKGND_WHITE:
        case IDM_BKGND_LTGRAY:
        case IDM_BKGND_GRAY:
        case IDM_BKGND_DKGRAY:
        case IDM_BKGND_BLACK:
            CheckMenuItem(hMenu, iSelection, MF_UNCHECKED);
            iSelection = LOWORD(wParam);
            CheckMenuItem(hMenu, iSelection, MF_CHECKED);

            SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)
                GetStockObject(idColor[LOWORD(wParam)-IDM_BKGND_WHITE]));
            InvalidateRect(hwnd, NULL, TRUE);
            return 0;

        case IDM_TIMER_START:
            if(SetTimer(hwnd, ID_TIMER, 1000, NULL))
            {
                EnableMenuItem(hMenu, IDM_TIMER_START, MF_GRAYED);
                EnableMenuItem(hMenu, IDM_TIMER_STOP, MF_ENABLED);
            }
            return 0;

        case IDM_TIMER_STOP:
            KillTimer(hwnd, ID_TIMER);
            EnableMenuItem(hMenu, IDM_TIMER_START, MF_ENABLED);
            EnableMenuItem(hMenu, IDM_TIMER_STOP, MF_GRAYED);
            return 0;
        
        case IDM_APP_HELP:
            MessageBox(hwnd, TEXT("Help not yet implemented!"),
                        szAppName, MB_ICONEXCLAMATION | MB_OK);
            return 0;

        case IDM_APP_ABOUT:
            MessageBox(hwnd, TEXT("Menu Demonstration Program
")
                             TEXT("(c) Charles Petzold, 1998"),
                        szAppName, MB_ICONINFORMATION | MB_OK);
            return 0;
        }
        break;
    
    case WM_TIMER:
        MessageBeep(0);
        return 0;
        
    case WM_DESTROY: 
        PostQuitMessage(0);
        return 0;            
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}

MenuDemo.rc

/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

MenuDemo MENU DISCARDABLE 
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "&New",                        IDM_FILE_NEW
        MENUITEM "&Open",                       IDM_FILE_OPEN
        MENUITEM "&Save",                       IDM_FILE_SAVE
        MENUITEM "Save &As...",                 IDM_FILE_SAVE_AS
        MENUITEM "SEPARATOR",                   ID_MENUITEM40005
        MENUITEM "E&xit",                       IDM_APP_EXIT
    END
    POPUP "&Edit"
    BEGIN
        MENUITEM "&Undo",                       IDM_EDIT_UNDO
        MENUITEM "SEPARATOR",                   ID_MENUITEM40008
        MENUITEM "C&ut",                        IDM_EDIT_CUT
        MENUITEM "&Copy",                       IDM_EDIT_COPY
        MENUITEM "&Paste",                      IDM_EDIT_PASTE
        MENUITEM "De&lete",                     IDM_EDIT_CLEAR
    END
    POPUP "&Background"
    BEGIN
        MENUITEM "&White",                      IDM_BKGND_WHITE, CHECKED
        MENUITEM "&Light Gray",                 IDM_BKGND_LTGRAY
        MENUITEM "&Gray",                       IDM_BKGND_GRAY
        MENUITEM "&Dark Gray",                  IDM_BKGND_DKGRAY
        MENUITEM "&Black",                      IDM_BKGND_BLACK
    END
    POPUP "&Timer"
    BEGIN
        MENUITEM "&Start",                      IDM_TIMER_START
        MENUITEM "S&top",                       IDM_TIMER_STOP, GRAYED
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&Help...",                    IDM_APP_HELP
        MENUITEM "&About MenuDemo...",          IDM_APP_ABOUT
    END
END

 

以上是关于菜单演示程序的主要内容,如果未能解决你的问题,请参考以下文章

从外部片段内的 FragmentTabHost 的子片段添加新的选项菜单

html PHP代码片段: - AJAX基本示例:此代码演示了使用PHP和JavaScript实现的基本AJAX功能。

sql 这些代码片段将演示如何逐步使用PolyBase。你应该有一个blob存储和存储秘密方便

如何从片段返回主要活动

多片段层次结构中的菜单膨胀问题

如何使用 Android 片段?