/*----------------------------------------------
GRAFMENU.C -- Demonstrates Bitmap Menu Items
(c) Charles Petzold, 1996
----------------------------------------------*/
#include <windows.h>
#include <string.h>
#include "grafmenu.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
HBITMAP StretchBitmap (HBITMAP) ;
HBITMAP GetBitmapFont (int) ;
char szAppName[] = "GrafMenu" ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HBITMAP hBitmapHelp, hBitmapFile, hBitmapEdit,
hBitmapFont, hBitmapPopFont[3] ;
HMENU hMenu, hMenuPopup ;
HWND hwnd ;
int i ;
MSG msg ;
WNDCLASSEX wndclass ;
wndclass.cbSize = sizeof (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 = NULL ;
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ;
RegisterClassEx (&wndclass) ;
hMenu = CreateMenu () ;
hMenuPopup = LoadMenu (hInstance, "MenuFile") ;
hBitmapFile = StretchBitmap (LoadBitmap (hInstance, "BitmapFile")) ;
AppendMenu (hMenu, MF_BITMAP | MF_POPUP, (int) hMenuPopup,
(PSTR) (LONG) hBitmapFile) ;
hMenuPopup = LoadMenu (hInstance, "MenuEdit") ;
hBitmapEdit = StretchBitmap (LoadBitmap (hInstance, "BitmapEdit")) ;
AppendMenu (hMenu, MF_BITMAP | MF_POPUP, (int) hMenuPopup,
(PSTR) (LONG) hBitmapEdit) ;
hMenuPopup = CreateMenu () ;
for (i = 0 ; i < 3 ; i++)
{
hBitmapPopFont[i] = GetBitmapFont (i) ;
AppendMenu (hMenuPopup, MF_BITMAP, IDM_COUR + i,
(PSTR) (LONG) hBitmapPopFont[i]) ;
}
hBitmapFont = StretchBitmap (LoadBitmap (hInstance, "BitmapFont")) ;
AppendMenu (hMenu, MF_BITMAP | MF_POPUP, (int) hMenuPopup,
(PSTR) (LONG) hBitmapFont) ;
hwnd = CreateWindow (szAppName, "Bitmap Menu Demonstration",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, hMenu, hInstance, NULL) ;
hMenu = GetSystemMenu (hwnd, FALSE);
hBitmapHelp = StretchBitmap (LoadBitmap (hInstance, "BitmapHelp")) ;
AppendMenu (hMenu, MF_SEPARATOR, NULL, NULL) ;
AppendMenu (hMenu, MF_BITMAP, IDM_HELP, (PSTR) (LONG) hBitmapHelp) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
DeleteObject (hBitmapHelp) ;
DeleteObject (hBitmapEdit) ;
DeleteObject (hBitmapFile) ;
DeleteObject (hBitmapFont) ;
for (i = 0 ; i < 3 ; i++)
DeleteObject (hBitmapPopFont[i]) ;
return msg.wParam ;
}
HBITMAP StretchBitmap (HBITMAP hBitmap1)
{
BITMAP bm1, bm2 ;
HBITMAP hBitmap2 ;
HDC hdc, hdcMem1, hdcMem2 ;
TEXTMETRIC tm ;
hdc = CreateIC ("DISPLAY", NULL, NULL, NULL) ;
GetTextMetrics (hdc, &tm) ;
hdcMem1 = CreateCompatibleDC (hdc) ;
hdcMem2 = CreateCompatibleDC (hdc) ;
DeleteDC (hdc) ;
GetObject (hBitmap1, sizeof (BITMAP), (PSTR) &bm1) ;
bm2 = bm1 ;
bm2.bmWidth = (tm.tmAveCharWidth * bm2.bmWidth) / 4 ;
bm2.bmHeight = (tm.tmHeight * bm2.bmHeight) / 8 ;
bm2.bmWidthBytes = ((bm2.bmWidth + 15) / 16) * 2 ;
hBitmap2 = CreateBitmapIndirect (&bm2) ;
SelectObject (hdcMem1, hBitmap1) ;
SelectObject (hdcMem2, hBitmap2) ;
StretchBlt (hdcMem2, 0, 0, bm2.bmWidth, bm2.bmHeight,
hdcMem1, 0, 0, bm1.bmWidth, bm1.bmHeight, SRCCOPY) ;
DeleteDC (hdcMem1) ;
DeleteDC (hdcMem2) ;
DeleteObject (hBitmap1) ;
return hBitmap2 ;
}
HBITMAP GetBitmapFont (int i)
{
static char *szFaceName[3] = { "Courier New", "Arial",
"Times New Roman" } ;
static LOGFONT lf ;
HBITMAP hBitmap ;
HDC hdc, hdcMem ;
HFONT hFont ;
SIZE size ;
TEXTMETRIC tm ;
hdc = CreateIC ("DISPLAY", NULL, NULL, NULL) ;
GetTextMetrics (hdc, &tm) ;
lf.lfHeight = 2 * tm.tmHeight ;
strcpy ((char *) lf.lfFaceName, szFaceName[i]) ;
hdcMem = CreateCompatibleDC (hdc) ;
hFont = (HFONT) SelectObject (hdcMem, CreateFontIndirect (&lf)) ;
GetTextExtentPoint (hdcMem, szFaceName[i], strlen (szFaceName[i]), &size) ;
hBitmap = CreateBitmap (size.cx, size.cy, 1, 1, NULL) ;
SelectObject (hdcMem, hBitmap) ;
TextOut (hdcMem, 0, 0, szFaceName[i], strlen (szFaceName[i])) ;
DeleteObject (SelectObject (hdcMem, hFont)) ;
DeleteDC (hdcMem) ;
DeleteDC (hdc) ;
return hBitmap ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu ;
static int iCurrentFont = IDM_COUR ;
switch (iMsg)
{
case WM_CREATE :
CheckMenuItem (GetMenu (hwnd), iCurrentFont, MF_CHECKED) ;
return 0 ;
case WM_SYSCOMMAND :
switch (LOWORD (wParam))
{
case IDM_HELP :
MessageBox (hwnd, "Help not yet implemented!",
szAppName, MB_OK | MB_ICONEXCLAMATION) ;
return 0 ;
}
break ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDM_NEW :
case IDM_OPEN :
case IDM_SAVE :
case IDM_SAVEAS :
case IDM_UNDO :
case IDM_CUT :
case IDM_COPY :
case IDM_PASTE :
case IDM_DEL :
MessageBeep (0) ;
return 0 ;
case IDM_COUR :
case IDM_ARIAL :
case IDM_TIMES :
hMenu = GetMenu (hwnd) ;
CheckMenuItem (hMenu, iCurrentFont, MF_UNCHECKED) ;
iCurrentFont = LOWORD (wParam) ;
CheckMenuItem (hMenu, iCurrentFont, MF_CHECKED) ;
return 0 ;
}
break ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
vc_menu.rar (34个子文件)
c_menu
POPPAD2.EXE 20KB
NOPOPUPS.MAK 360B
POORMENU.EXE 17KB
GRAFMENU.C 7KB
MENUDEMO.EXE 19KB
MENUDEMO.C 5KB
POPPAD2.MAK 350B
EDITLABL.BMP 190B
MENUDEMO.MAK 360B
GRAFMENU.MAK 419B
NOPOPUPS.C 3KB
POPMENU.EXE 19KB
POPPAD2.C 7KB
NOPOPUPS.H 370B
GRAFMENU.H 396B
GRAFMENU.EXE 21KB
POPMENU.C 5KB
FILELABL.BMP 190B
MENUDEMO.H 551B
MENUDEMO.RC 1KB
POPMENU.H 498B
POORMENU.C 3KB
FONTLABL.BMP 190B
NOPOPUPS.RC 910B
NOPOPUPS.EXE 18KB
BIGHELP.BMP 574B
POORMENU.MAK 243B
POPPAD2.H 418B
GRAFMENU.RC 696B
POPPAD2.ICO 326B
POPMENU.MAK 343B
POPMENU.RC 1KB
POPPAD2.RC 2KB
www.pudn.com.txt 218B
共 34 条
- 1
资源评论
我虽横行却不霸道
- 粉丝: 91
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功