SDK编程再次提问,我的加速键为什么有问题?

zpx833 2008-02-20 08:02:58
我的加速键程序出什么问题了,能帮我改一个成功的吗?
加速键.h
#define IDA_TEST 10
#define IDA_TESTT 11
#define IDA_TESTTT 12
#define IDA_TESTTTT 13
#define IDA_TESTTTTT 14
加速键.rc
#include <windows.h>
#include "加速键.h"
MyAccel MENU
{
POPPU "加速键测试"
{
MENUITEM "TEST",IDA_TEST
MENUITEM "TSETT",IDA_TESTT
MENUITEM "TESTTT",IDA_TESTTT
MENUITEM "TESTTTT",IDA_TESTTTT
MENUITEM "TESTTTTT",IDA_TESTTTTT
}
}
MyAccel ACCELERATORS
{
"^C", IDA_TEST, ASCII
"A", IDA_TESTT, ASCII, SHIFT
"B", IDA_TESTTT, ASCII, ALT
"D" IDA_TESTTTT, ASCII, SHIFT ,ALT
VK_F1, IDA_TESTTTTT, VIRTKEY
}加速键.cpp
#include <windows.h>
#include "加速键.h"

LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam ,LPARAM lParam)
{
int i;
switch(message)
{
case WM_COMMAND:
i=LOWORD(wParam);
switch(i)
{
case IDA_TEST:
MessageBox(hWnd,"TEST","成功",MB_OK);
break;
case IDA_TESTT:
MessageBox(hWnd,"TESTT","成功",MB_OK);
break;
case IDA_TESTTT:
MessageBox(hWnd,"TESTTT","成功",MB_OK);
break;
case IDA_TESTTTT:
MessageBox(hWnd,"TESTTTT","成功",MB_OK);
break;
case IDA_TESTTTTT:
MessageBox(hWnd,"TESTTTTT","成功",MB_OK);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);

}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hpInstance,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hWnd;
MSG msg;
HACCEL hAccel;
WNDCLASS wc;
char lpszClassName[]="加速键";
char lpszTitle[]="加速键";
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName=lpszClassName;
wc.lpszMenuName=0;
wc.style=0;
hAccel=LoadAccelerators(hInstance,"MyAccel");
if(!RegisterClass(&wc))
{
MessageBox(NULL,"注册失败",NULL,MB_OK);
return 0;
}
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))
{
if(!TranslateAccelerator(hWnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return 0;
}
...全文
53 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
UltraBejing 2008-05-01
支持搂主,收藏
回复
以后需再关注,现在先帮你顶一下
回复
leble 2008-02-28
加速键.rc
#include <windows.h>
#include "加速键.h"
MyAccel MENU
BEGIN
POPUP "加速键测试"
BEGIN
MENUITEM "TEST", IDA_TEST
MENUITEM "TSETT", IDA_TESTT
MENUITEM "TESTTT", IDA_TESTTT
MENUITEM "TESTTTT", IDA_TESTTTT
MENUITEM "TESTTTTT", IDA_TESTTTTT
END
END

MyAccel ACCELERATORS
BEGIN
"^C", IDA_TEST, ASCII
"A", IDA_TESTT, VIRTKEY, SHIFT
"B", IDA_TESTTT, VIRTKEY, ALT
"D", IDA_TESTTTT, VIRTKEY, SHIFT, ALT
VK_F1, IDA_TESTTTTT, VIRTKEY
END
回复
cnzdgs 2008-02-20
同意1楼。
按F1也无效吗?
回复
jameshooo 2008-02-20
while(GetMessage(&msg,NULL,0,0))
{
if(!IsDialogMessage(hWnd,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
回复
crumpy 2008-02-20
[code=BatchFile]"A", ID_ACCEL1 ; SHIFT+A
65, ID_ACCEL2, ASCII ; SHIFT+A [/code]
要是用"A", 后面就不要用ASCII了

一个例子:

[code=BatchFile]FileAccel ACCELERATORS
BEGIN
VK_F12, IDM_OPEN, CONTROL, VIRTKEY ; CTRL+F12
VK_F4, IDM_CLOSE, ALT, VIRTKEY ; ALT+F4
VK_F12, IDM_SAVE, SHIFT, VIRTKEY ; SHIFT+F12
VK_F12, IDM_SAVEAS, VIRTKEY ; F12
END

FilePopup MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New..", IDM_NEW
MENUITEM "&Open\tCtrl+F12", IDM_OPEN
MENUITEM "&Close\tAlt+F4" IDM_CLOSE
MENUITEM "&Save\tShift+F12", IDM_SAVE
MENUITEM "Save &As...\tF12", IDM_SAVEAS
END
END[/code]

你查一下你的LoadAcceleratror()成功了吗?
回复
crumpy 2008-02-20
在wc.lpszMenuName=0;没有为你的窗口类指定类菜单

在CreateWindow(lpszClassName,lpszTitle,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
也没有为你要创建的窗口指定窗口实例菜单
回复
zpx833 2008-02-20
错误提示为:从rc返回错误
楼上的答案都不对
更正:
MyAccel MENU
{
POPUP "加速键测试" ;写成POPPU了
{
MENUITEM "TEST",IDA_TEST
MENUITEM "TSETT",IDA_TESTT
MENUITEM "TESTTT",IDA_TESTTT
MENUITEM "TESTTTT",IDA_TESTTTT
MENUITEM "TESTTTTT",IDA_TESTTTTT
}
}

我用楼上的方法改了我的前一个菜单程序,正确了,但是,这个程序咋改都不对,想知道这个程序的问题,谢谢,
回复
相关推荐
发帖
资源
创建于2007-09-28

2579

社区成员

VC/MFC 资源
申请成为版主
帖子事件
创建了帖子
2008-02-20 08:02
社区公告
暂无公告