无法消除巨大的怪异叮当声 [英] can't get rid of loud freakin dinging noise

查看:73
本文介绍了无法消除巨大的怪异叮当声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是写了这个,并使用了SetWindowSubclass,有一次,我所做的几乎没有麻烦.几乎.当我在编辑控件的子类具有焦点的情况下按键盘上的Enter键时,它恰好实现了我想要的功能.除此以外,每次我按它时,都会发出很大的嗡嗡声.反正有解决办法吗?

Hi, i just wrote this and used SetWindowSubclass and for once, something i did worked almost without a hitch. ALMOST. when i press enter on the keyboard while the edit control it''s subclassed to has the focus, it does precisely what i want it to. EXCEPT, that every time i press it, it makes a loud f***ing dinging noise. Is there anyway to fix this?

LRESULT CALLBACK EditSubclass(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
	switch (msg)
	{
		case WM_KEYDOWN:
		{
			switch(wParam)
			{
				case VK_RETURN:
				{
					SendMessage(sendbutton, BM_CLICK, 0, 0);
					SetFocus(editbox);
				}
			}
			return TRUE;
		}
	}
	return DefSubclassProc(hwnd, msg, wParam, lParam);
}

推荐答案

之所以发出蜂鸣声是因为,作为单行,按Enter键被认为是尝试插入另一行.
在对话框上,Enter键被对话框过程捕获,并发送到默认按钮(如果有),否则留给编辑控件本身.
在其他窗口上,此类陷阱"需要一个messge循环,该循环在分发到焦点窗口之前检查对话框消息的存在.


It beeps because, being a single line, pressing enter is considered an attempt to insert another line.

On dialog boxes, the Enter key is trapped by the dialog procedure and sent to the default pushbutton (if any), otherwise left to the edit control itself.
On other window, such "trapping" requires a messge-loop that check the presence of a dialog message before dispatching to the focused window.

Something like
/* Window procedure definition */
LRESULT WINAPI CALLBACK winproc(HWND h, UINT m, WPARAM w, LPARAM z)
{
    ....
}


/* may be WinMain, _tmain, _tWinMain or whatever entry point */
int main() 
{
    /* Class registration stuff */
    WNDCLASSEX wcx = { ..... };
    ....
    RegisterWindowClassEx(&wcx);

    
    /* WIndow Creation */ 
    HWND hwnd = CreateWindow( .... );
    ....
    
    /* messge loop */
    for(;;)
    {
        MSG msg;
        if(GetMessage(&msg,0,0,0)<=0) break; //< exit on error or "quit" 
        if(IsDialogMessage(hwnd,&msg)) continue; //< skip regular dispatching
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}


我不确定这是否有帮助.我在子类控件上遇到了相同的叮叮问题,发现该问题是由吞咽" WM_KEYDOWN引起的.
在消息循环中,WM_KEYDOWN + WM_KEYUP = WM_CHAR.系统在没有WM_KEYDOWN的情况下看到WM_KEYUP时,就会响起叮当声.
I am not sure if this is any help. I have had the same dinging problem on sub classed controls and found the problem was caused by ''swallowing'' the WM_KEYDOWN.
In the message loop WM_KEYDOWN + WM_KEYUP = WM_CHAR. Ding occurs when system sees WM_KEYUP without WM_KEYDOWN.


我在Google上搜索了输入编辑控制提示音",并且第一个结果包含以下内容:

ES_MULTILINE

指定多行编辑控件.默认为单行编辑控件.

当多行编辑控件在对话框中时,按ENTER键的默认响应是激活默认按钮.要将ENTER键用作回车键,请使用ES_WANTRETURN样式.

当多行编辑控件不在对话框中并且指定了ES_AUTOVSCROLL样式时,编辑控件将显示尽可能多的行,并在用户按下ENTER键时垂直滚动.如果未指定ES_AUTOVSCROLL,则编辑控件将显示尽可能多的行,如果在没有更多行可以显示的情况下用户按ENTER键,则会发出哔声.
I did a google search for "enter edit control beep" and the first result contains the following:

ES_MULTILINE

Designates a multiline edit control. The default is single-line edit control.

When the multiline edit control is in a dialog box, the default response to pressing the ENTER key is to activate the default button. To use the ENTER key as a carriage return, use the ES_WANTRETURN style.

When the multiline edit control is not in a dialog box and the ES_AUTOVSCROLL style is specified, the edit control shows as many lines as possible and scrolls vertically when the user presses the ENTER key. If you do not specify ES_AUTOVSCROLL, the edit control shows as many lines as possible and beeps if the user presses the ENTER key when no more lines can be displayed.


这篇关于无法消除巨大的怪异叮当声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆