Benutzerdefiniertes Event feuern?

Für allgemeine Fragen zur Programmierung mit PureBasic.
Benutzeravatar
Kiffi
Beiträge: 10621
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Benutzerdefiniertes Event feuern?

Beitrag von Kiffi »

Hallo Leute,

ist es möglich, ein benutzerdefiniertes Ereignis in einer Prozedur zu feuern,
welches dann in der MainLoop-Schleife zu einer Aktion führt?

Code: Alles auswählen

; Pseudocode!
Procedure MachWas()
  Repeat
    If MeineBedingung
      ; Event feuern
      RaiseEvent(#my_Event)
    EndIf
  ForEver
EndProcedure

Repeat
  Select WaitWindowEvent()
    Case #PB_EventCloseWindow
      Break
    Case #my_Event
      MachWasAnderes()
  EndSelect
ForEver
In VB ist sowas mittels RaiseEvent() möglich.

Danke im voraus & Grüße ... Kiffi
Benutzeravatar
Franky
Beiträge: 1132
Registriert: 29.08.2004 16:31
Wohnort: Münsterland
Kontaktdaten:

Beitrag von Franky »

Sendmessage müsste doch gehen, oder?
Falsch zugeordnetes Zitat des Tages: "O'zapft is" - Edward Snowden :)
GPI
Beiträge: 1511
Registriert: 29.08.2004 13:18
Kontaktdaten:

Beitrag von GPI »

Wenns WindowEvent() kriegen soll: PostMessage(), wenns in Callback sein soll: SendMessage()

Für Messages: #WM_App bis #WM_App+100
CodeArchiv Rebirth: Deutsches Forum Github Hilfe ist immer gern gesehen!
Benutzeravatar
Kiffi
Beiträge: 10621
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Beitrag von Kiffi »

Hallo Franky und GPI,

vielen Dank für Eure Antworten. Nachfolgend habe ich mal einen kleinen
Code zusammengebastelt, der mein RaiseEvent() demonstriert.

Funktionieren tut's, aber ist das auch sauber?

Code: Alles auswählen

Enumeration
  #frmMain
EndEnumeration

Enumeration
  #cmdLos
  #lstOutput
EndEnumeration

#WM_App = $8000

Procedure myEvent()
  PostMessage_(WindowID(#frmMain), #WM_App,0,0)
  PostMessage_(WindowID(#frmMain), #WM_App + 1,0,0)
EndProcedure

If OpenWindow(#frmMain, 0, 0, 300, 150, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "RaiseEvent-Test")
  If CreateGadgetList(WindowID(#frmMain))
    ListViewGadget(#lstOutput,10,10,280,100)
    ButtonGadget(#cmdLos,10,120,90,20,"Los!")
    Repeat
      Select WindowEvent()
        Case #PB_EventCloseWindow
          Break
        Case #PB_EventGadget
          Select EventGadgetID()
            Case #cmdLos
              myEvent()
          EndSelect
        Case #WM_App
          AddGadgetItem(#lstOutput,-1,"#WM_App erhalten")
        Case #WM_App + 1
          AddGadgetItem(#lstOutput,-1,"#WM_App+1 erhalten")
      EndSelect
      Delay(1)
    ForEver
  EndIf
  CloseWindow(#frmMain)
EndIf

End
GPI hat geschrieben: Für Messages: #WM_App bis #WM_App+100
das bedeutet im Klartext, daß mir 101 benutzerdefinierte Messages zur
Verfügung stehen?

Nochmals Danke & Grüße ... Kiffi
GPI
Beiträge: 1511
Registriert: 29.08.2004 13:18
Kontaktdaten:

Beitrag von GPI »

msdn sagt dazu:
WM_APP
The WM_APP constant is used by applications to help define private messages, usually of the form WM_APP+X, where X is an integer value.

#define WM_APP 0x8000

Remarks
The WM_APP constant is used to distinguish between message values that are reserved for use by the system and values that can be used by an application to send messages within a private window class. There are five ranges of message numbers:

Range Meaning
0 through WM_USER – 1 Messages reserved for use by the system.
WM_USER through 0x7FFF Integer messages for use by private window classes.
WM_APP through 0xBFFF Messages available for use by applications.
0xC000 through 0xFFFF String messages for use by applications.
Greater than 0xFFFF Reserved by the system for future use.


Message numbers in the first range (0 through WM_USER – 1) are defined by the system. Values in this range that are not explicitly defined are reserved for future use by the system.

Message numbers in the second range (WM_USER through 0x7FFF) can be defined and used by an application to send messages within a private window class. These values cannot be used to define messages that are meaningful throughout an application, because some predefined window classes already define values in this range. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use these values. Messages in this range should not be sent to other applications unless the applications have been designed to exchange messages and to attach the same meaning to the message numbers.

Message numbers in the third range (0x8000 through 0xBFFF) are available for application to use as private messages. Message in this range do not conflict with system messages.

Message numbers in the fourth range (0xC000 through 0xFFFF) are defined at run time when an application calls the RegisterWindowMessage function to retrieve a message number for a string. All applications that register the same string can use the associated message number for exchanging messages. The actual message number, however, is not a constant and cannot be assumed to be the same between different sessions.

Message numbers in the fifth range (greater than 0xFFFF) are reserved for future use by the system.

QuickInfo
Windows NT: Requires version 3.51 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 2.0 or later.
Header: Declared in winuser.h.

See Also
Messages and Message Queues Overview, Message and Message Queue Messages, RegisterWindowMessage, WM_USER
CodeArchiv Rebirth: Deutsches Forum Github Hilfe ist immer gern gesehen!
Antworten