lcc-win32中如何添加资源文件?
这是我拷的代码不知哪里错了,无法调用资源?程序代码:
/*@@ Wedit generated application. Written Fri Mar 07 11:23:58 2014 @@header: d:\lcc\menu1\menu1res.h @@resources: d:\lcc\menu1\menu1.rc Do not edit outside the indicated areas */ /*<---------------------------------------------------------------------->*/ /*<---------------------------------------------------------------------->*/ #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "menu1res.h" HMENU hmenu,hprintmenu; LRESULT CALLBACK WndProc (HWND,UINT, WPARAM,LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevlnst, LPSTR lpszCmdLine,int nCmdShow) { //int nMode; HWND hwnd; MSG Msg; WNDCLASS wndclass; char lpszMenuName[]="Menu"; char lpszClassName[]="菜单"; char lpszTitle[]="Menu1"; wndclass.style=0; 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= GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName=lpszMenuName; wndclass.lpszClassName=lpszClassName; if(!RegisterClass(&wndclass)) { MessageBeep(0); return FALSE; } hwnd=CreateWindow ( lpszClassName, lpszTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while (GetMessage(&Msg,NULL,0,0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { //HDC hdc; //PAINTSTRUCT ps; //HPEN hP; //HBRUSH hB1,hB2; //static int nMode; switch(message) { case WM_COMMAND: //nMode=MM_TEXT; switch(LOWORD(wParam)) { case IDM_NEW: break; case IDM_OPEN: break; case IDM_SAVE: break; case IDM_SAVEAS: break; case IDM_CLOSE: break; case IDM_ADDPRINTMENU: hmenu=GetMenu(hwnd); hprintmenu=CreateMenu(); AppendMenu(hprintmenu,MF_GRAYED,IDM_LINE,"线条"); AppendMenu(hprintmenu,MF_GRAYED,IDM_RECT,"矩形"); AppendMenu(hprintmenu,MF_GRAYED,IDM_RRECT,"圆角矩形"); AppendMenu(hprintmenu,MF_GRAYED,IDM_ELLIP,"椭圆"); InsertMenu(hmenu,2,MF_POPUP|MF_BYPOSITION,(UINT)hprintmenu,"绘图(&P)"); EnableMenuItem(hmenu,IDM_ADDPRINTMENU,MF_GRAYED); EnableMenuItem(hmenu,IDM_DELPRINTMENU,MF_ENABLED); DrawMenuBar(hwnd); break; case IDM_DELPRINTMENU: DeleteMenu(hmenu,2,MF_BYPOSITION); EnableMenuItem(hmenu,IDM_ADDPRINTMENU,MF_ENABLED); EnableMenuItem(hmenu,IDM_DELPRINTMENU,MF_GRAYED); DrawMenuBar(hwnd); //break; //nMode=MM_ISOTROPIC; //nMode=MM_LOMETRIC; //InvalidateRect(hwnd,NULL,1); break; case IDM_EXIT: //nMode=MM_ANISOTROPIC; //InvalidateRect(hwnd,NULL,1); SendMessage(hwnd,WM_DESTROY,0,0); break; case IDM_CUT: break; case IDM_COPY: break; case IDM_PASTE: break; case IDM_DELETE: break; } case WM_DESTROY: //DeleteObject(hB1); //DeleteObject(hB2); PostQuitMessage(0); break; default: return DefWindowProc(hwnd,message,wParam,lParam); } return 0; }这里是rc文件和头文件
程序代码:
#include <windows.h> #include "menu1res.h" Menu1 MENU { POPUP"文件(&F)" { MENUITEM "新建(&N)\tCtrl+N",IDM_NEW MENUITEM "打开(&O)\tCtrl+O",IDM_OPEN MENUITEM "关闭(&C)\tCtrl+N",IDM_CLOSE MENUITEM SEPARATOR MENUITEM "保存(&S)\tCtrl+S",IDM_SAVE MENUITEM "另存为(&A)",IDM_SAVEAS MENUITEM SEPARATOR MENUITEM "创建绘图菜单项(&P)\tCtrl+P",IDM_ADDPRINTMENU MENUITEM "删除绘图菜单项(&D)\tCtrl+D",IDM_EDLPRINTMENU,GRAYED MENUITEM SEPARATOR MENUITEM "退出(&X)\tCtrl+N",IDM_EXIT } POPUP"编辑(&E)" { MENUITEM "剪切(&T)\tCtrl+X",IDM_CUT MENUITEM "复制(&C)\tCtrl+C",IDM_COPY MENUITEM "粘贴(&P)\tCtrl+V",IDM_PASTE MENUITEM "删除(&D)\tDel",IDM_DELETE } MENUITEM "帮助(&H)",IDM_HELP } Menu1 ACCELERATORS { "^N",IDM_NEW "^O",IDM_OPEN "^S",IDM_SAVE "^P",IDM_ADDPRINTMENU "^D",IDM_DELPRINTMENU "^X",IDM_CUT "^C",IDM_COPY "^V",IDM_PASTE VK_DELETE,IDM_DELETE,VIRTKEY } #define IDM_NEW 10 #define IDM_OPEN 11 #define IDM_CLOSE 12 #define IDM_SAVE 13 #define IDM_SAVEAS 14 #define IDM_ADDPRINTMENU 15 #define IDM_DELPRINTMENU 16 #define IDM_EXIT 17 #define IDM_CUT 18 #define IDM_COPY 19 #define IDM_PASTE 20 #define IDM_DELETE 21 #define IDM_HELP 22 #define IDM_LINE 23 #define IDM_RECT 24 #define IDM_RRECT 25 #define IDM_ELLIP 26.h和.c和.rc在同一目录下
[ 本帖最后由 zcl2013c 于 2014-3-11 15:21 编辑 ]