菜单 图标

VC 插入菜单--资源,新建一个菜单和加入一个图标

#include "windows.h"

#include "resource.h"

char szWindowClass[] = "演示程序";
char szWindowsTite[] = "主窗口标题";


LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
WORD wmID;
WORD wmEvent;


switch(uMsg)
{
HDC hdc;
/* HWND hwnd;*/
WORD wMouseX;
WORD wMouseY;
PAINTSTRUCT ps;


case WM_DESTROY:
PostQuitMessage(0);
break;


case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
MessageBox(hwnd,"ESC","消息框",MB_OK);
break;
}
break;
case WM_KEYUP:
switch(wParam)
{
case VK_RETURN:
MessageBox(hwnd,"Enter","消息框",MB_OK);
break;
}
break;


case WM_RBUTTONDOWN:
MessageBox(hwnd,"鼠标右键按下","消息框",MB_OK);
break;


case WM_COMMAND:
wmID=LOWORD(wParam);
wmEvent=HIWORD(wParam);
switch(wmID)
{
case IDM_EXIT:
DestroyWindow(hwnd);
PostQuitMessage(0);
break;


case IDM_SHOW:
MessageBox(hwnd,"去你妈的","提示",MB_OK);
break;
}
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);


}
}


int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE, LPTSTR lpCmdLine, int nCmdShow)
{
//填充窗口类
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc= (WNDPROC)WndProc;
wcex.cbClsExtra= 0;
wcex.cbWndExtra= 0;
wcex.hInstance= hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON3));//加入图标函数LoadIcon
wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW +1);
wcex.lpszMenuName= NULL;
wcex.lpszClassName= szWindowClass;
wcex.hIconSm = NULL;

//注册窗口类
RegisterClassEx(&wcex);

//创建窗口
HWND hWnd = CreateWindowEx(
0, 
szWindowClass,
szWindowsTite,
WS_OVERLAPPEDWINDOW,
128,
96,
640,
480,
HWND_DESKTOP,
LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)),//菜单函数LoadMenu
hInstance,
NULL);

//创建窗口失败
if(!hWnd)
return 0;

//显示并更新窗口
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);

//设置消息循环
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 1;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值