我想在面板上做一个按键,当鼠标点击它就实现与在键盘上按下一个键相同的功能 怎么做
解决方案 »
- CEdit在密码模式下星号如何变为黑点,工程是ANSI版
- BEGIN_MESSAGE_MAP( CMainFrame, CFrameWnd )//宏定义为啥需要CMainFrame与CFrameWnd?
- 求解
- 托盘右击弹出的菜单不可用????
- 在VC下向MySQL数据库添加数据表?
- handwolf(青松崖),请进来领分
- 关于socket的最大并发连接数
- 如何在应用程序中读取USB接口的数据?
- 哪里可以下载最新的Windows SDK?
- 如何实现对象素的操作?
- 有谁知道水晶报表怎样使用啊?提供给我们的接口是什么?在VC下怎样把数据库的内容导入报表?
- 我的窗口用ShowWindow(SW_HIDE)隐藏,如何访止别的程序用ShowWindow(hWnd,SW_SHOW)把我的窗口给显示?
BOOL CUrDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN && pMsg->wParaw==urChar)
{
OnButton1();//ur button function
return TRUE;
}
return CEdit::PreTranslateMessage(pMsg);
}
{keybd_event(..);
...}
WAIT. PLZ
{
// TODO: Add your control notification handler code here
SendMessage(WM_CHAR, 'a');
}void CTest11Dlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar=='a')
{
AfxMessageBox("hello");
}
CDialog::OnChar(nChar, nRepCnt, nFlags);
}
SendMessage(m_pParentHwnd,WM_COMMAND,MAKEWPARAM(ID_BUTTON,BN_CLICKED),(LPARAM)buttonHwnd);
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0 ); // Simulate a key release
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
你可以查msdn 关键字“Virtual-Key Codes”
可以获得所有虚拟健值的信息
完全跟按下键盘按键一样,别忘了发送完按下发送放开。
SendMessage(WM_KEYUP,.....);
This function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. VOID keybd_event(
BYTE bVk,
BYTE bScan,
DWORD dwFlags,
DWORD dwExtraInfo
);
Parameters
bVk
[in] Specifies a virtual-key code. The code must be a value in the range 1 to 254.
bScan
[in] Specifies a hardware scan code for the key. This parameter is not explicitly used.
dwFlags
[in] Specifies various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags. Value Description
KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being depressed.
KEYEVENTF_SILENT If specified, a keystroke is simulated, but no clicking sound is made. dwExtraInfo
[in] Specifies an additional 32-bit value associated with the key stroke.
Return Values
None.Res
When keyboard input is disabled with EnableHardwareKeyboard(FALSE), you can simulate keyboard input using keybd_event.Although keybd_event passes an OEM-dependent hardware scan code to the system, applications should not use the scan code. The system converts scan codes to virtual-key codes internally and clears the up/down bit in the scan code before passing it to applications.The parameters bVk and bScan are treated independently. The OS does not use bVk to generate bScan and does not use bScan to generate bVk.An application can simulate a press of the PRINTSCREEN key in order to obtain a screen snapshot and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT, and the bScan parameter set to 0 for a snapshot of the full screen or set bScan to 1 for a snapshot of the active window.