Behandeln WM_CHAR, WM_KEYDOWN auch das drücken der Enter Taste?
-
Hallo
Ich habe folgendes Problem, ich will das das Programm eine bestimmte Aktion ausführt wenn in einem edit Feld Enter gedrückt wird. Ich habe ein bisschen gesucht und bin auf den Eintrag in der FAQ aufmerksam geworden ("Abfangen von Nachrichten an Childwindows"). Nun das Funktioniert ganz gut solange ich zeichen angebe, allerdings funktioniert es nicht bei der Enter Taste.
-
mein vorschlag:
subclassing --> enter abfangen
http://www.winapi.net/index.php?inhalt=s27
-
les dir bitte meine frage durch, es funktioniert bei normalen Tasten (a,b,c,d ...), allerdings nicht mit Enter.
edit: Ich habe das fast genauso wie auf der WinApi Seite
-
Du kannst auch nen Button mit der ID IDOK anlegen. Der wird auf Dialogen (bzw. bei Fenstern für die du IsDialogMessage aufrufst) automatisch aufgerufen.
Dann könnte man seine Eingabe wahlweise mit Enter oder mit Druck auf den Button bestätigen.
-
flammenvogel schrieb:
les dir bitte meine frage durch, es funktioniert bei normalen Tasten (a,b,c,d ...), allerdings nicht mit Enter.
tut mir vielmals leid das ich die faq nicht ganz auswendig keine.
aber es geht so

mit geht nicht kann hier niemand was anfangen

-
-
Ich habe das wie gesagt mit dem Subclassing so gemacht wie beschrieben. Mal mit der ausnahme das ich SetWindowLong anstatt SetWindowLongPtr benutzte. Zur Zeit wird noch nicht unterschieden welche Taste gedrückt wurde und einfach bei jedem Tastendruck im Editfeld eine MessageBox geöffnet. Das funktioniert wie gesagt bei zeichen wie a,s,d, ... aber eben nicht mit Zeichen die nicht im Edit Feld erscheinen unter anderem Enter.
edit: Ich poste jetzt trozdem mal den Code
//Aus WM_CREATE: CreateWindowEx(WS_EX_CLIENTEDGE,"edit", "", WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL , 140,130,160,20, hwnd, (HMENU) EDIT_DEUTSCH, hinstance, NULL); oldeditproc= (WNDPROC)SetWindowLongPtr (GetDlgItem(hwnd, EDIT_DEUTSCH), GWL_WNDPROC, (long) WndEditProc); //Aus WndEditProc: LRESULT CALLBACK WndEditProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_COMMAND: case WM_CHAR: MessageBox(0,"Test",0,0); if(wParam == VK_RETURN) { MessageBox(0,"Test",0,0); SendMessage((HWND) GetWindowLong(hwnd, GWL_HWNDPARENT), WM_COMMAND, MAKEWPARAM(BU_WEITER, 0),0); } //Kein break !!! default: return CallWindowProc((WNDPROC)oldeditproc, hwnd, message, wParam, lParam); } }Achja, oldeditproc ist eine globale Variabel vom Typ WNDPROC.
-
ich sehr grad keinen fehler bzw ich übersehe ihn.
deine code funktioniert bei mir einwandfrei
-
ohh bravo...
Dann suche ich mal wieder nach irgendeinem Fehler, der eigentlicht nicht möglich ist ... ich hasse das
-
Ich sehe gerade das ich noch if(!IsDialogMessage) in der Endlosschleife/Haupschleife drin habe da ich Tabstops benutze kann das damit was zu tun haben???
-
Benutze dafür lieber WM_KEYDOWN, WM_CHAR wird gesendet wenn WM_KEYDOWN durch TranslateMessage() übersetzt wurde, in wParam sitzt dann das "Zeichen", lParam enthält weitere Informationen (Key Data);
Probieren könntest du vieleicht:
TCHAR code = (TCHAR)wParam; switch (code) { case "\n": MessageBox(NULL,"Ist Enter","Info",MB_OK); break; //...etc. }Ist eine ungetestete Idee, ich selbst benutze nie WM_CHAR, nur WM_KEYDOWN.
-
Was ne blöde Idee von mir, benutze WM_KEYDOWN.
Lese selbst:
PSDK schrieb:
The WM_CHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. WM_CHAR contains the character code of the key that was pressed.
WM_CHAR
chCharCode = (TCHAR) wParam; // character code
lKeyData = lParam; // key dataParameters
chCharCode
Value of wParam. Specifies the character code of the key.
lKeyData
Value of lParam. Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table:
Value Description
0-15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user holding down the key.
16-23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28 Reserved; do not use.
29 Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31 Specifies the transition state. The value is 1 if the key is being released, or it is 0 if the key is being pressed.Return Values
An application should return zero if it processes this message.
Remarks
Because there is not necessarily a one-to-one correspondence between keys pressed and character messages generated, the information in the high-order word of the lKeyData parameter is generally not useful to applications. The information in the high-order word applies only to the most recent WM_KEYDOWN message that precedes the posting of the WM_CHAR message.
For enhanced 101- and 102-key keyboards, extended keys are the right ALT and the right CTRL keys on the main section of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN and arrow keys in the clusters to the left of the numeric keypad; and the divide (/) and ENTER keys in the numeric keypad. Some other keyboards may support the extended-key bit in the lKeyData parameter.
-
Hast du dir den Link angesehen?
-
WM_KEYDOWN und WM_CHAR funktionieren nicht und ich bin ziemlich sicher das das was mit dem IsDialogMessage für Tabstops zu tun hat.
@link was soll man sich da groß ansehen, du hast doch meinen Code gesehen oder? ich sehe zu dem auf www.winapi.net kaum einen unterschied (codemäßig).
Ich habe jetzt mal if(!IsDialogMessage) weggelassen und es funzt, das Problem ist wie kriege ich das hin das Tabstops und das Subclassing funktionieren
-
Srry link habe deinen link zu spät gesehen, mit dem Code funktioniert es zwar auch mit IsDialogMessage allerdings geht jetzt Tabstop net mehr

-
oh das stimmt. dann muss man den code in WM_GETDLGCODE ein bisschen verfeinern.

-
ähm link ich halte die deutsche übersetzung nicht wirklich für gelungen ... ich verstehe nämlich so gut wie gar nichts ... kannst du mir mal in richtigem Deutsch sagen was ich jetzt noch ändern muss?
-
ne, da geb ich dir doch lieber den link zum englischen text.
-
also ich verstehe das immer noch nicht richtig. Ich bräuchte jetzt wirklich mal ein Beispiel wie ich das genau machen soll. Ich wann muss ich was/wo/wieoft zurückgeben?

-
Peek at the lParam. If it is a press of the Return key, then return DLGC_WANTMESSAGE so the message will not be handled by the dialog manager.