BitmapMenu.docx

上传人:b****6 文档编号:5995511 上传时间:2023-01-02 格式:DOCX 页数:8 大小:16.93KB
下载 相关 举报
BitmapMenu.docx_第1页
第1页 / 共8页
BitmapMenu.docx_第2页
第2页 / 共8页
BitmapMenu.docx_第3页
第3页 / 共8页
BitmapMenu.docx_第4页
第4页 / 共8页
BitmapMenu.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

BitmapMenu.docx

《BitmapMenu.docx》由会员分享,可在线阅读,更多相关《BitmapMenu.docx(8页珍藏版)》请在冰豆网上搜索。

BitmapMenu.docx

BitmapMenu

#include

#include"resource.h"

VOIDWINAPILoadChartBitmaps(HBITMAP*paHbm);

VOIDWINAPICreateLineBitmaps(HBITMAP*paHbm,HWNDhwnd);

VOIDWINAPIAddBitmapMenu(HWNDhwnd,LPTSTRlpszText,UINTuID,HBITMAP*paHbm,intcItems);

LRESULTCALLBACKMainWindowProc(HWNDhwnd,UINTuMsg,WPARAMwParam,LPARAMlParam);

//Menu-itemidentifiers

#defineIDM_SOLID500

#defineIDM_DASH501

#defineIDM_DOT502

#defineIDM_DASHDOT503

#defineIDM_DASHDOTDOT504

//NumberofitemsontheChartandLinesmenus

#defineC_LINES5

#defineC_CHARTS3

//Dimensionsofthelinebitmaps

#defineCX_LINEBMP40

#defineCY_LINEBMP10

 

HINSTANCEg_hinst;

intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,

PSTRszCmdLine,intiCmdShow)

{

TCHARszAppName[16],szCaption[64],szErrMsg[64];

HWNDhwnd;

MSGmsg;

WNDCLASSwndclass;

LoadString(hInstance,IDS_APPNAME,szAppName,

sizeof(szAppName)/sizeof(TCHAR));

LoadString(hInstance,IDS_CAPTION,szCaption,

sizeof(szCaption)/sizeof(TCHAR));

wndclass.style=CS_HREDRAW|CS_VREDRAW;

wndclass.lpfnWndProc=MainWindowProc;

wndclass.cbClsExtra=0;

wndclass.cbWndExtra=0;

wndclass.hInstance=hInstance;

wndclass.hIcon=LoadIcon(hInstance,szAppName);

wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);

wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

wndclass.lpszMenuName=szAppName;

wndclass.lpszClassName=szAppName;

if(!

RegisterClass(&wndclass))

{

LoadStringA(hInstance,IDS_APPNAME,(char*)szAppName,

sizeof(szAppName));

LoadStringA(hInstance,IDS_ERRMSG,(char*)szErrMsg,

sizeof(szErrMsg));

MessageBoxA(NULL,(char*)szErrMsg,

(char*)szAppName,MB_ICONERROR);

return0;

}

g_hinst=hInstance;

hwnd=CreateWindow(szAppName,szCaption,

WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,

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);

}

returnmsg.wParam;

}

LRESULTCALLBACKMainWindowProc(HWNDhwnd,UINTuMsg,WPARAMwParam,LPARAMlParam)

{

staticHBITMAPaHbmLines[C_LINES];

staticHBITMAPaHbmChart[C_CHARTS];

inti;

switch(uMsg)

{

caseWM_CREATE:

//Callapplication-definedfunctionstoloadthe

//bitmapsfortheChartmenuandcreatethosefor

//theLinesmenu.

LoadChartBitmaps(aHbmChart);

CreateLineBitmaps(aHbmLines,hwnd);

//Callanapplication-definedfunctiontocreate

//menuscontainingthebitmapmenuitems.Thefunction

//alsoaddsamenunametothewindow'smenubar.

AddBitmapMenu(

hwnd,//menubar'sownerwindow

TEXT("&Chart"),//textofmenunameonmenubar

IDB_PIE,//IDoffirstitemonmenu

aHbmChart,//arrayofbitmaphandles

C_CHARTS//numberofitemsonmenu

);

AddBitmapMenu(hwnd,TEXT("&Lines"),IDM_SOLID,

aHbmLines,C_LINES);

DrawMenuBar(hwnd);

break;

caseWM_DESTROY:

for(i=0;i

DeleteObject(aHbmLines[i]);

for(i=0;i

DeleteObject(aHbmChart[i]);

PostQuitMessage(0);

break;

//Processadditionalmessageshere.

default:

return(DefWindowProc(hwnd,uMsg,wParam,lParam));

}

return0;

}

 

VOIDWINAPILoadChartBitmaps(HBITMAP*paHbm)

{

paHbm[0]=LoadBitmap(g_hinst,MAKEINTRESOURCE(IDB_PIE));

paHbm[1]=LoadBitmap(g_hinst,MAKEINTRESOURCE(IDB_LINE));

paHbm[2]=LoadBitmap(g_hinst,MAKEINTRESOURCE(IDB_BAR));

}

VOIDWINAPICreateLineBitmaps(HBITMAP*paHbm,HWNDhwnd)

{

HDChdc=GetDC(hwnd);

HDChdcMem=CreateCompatibleDC(hdc);

COLORREFclrMenu=GetSysColor(COLOR_MENU);

HBRUSHhbrOld;

HPENhpenOld;

HBITMAPhbmOld;

intfnDrawMode;

inti;

//Createabrushusingthemenubackgroundcolor,

//andselectitintothememoryDC.

hbrOld=SelectObject(hdcMem,CreateSolidBrush(clrMenu));

//Createthebitmaps.Selecteachoneintothememory

//DCthatwascreatedanddrawinit.

for(i=0;i

{

//CreatethebitmapandselectitintotheDC.

paHbm[i]=CreateCompatibleBitmap(hdc,

CX_LINEBMP,CY_LINEBMP);

hbmOld=SelectObject(hdcMem,paHbm[i]);

//Fillthebackgroundusingthebrush.

PatBlt(hdcMem,0,0,CX_LINEBMP,CY_LINEBMP,PATCOPY);

//CreatethepenandselectitintotheDC.

hpenOld=SelectObject(hdcMem,

CreatePen(PS_SOLID+i,1,RGB(0,0,0)));

//Drawtheline.Topreservethebackgroundcolorwhere

//thepeniswhite,usetheR2_MASKPENdrawingmode.

fnDrawMode=SetROP2(hdcMem,R2_MASKPEN);

MoveToEx(hdcMem,0,CY_LINEBMP/2,NULL);

LineTo(hdcMem,CX_LINEBMP,CY_LINEBMP/2);

SetROP2(hdcMem,fnDrawMode);

//Deletethepen,andselecttheoldpenandbitmap.

DeleteObject(SelectObject(hdcMem,hpenOld));

SelectObject(hdcMem,hbmOld);

}

//Deletethebrushandselecttheoriginalbrush.

DeleteObject(SelectObject(hdcMem,hbrOld));

//DeletethememoryDCandreleasethedesktopDC.

DeleteDC(hdcMem);

ReleaseDC(hwnd,hdc);

}

 

VOIDWINAPIAddBitmapMenu(

HWNDhwnd,//windowthatownedthemenubar

LPTSTRlpszText,//textofmenunameonmenubar

UINTuID,//IDoffirstbitmapmenuitem

HBITMAP*paHbm,//bitmapsforthemenuitems

intcItems)//numberbitmapmenuitems

{

HMENUhmenuBar=GetMenu(hwnd);

HMENUhmenuPopup=CreatePopupMenu();

MENUITEMINFOmii;

inti;

//Addthebitmapmenuitemstothemenu.

mii.cbSize=sizeof(MENUITEMINFO);

for(i=0;i

{

mii.fMask=MIIM_ID|MIIM_BITMAP;

mii.wID=uID+i;

mii.hbmpItem=paHbm[i];

//mii.dwItemData=IDStart+i;

InsertMenuItem(hmenuPopup,i,TRUE,&mii);

}

//Addamenunametothemenubar.

mii.fMask=MIIM_STRING|MIIM_DATA|MIIM_SUBMENU;

mii.fType=MFT_STRING;

mii.hSubMenu=hmenuPopup;

mii.dwTypeData=lpszText;

InsertMenuItem(hmenuBar,

GetMenuItemCount(hmenuBar),TRUE,&mii);

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1