LoadAccelerators具体用法?(50分)

  • 主题发起人 主题发起人 SonicX
  • 开始时间 开始时间
S

SonicX

Unregistered / Unconfirmed
GUEST, unregistred user!
已在资源文件定义了数条快捷键代码<br>110 ACCELERATORS<br>LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED<br>{<br> &nbsp; &nbsp;&quot;^A&quot;, 20102<br> &nbsp; &nbsp;&quot;^C&quot;, 20103<br> &nbsp; &nbsp;&quot;^V&quot;, 20104<br>}<br>用LoadAccelerators后该在什么事件中去捕获?<br>SDK里还看到要用TranslateAccelerator,不知该怎么操作,还请指教
 
Haccel1:=LoadAccelerators(HInstance,PChar(ACCELERATORS_1)); <br><br> while GetMessage(AMsg,0,0,0) do begin<br> &nbsp; if not Boolean(TranslateAccelerator(AMsg.hwnd,Haccel1,AMsg)) then<br> &nbsp; begin<br> &nbsp; &nbsp; TranslateMessage(AMsg);<br> &nbsp; &nbsp; DispatchMessage(AMsg);<br> &nbsp; end;<br> end;
 
楼上正解!补充一下,快捷键消息是不放到消息对列中的,直接发送到应用程序.
 
while那段应该放在哪?线程里面?<br>楼上能不能给出稍微完整点的?
 
放在线程里做什么? 既然是消息就在消息循环里接收并处理就行了!接收一下.WM_SYSKEYUP,WM_SYSKEYDOWN<br>不明白使用Delphi为什么要自己定义加速键呢!!用现成的多好啊!!!
 
谢谢,我试试<br>主要是MENU也是在资源文件里定义的,想简化操作
 
似乎不行,帮忙看看<br>procedure WMKeyDown(var Msg:TMsg); message WM_SYSKEYDOWN;<br>procedure WMCommand(var Msg:TWMCommand); Message WM_COMMAND;<br>..........<br>..........<br>var<br> MenuAccel:HACCEL;<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>MenuAccel:=LoadAccelerators(HInstance,MAKEINTRESOURCE(110));<br>end;<br>..........<br>..........<br>procedure TForm1.WMKeyDown(var Msg: TMsg);<br>begin<br> while GetMessage(Msg,0,0,0) do begin<br> &nbsp; if not Boolean(TranslateAccelerator(Msg.hwnd,MenuAccel,Msg)) then<br> &nbsp; begin<br> &nbsp; &nbsp; TranslateMessage(Msg);<br> &nbsp; &nbsp; DispatchMessage(Msg);<br> &nbsp; end;<br> end;<br>end;<br><br>procedure TForm1.WMCommand(var Msg:TWMCommand);<br>begin<br> inherited<br> case Msg.ItemID of<br> 20102:showmessage('20102');<br> 20103:showmessage('20103');<br> 20104:showmessage('20104');<br> end;<br>end;
 
多人接受答案了。
 

Similar threads

后退
顶部