| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1227 人关注过本帖
标题:vc++如何加载菜单,以下代码请帮我看一下,各路高手,
只看楼主 加入收藏
whyan
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-10-4
收藏
 问题点数:0 回复次数:1 
vc++如何加载菜单,以下代码请帮我看一下,各路高手,
这是Menu.h文件
#include "windows.h"

#define IDM_NEW    10
#define IDM_OPEN   20
#define IDM_CLOSE  30
#define IDM_SAVE   40
#define IDM_SAVEAS 50
#define IDM_EXIT   60





这是test.cpp文件
#include "windows.h"
#include "stdio.h"
#include "string.h"
#include "Menu.h"

//定义菜单

Menu MENU MOVEABLE
{
    
        POPUP"文件(&F)"   //弹出式菜单
        {
                
            MENUITEM"新建(&N)",IDM_NEW
            MENUITEM"打开(&O)",IDM_OPEN
            MENUITEM"关闭(&C)",IDM_CLOSE
            MENUITEM"保存(&S)",IDM_SAVE
            MENUITEM"另存为(&A)",IDM_SAVEAS
            MENUITEM"退出(&E)",IDM_EXIT        
            
        }
    
}


LRESULT CALLBACK WinProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam);


int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
        {
            HWND hWnd;
            MSG Message;
            WNDCLASS WndClass;
            WndClass.hInstance=hInstance;
            WndClass.lpfnWndProc=WinProc;
            WndClass.lpszClassName="whyan";
            WndClass.lpszMenuName="Menu";
            WndClass.style=CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
            WndClass.cbClsExtra=0;
            WndClass.cbWndExtra=0;
            WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
            WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
            WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
            RegisterClass(&WndClass);

            hWnd=CreateWindow("whyan","whyan",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
            ShowWindow(hWnd,SW_SHOWNORMAL);
            UpdateWindow(hWnd);

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

LRESULT CALLBACK WinProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
        {
            HDC hdc;
            HBRUSH hbrush;
            HPEN pen;
            PAINTSTRUCT pstr;

            int x,y;
            HCURSOR cursor;
               
            switch (Message)
            {
            case WM_PAINT:
                hdc=BeginPaint(hWnd,&pstr);
                SetMapMode(hdc,MM_ANISOTROPIC);
                pen=(HPEN)GetStockObject(BLACK_PEN);
                hbrush=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
                SelectObject(hdc,hbrush);
                SelectObject(hdc,pen);
                RoundRect(hdc,50,120,100,200,15,15);
                EndPaint(hWnd,&pstr);
                break;
            case WM_LBUTTONDOWN:
                //MessageBox(hWnd,"你按下了左键","infomation",MB_OK);
                if(wParam&MK_CONTROL)
                {
                    MessageBox(hWnd,"你按下了control键","infomation",MB_OK);
                }
                if(wParam&MK_SHIFT)
                {
                    MessageBox(hWnd,"你按下了shift键","infomation",MB_OK);
                }
                break;
            case WM_MBUTTONDOWN:
                MessageBox(hWnd,"你按下了中健","infomation",MB_OK);
                break;
            case WM_RBUTTONDOWN:
                MessageBox(hWnd,"你按下了右键","infomation",MB_OK);
                break;
            case WM_LBUTTONDBLCLK:
                MessageBox(hWnd,"你双击了左键","infomation",MB_OK);
                break;
            case WM_MOUSEMOVE:
                x=LOWORD(lParam);//取得lParam的低位值
                y=HIWORD(lParam);//取得lParam的高位值

                if(x>50&&x<400&&y>50&&y<400)
                {
                    if(x>=50&&x<=100&&y>=50&&y<=100)
                        {
                            cursor=LoadCursor(NULL,IDC_WAIT);
                            SetCursor(cursor);
                        }
                    if(x>=100&&x<=400&&y>=100&&y<=400)
                        {
                            cursor=LoadCursor(NULL,IDC_CROSS);
                            SetCursor(cursor);                        
                        }
                
                }
                break;
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            default:
                return(DefWindowProc(hWnd,Message,wParam,lParam));
            }
            return 0;
        }
搜索更多相关主题的帖子: 加载 菜单 代码 
2008-10-05 15:04
沼泽
Rank: 4
等 级:业余侠客
威 望:8
帖 子:291
专家分:228
注 册:2008-9-15
收藏
得分:0 
wc.lpszMenuName     = MAKEINTRESOURCE(LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU)));
2008-10-05 16:30
快速回复:vc++如何加载菜单,以下代码请帮我看一下,各路高手,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030921 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved