PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : API Programmierung - Button abfragen


Kennung Eins
2004-04-22, 19:12:43
Ich hab ein Fenster mittels CreateWindowEx erzeugt, auf dem liegen Buttons.
CreateWindow('BUTTON', buttonName, WS_CHILD or WS_VISIBLE or BS_AUTOCHECKBOX or SS_SUNKEN,x_start, y_start, x_end, y_end, hwnd, HMENU(COMMAND_ID),hInstance, nil);
Ich möchte gerne irgendwie Abfragen, ob ein User den Button "angeklickt" hat, also den Mousebutton zwar gedrückt, aber noch nicht losgelassen hat.

Da gibts so tolle Sachen wie BN_PUSHED / BST_PUSHED - aber ich komm da einfach nicht ran, ich krieg immer nur BN_CLICKED zurück.
Liegt das daran, daß ich meine Abfragen alle im WM_COMMAND mache? Welche Message müsste ich abfragen, damit ich auch BN_PUSHED zurückbekomme?

Mit WM_LBUTTONDOWN klappt das nicht.
Ich bin dankbar für jede Hilfe!

Matrix316
2004-04-22, 21:21:22
Und was bringt es wenn du weißt, dass er die Maustaste noch nicht losgelassen hat?

Gefunden habe ich das hier:


CButton


The CButton class provides the functionality of Windows button controls. A button control is a small, rectangular child window that can be clicked on and off. Buttons can be used alone or in groups and can either be labeled or appear without text. A button typically changes appearance when the user clicks it.

Typical buttons are the check box, radio button, and pushbutton. A CButton object can become any of these, according to the button style specified at its initialization by the Create member function.

In addition, the CBitmapButton class derived from CButton supports creation of button controls labeled with bitmap images instead of text. A CBitmapButton can have separate bitmaps for a button's up, down, focused, and disabled states.

You can create a button control either from a dialog template or directly in your code. In both cases, first call the constructor CButton to construct the CButton object; then call the Create member function to create the Windows button control and attach it to the CButton object.

Construction can be a one-step process in a class derived from CButton. Write a constructor for the derived class and call Create from within the constructor.

If you want to handle Windows notification messages sent by a button control to its parent (usually a class derived from CDialog), add a message-map entry and message-handler member function to the parent class for each message.

Each message-map entry takes the following form:

ON_Notification( id, memberFxn )

where id specifies the child window ID of the control sending the notification and memberFxn is the name of the parent member function you have written to handle the notification.

The parent’s function prototype is as follows:

afx_msg void memberFxn( );

Potential message-map entries are as follows:

Map entry Sent to parent when...
ON_BN_CLICKED The user clicks a button.
ON_BN_DOUBLECLICKED The user double-clicks a button.


If you create a CButton object from a dialog resource, the CButton object is automatically destroyed when the user closes the dialog box.

If you create a CButton object within a window, you may need to destroy it. If you create the CButton object on the heap by using the new function, you must call delete on the object to destroy it when the user closes the Windows button control. If you create the CButton object on the stack, or it is embedded in the parent dialog object, it is destroyed automatically.

#include <afxwin.h>


Vielleicht hilft es ja obwohl da auch nur klick und doppelklick steht.

EDIT: Kannst ja bei WM_LBUTTONUP auch eine Variable setzen, und wenn die nicht true ist oder einen bestimmten Wert hat im Vergleich zu einer anderen Variable bei WMLBUTTENDOWN weißt du ja dass die Maustaste noch nicht wieder losgelassen wurde. ;)

Kennung Eins
2004-04-23, 10:30:52
Original geschrieben von Matrix316
Und was bringt es wenn du weißt, dass er die Maustaste noch nicht losgelassen hat?

Gefunden habe ich das hier:



Vielleicht hilft es ja obwohl da auch nur klick und doppelklick steht.

EDIT: Kannst ja bei WM_LBUTTONUP auch eine Variable setzen, und wenn die nicht true ist oder einen bestimmten Wert hat im Vergleich zu einer anderen Variable bei WMLBUTTENDOWN weißt du ja dass die Maustaste noch nicht wieder losgelassen wurde. ;) Bringen tut mir das folgendes: Ich bastel an einem Button, der ein Bitmap steuert. Dieses Bitmap soll sich aber nicht erst ändern, wenn der User geklickt hat, sondern während er noch klickt.

Leider kann ich CButton nicht benutzen, da ich unter Delphi arbeite und ohne VCL.

Danke trotzdem! :)

Das mit WM_LBUTTONUP hab ich mir auch schon gedacht. Leider reagiert WM_LBUTTONUP nicht, wenn ich auf den Button klicke, sondern nur, wenn ich in das Hauptfenster klicke.
Aber vielleicht kriegt man das ja noch hin irgendwie?

Xmas
2004-04-23, 11:53:51
Tja, Button ist ganz schön dumm...

The BN_PUSHED notification code is sent when the push state of a button is set to pushed.

Note This notification message is provided only for compatibility with 16-bit versions of Windows earlier than version 3.0. Applications should use the BS_OWNERDRAW button style and the DRAWITEMSTRUCT structure for this task.

The parent window of the button receives the BN_PUSHED notification code through the WM_COMMAND message.

Probier mal den Button-Style BS_NOTIFY, obwohl ich nicht glaube dass es was bringt.

Ansonsten: Subclassing. Mit GetClassInfo die WNDCLASS struct von Button auslesen, WinProc kapseln, neue Funktionalität einbauen, neue WNDCLASS registrieren.

Kennung Eins
2004-04-23, 17:32:48
Hmpf alles zu kompliziert irgendwie.
Ich mal jetzt einfach ein Button-Bild auf ein Label und mache dann per WM_LBUTTONDOWN meine Abfrage. Das funzt erstmal ausreichend.

Danke trotzdem!

Metal Maniac
2004-04-25, 18:44:30
In diesem Thread hatte jemand ein ähnliches Problem:
http://www.forum-3dcenter.org/vbulletin/showthread.php?s=&threadid=118711

Insbesondere könnte Dir folgender Link helfen:
http://www.openroad.org/school/faq/mfc.html#SetCursor