Tastatureingaben abfangen
-
Wie kann ich in einem Dialog mit aktiven Steuerelement Tastatureingaben abfangen. Ich hab auch probiert die Steuerelemente zur Laufzeit zu deaktivieren, aber das klappt nicht.
Und gibt es eine einfache Möglichkeit abzufragen ob zwei bestimmte Tasten(gleichzeitig) gedrückt wurden?
thx
-
Servus,
also während der Laufzeit kannst du super mit "EnableWindow(FALSE)" ein Control deaktivieren und mit "TRUE" wieder aktivieren. Also das geht aufjedenfall. Du brauchst halt entweder eine Membervar oder einen Zeiger von dem Control.
Das Zweite müsstest du ein wenig erklären....
Wie kann man denn zwei gleichzeitig drücken?
Du könntest doch einfach für beide eine Func erstellen und dann einen boolschen Wert irgendwie setzen.BOOL bFeld1 = FALSE, bFeld2 = FALSE; void CDlg::EinsGedrückt() { bFeld1 = TRUE; } void CDlg::ZweiGedrückt() { bFeld2 = TRUE; }Dann erfährst du aber ob beide gedrückt worden sind.
*winke*
Hellsgore
-
EnableWindow(FALSE)?
Möglicherweise hab ich es mit ShowWindow(FALSE) probiert und deshalb gings nicht.
Wie kann man denn zwei gleichzeitig drücken?
Hasst du noch nie zwei Tasten gleichzeitig gedrückt?

-
Servus,
MSDN:
Parameters
bEnable
Specifies whether the given window is to be enabled or disabled. If this parameter is TRUE, the window will be enabled. If this parameter is FALSE, the window will be disabled.Return Value
Indicates the state before the EnableWindow member function was called. The return value is nonzero if the window was previously disabled. The return value is 0 if the window was previously enabled or an error occurred.Remarks
When input is disabled, input such as mouse clicks and keystrokes is ignored. When input is enabled, the window processes all input.
If the enabled state is changing, the WM_ENABLE message is sent before this function returns.If disabled, all child windows are implicitly disabled, although they are not sent WM_ENABLE messages.
A window must be enabled before it can be activated. For example, if an application is displaying a modeless dialog box and has disabled its main window, the main window must be enabled before the dialog box is destroyed. Otherwise, another window will get the input focus and be activated. If a child window is disabled, it is ignored when Windows tries to determine which window should get mouse messages.
By default, a window is enabled when it is created. An application can specify the WS_DISABLED style in the Create or CreateEx member function to create a window that is initially disabled. After a window has been created, an application can also use the EnableWindow member function to enable or disable the window.An application can use this function to enable or disable a control in a dialog box. A disabled control cannot receive the input focus, nor can a user access it.
Example
//CMyFileDialog is a CFileDialog-derived class
//OnInitDialog is the handler for WM_INITDIALOG
BOOL CMyFileDialog::OnInitDialog()
{
CFileDialog::OnInitDialog();CWnd* pWndParent = GetParent();
//make sure you add #include <dlgs.h> for IDs 'edt1' & 'stc3'
//disables the 'file name' edit and static control
//of the standard file open dialog//get handle of 'file name' edit control & disable it
CWnd* pWnd = pWndParent->GetDlgItem(edt1);
pWnd->EnableWindow(FALSE);//get handle of 'file name' static control & disable it
pWnd = pWndParent->GetDlgItem(stc3);
pWnd->EnableWindow(FALSE);return TRUE;
}Ajo damit kann man die aktivieren oder deaktivieren.
Achsoooooo jetzt weiss ich was du meinst. Benutz doch einfach Accelatoren. Ausser du möchtest alle Tasten abfangen, benuzten oder weiterleiten. Dann machste einen Keyboardhook. Kann dir aber dazu noch ein Beispiel geben wenn du sowas haben willst.
*winke*
Hellsgore
-
Ich werd mal noch'n biss'L rumprobieren, werd das schon hinkriegen
thx
-
Ich hab den Mist net hinbekommen.

Warum funktioniert WM_KEYDOWN nicht, wenn ich zur Laufzeit alle Steuerelemente deaktiviert habe?
Wenn sie vorher deaktiviert sind geht das doch auch, aber wenn sie erst später(zur laufzeit) deaktiviert werden klappt das nicht, ich raff dat net.
Wie bekommt man das hin?
-
Hallo ChYu Chen,
mir fallen zwei auf Anhieb zwei Möglichkeiten ein:
Methode 1: (Unfein!)
BOOL YourDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN) { // Abgefangen } return CDialog::PreTranslateMessage(pMsg); }Methode 2: (Besser!)
Von Deinem Steuerelement eine eigene Klasse ableiten und dort OnKeyDown(...)
abfangen.Gruß
Chris
-
Was ist denn an der ersten Methode so unfein?
zur zweiten: das müsste ich dann theoretisch für jedes aktive Steuerelemt machen oder wie?

-
Hallo ChYu Chen,
in der ersten Methode durchlaufen alle Events von Deinem Dialog die Methode PreTranslateMessage. Würde ich deshalb auch nur hernehmen für Events, die alle Steuerelemente betreffen. Gezielt auf ein Steuerelement ist die zweite Steuermethode.
Gruß
Chris