www.pudn.com > 嵌入式linux9应用开发祥解.rar > menubutton.c


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 

static HWND hMainWnd = HWND_INVALID;

#define IDC_CTRL1     100
#define IDC_CTRL2     110

static int ControlTestWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    static HWND hChildWnd1, hChildWnd2;
    MENUBUTTONITEM mbi;

    switch (message) {
        case MSG_CREATE:
            hChildWnd1 = CreateWindow ("menubutton", 
                                        "", 
                                        WS_CHILD 
                                        | WS_VISIBLE, 
                                        IDC_CTRL1, 
                                        10, 20, 80, 24, hWnd, 0);
            hChildWnd2 = CreateWindow ("button", 
                                        "Cancel", 
                                        WS_CHILD
                                        | BS_PUSHBUTTON
                                        | WS_VISIBLE, 
                                        IDC_CTRL2, 
                                        100, 20, 60, 24, hWnd, 0);
            mbi.text = "item one";
            mbi.bmp = NULL;
            mbi.data = 0;
            SendMessage (hChildWnd1, MBM_ADDITEM, -1, (LPARAM) &mbi);
            mbi.text = "item two";
            SendMessage (hChildWnd1, MBM_ADDITEM, -1, (LPARAM) &mbi);
            mbi.text = "item three";
            SendMessage (hChildWnd1, MBM_ADDITEM, -1, (LPARAM) &mbi);
            mbi.text = "item four";
            SendMessage (hChildWnd1, MBM_ADDITEM, -1, (LPARAM) &mbi);
        break;

        case MSG_COMMAND:
        {
            int id   = LOWORD(wParam);

            switch (id) {
            case IDC_CTRL1:
            break;
            
            case IDC_CTRL2:
                PostMessage (hWnd, MSG_CLOSE, 0, 0);
            break;
                
            default:
            break;
            }
        }
        break;
       
        case MSG_CLOSE:
            DestroyWindow (hChildWnd1);
            DestroyWindow (hChildWnd2);
            DestroyMainWindow (hWnd);
            MainWindowCleanup (hWnd);
            hMainWnd = HWND_INVALID;
        return 0;
    }

    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}

static void InitCreateInfo(PMAINWINCREATE pCreateInfo)
{
    pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_MINIMIZEBOX 
                                      | WS_MAXIMIZEBOX
                                      | WS_VISIBLE;
    pCreateInfo->dwExStyle = WS_EX_NONE;
    pCreateInfo->spCaption = "MenuButton control" ;
    pCreateInfo->hMenu = 0;
    pCreateInfo->hCursor = GetSystemCursor(1);
    pCreateInfo->hIcon = 0;
    pCreateInfo->MainWindowProc = ControlTestWinProc;
    pCreateInfo->lx = 0; 
    pCreateInfo->ty = 0;
    pCreateInfo->rx = 400;
    pCreateInfo->by = 300;
    pCreateInfo->iBkColor = GetWindowElementColor (BKC_CONTROL_DEF);
    pCreateInfo->dwAddData = 0;
    pCreateInfo->hHosting = HWND_DESKTOP;
}

void menubutton_demo (HWND hwnd)
{
    MAINWINCREATE CreateInfo;

    if (hMainWnd != HWND_INVALID) {
        ShowWindow (hMainWnd, SW_SHOWNORMAL);
        return;
    }

    InitCreateInfo (&CreateInfo);
    CreateInfo.hHosting = hwnd;

    hMainWnd = CreateMainWindow (&CreateInfo);
}