Sourceverwaltung und PowerBuilder by jizhen1947

VIEWS: 21 PAGES: 29

									Window Message und
   PowerBuilder
      Ludwin Feiten
      Power People




                      Ludwin Feiten
                                      • Motivation
                                      • Send Function
                                      • Beispiel
                                      • Suchen in der Win-API Help
                                      • Beispiel für PB Custom
                                        Events
                                      • …

        Fahrplan
       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 2/29
    Motivation
                                   • PowerBuilder hat die
                                     Send()-Funktion
                                   • Die Informationen
                                     darüber sind verstreut
                                     und mühsam zu finden.



       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 3/29
  Window Events
                        • PowerBuilder ist eine Windows Anwendung
                        • Windows hat ein Event gesteuertes User
                          Interface, das von PowerBuilder genutzt
                          werden kann.
                        • Triggern von Events durch senden von
                          Messages an Controls.


                        • SendMessage(HWND hWnd, UINT Msg,
                          WPARAM wParam, LPARAM lParam );

       PBUGG               Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                      Folie 4/29
   SendMessage Function

             In Windows sind nicht nur Windows
               “windows” sondern auch fast alle
               anderen visuellen Control wie
               Buttons, Scrollbars, Editfields, etc.

             Zur Identifizierung gibt es einen
              handle
       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 5/29
   Send Function in PowerBuilder
             • Send ( handle, message#, lowword, long )
                  – handle: A long whose value is the system handle of a
                    window (that you have created in PowerBuilder or
                    another application) to which you want to send a
                    message.
                  – message#: An UnsignedInteger whose value is the
                    system message number of the message you want to
                    send.
                  – Lowword: A long whose value is the integer value of
                    the message. If this argument is not used by the
                    message, enter 0.
                  – Long: The long value of the message or a string.

       PBUGG            Window Messages und PowerBuilder            Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 6/29
   Send Function: Beispiele
             • Dieses Statement scrollt das Fenster
               w_emp eine Seite hoch:
                  – Send(Handle(w_emp), 277, 2, 0)
             • Das folgende Statements click den
               CommandButton cb_OK:
                  – Send(Handle(Parent), 273, 0,
                    Handle(cb_OK))
       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 7/29
   Messages: Wie kann man sie finden?

             • windows API help
                  – http://msdn.microsoft. com/library/
             • winuser.h
                  – C:\Program
                    Files\Sybase\Shared\PowerBuilder\c
                    gen\h\nt\winuser.h


       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 8/29
   Bspl.: Tab out a field

             Suchen in der Windows API Hilfe mit
                  – „Key pressed notification“
             Führt zu:
                  – „WM_KEYDONW




       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 9/29
   Syntax WM_KEYDOWN
    •   WM_KEYDOWN
    •       WPARAM wParam
            LPARAM lParam
                                                                        •   29: Specifies the context code. The value is always 0
                                                                            for a WM_KEYDOWN message
    •   wParam: Specifies the virtual-key code of the
        nonsystem key.                                                  •   30: Specifies the previous key state. The value is 1 if
                                                                            the key is down before the message is sent, or it is zero
    •   lParam: Specifies the repeat count, scan code,                      if the key is up
        extended-key flag, context code, previous key-state
        flag, and transition-state flag, as shown in the following      •   31: Specifies the transition state. The value is always
        table.                                                              zero for a WM_KEYDOWN message
                                                                        •   Return Value: An application should return zero if it
                                                                            processes this message.
    •   0-15: Specifies the repeat count for the current
        message. The value is the number of times the                   •   24: Specifies whether the key is an extended key, such
        keystroke is autorepeated as a result of the user                   as the right-hand ALT and CTRL keys that appear on an
        holding down the key. If the keystroke is held long                 enhanced 101- or 102-key keyboard. The value is 1 if it
        enough, multiple messages are sent. However, the                    is an extended key; otherwise, it is 0,
        repeat count is not cumulative.                                 •   25-28: Reserved; do not use
    •   16-23: Specifies the scan code. The value depends on            •   29: Specifies the context code. The value is always 0
        the OEM                                                             for a WM_KEYDOWN message
    •   24: Specifies whether the key is an extended key, such          •   30: Specifies the previous key state. The value is 1 if
        as the right-hand ALT and CTRL keys that appear on an               the key is down before the message is sent, or it is zero
        enhanced 101- or 102-key keyboard. The value is 1 if it             if the key is up
        is an extended key; otherwise, it is 0,                         •   31: Specifies the transition state. The value is always
    •   25-28: Reserved; do not use                                         zero for a WM_KEYDOWN message
                                                                        •   Return Value: An application should return zero if it
                                                                            processes this message.




       PBUGG                           Window Messages und PowerBuilder                                                   Ludwin Feiten
Düsseldorf 26.05.2006
                                                          Folie 10/29
   Nächster Schritt
             • winuser.h
                  – #define WM_KEYDOWN                     0x0100
             • hex 0x0100 ist dec 256.
               (Windows Rechner in Wissenschaftlicher Ansicht)

             • wParam muss der ASCII-Code for the Tab-Key sein:
                   Das ist 9.

             • lParam ist Null.

             • Der Aufruf ist: send(Handle(this), 256,9, long(0,0))


       PBUGG            Window Messages und PowerBuilder              Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 11/29
   Besp. Scroll a window
             Win32 and COM Development > User Interface > Windows
               Shell > Windows Controls > Individual Control
                 Information > Scroll Bars




       PBUGG             Window Messages und PowerBuilder           Ludwin Feiten
Düsseldorf 26.05.2006
                                    Folie 12/29
   Syntax WM_VSCROLL
    • WM_VSCROLL                                                          •   SB_THUMBPOSITION: The user has
                                                                              dragged the scroll box (thumb) and released
         – WPARAM wParam                                                      the mouse button. The high-order word
                                                                              indicates the position of the scroll box at
                                                                              the end of the drag operation.
         – LPARAM lParam;                                                 •   SB_THUMBTRACK: The user is dragging
                                                                              the scroll box. This message is sent
    •   wParam:                                                               repeatedly until the user releases the
                                                                              mouse button. The high-order word
         –   The high-order word specifies the                                indicates the position that the scroll box
                                                                              has been dragged to.
             current position of the scroll box if                        •   SB_TOP: Scrolls to the upper left.
             the low-order word is
             SB_THUMBPOSITION or                               •   lParam:
             SB_THUMBTRACK; otherwise, this                         –   If the message is sent by a scroll bar,
             word is not used.                                          this parameter is the handle to the scroll
                                                                        bar control. If the message is not sent
                                                                        by a scroll bar, this parameter is NULL.
         –   The low-order word specifies a scroll
             bar value that indicates the user's
             scrolling request. This parameter can
             be one of the following values.
               •   SB_BOTTOM: Scrolls to the lower right.
               •   SB_ENDSCROLL: Ends scroll.
               •   SB_LINEDOWN: Scrolls one line down.
               •   SB_LINEUP: Scrolls one line up.
               •   SB_PAGEDOWN: Scrolls one page down.
               •   SB_PAGEUP: Scrolls one page up.



       PBUGG                        Window Messages und PowerBuilder                                           Ludwin Feiten
Düsseldorf 26.05.2006
                                                     Folie 13/29
   Nächster Schritt:
             • winuser.h
                  – #define WM_VSCROLL 0x0115

             • hex 0x0115 ist dec 277.


             • SB_PAGEDOWN ist 3

             • lParam ist Null.

             • Der Aufruf ist: send(Handle(this), 277,3, long(0,0))


       PBUGG            Window Messages und PowerBuilder          Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 14/29
   Strategien zur Suche
             Suche in: MSDN Home > MSDN Library > Win32
               and COM Development > User
               Interface > Windows Shell > Windows Controls
             Subtopics:
             • “General Control Information”
             • “Individual Control Information”
             Suche unter:
             • "Messages" and "Notifications"


       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 15/29
   Strategien zur Suche

             Suche in winusers.h
             nach brauchbaren Schlagwörtern.

             Mappen von PB-Events auf WN-
              Events
                  Suche in spezieller Liste:
                   -> www.powerpeople.de
       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 16/29
   PowerBuilder custom events
             • pbm_custom01 event ID maps to wm_user+0
             • pbm_custom02 event ID maps to wm_user+1,
             • …
             • pbm_custom75 event ID to wm_user+74.

             • WM_USER is defined in winusers.h:

             • #define WM_USER 0x0400                      = 1024




       PBUGG            Window Messages und PowerBuilder            Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 17/29
   Application Ping-Pong




       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 18/29
   Ping - Pong

       • Suche der Instanzen des Programms
         (Find Instances)
       • Schicken eines Pings (Send Ping)
       • Empfangen des Ping (ue_ping)-> Pong
       • Empfangen des Pong (ue_pong)


       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 19/29
   Find Instances
    •   // Original autor: Karl E. Peterson
                                                                            •
                                                                            •
                                                                            •
                                                                                     If nRet > 0 Then
                                                                                       //
                                                                                       // Clean up return string, preparing for
                                                                            •          // case-insensitive comparison.
    •   // Aus VB "geklaut"                                                 •          //
                                                                            •          TitleTmp = upper(Left(TitleTmp, nRet))
    •   ulong       hWndTmp,&                                               •          //
    •                                                                       •          // Use appropriate method to determine if
                   FindWindowPartial                                        •          // current window//s caption either starts
    •   string     lpClassName,&                                            •          // with or contains passed string.
    •              lpWindowName,&                                           •          //
    •              TitleTmp,&                                               •          CHOOSE Case Method
    •              TitleStart                                               •            Case FWP_STARTSWITH
    •   integer    nRet                                                     •              If pos(TitleTmp, upper(TitleStart)) = 1 Then
    •   integer method                                                      •                FindWindowPartial = hWndTmp
                                                                            •
    •   constant integer FWP_STARTSWITH = 1
    •   constant integer FWP_CONTAINS = 0                                                    mle_windows.text += TitleTmp + ' HWND: ' +
                                                                                string(FindWindowPartial) + '~r~n'
    •   constant integer GW_HWNDNEXT = 2                                    •                 //Exit
                                                                            •               End If
    •   TitleStart = parent.title// "Application Ping Pong"                 •             Case FWP_CONTAINS
    •   mle_windows.text = ""                                               •               If pos(TitleTmp, upper(TitleStart)) > 0 Then
    •   setnull(lpClassName)                                                •                 FindWindowPartial = hWndTmp
    •   setnull(lpWindowName)                                               •
                                                                                            mle_windows.text += TitleTmp + ' HWND: ' +
    •    hWndTmp = FindWindow(lpClassName, lpWindowName)                        string(FindWindowPartial) + '~r~n'
    •    Do Until hWndTmp = 0                                               •                // Exit
    •     //                                                                •              End If
    •     // Make sure this window has no parent.                           •           End CHOOSE
    •     //                                                                •         End If
    •     If GetParent(hWndTmp) = 0 Then                                    •       End If
    •       //                                                              •       //
    •       // Retrieve caption text from current window.                   •       // Get next window in master window list and continue.
    •       //                                                              •       //
    •       TitleTmp = Space(256)                                           •       hWndTmp = GetWindow(hWndTmp, GW_HWNDNEXT)
    •       nRet = GetWindowText(hWndTmp, TitleTmp, Len(TitleTmp))          •     Loop
                                                                            •



       PBUGG                                  Window Messages und PowerBuilder                                                        Ludwin Feiten
Düsseldorf 26.05.2006
                                                              Folie 20/29
   Send ping
             unsignedlong   hndl_me,&
                            hndl_you
             hndl_me = handle(parent)
             hndl_you = long(em_win_handle.text)
             IF hndl_you > 0 THEN
                  // Send a ping to pbm_custom01 and transmit my handle and
                     instance number in the params
                  send (hndl_du, 1024, hndl_ich, il_nummer ) ;
             ELSE
                  MessageBox("Oups", em_window.text + " is not running!")
             END IF



       PBUGG             Window Messages und PowerBuilder                   Ludwin Feiten
Düsseldorf 26.05.2006
                                    Folie 21/29
   ue_ping
             event ue_ping pbm_custom01
                  Messagebox("Here is window:
                    "+string(handle(this))," Got a Ping from: " +
                    string (wparam) + " with Instance No.
                    "+string(lparam) )
                  // Pong to sender of the Ping (Event Id:1025)
                  send (wparam, 1025, handle(this), il_number ) ;
             end event

       PBUGG            Window Messages und PowerBuilder     Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 22/29
   ue_pong
             event ue_ping pbm_custom02
                  Messagebox("Here is window:
                   "+string(handle(this))," Got the Pong from: "
                   + string (wparam) + " with Instance No.
                   "+string(lparam) )
             end event




       PBUGG            Window Messages und PowerBuilder    Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 23/29
   Starting Syscommands
             Start Screensaver
             To start the screen saver write:
             /*
             ** WM_SYSCOMMAND 0x0112 274
             ** SC_SCREENSAVE 0xF140 61760
             */
             send(handle(This),274,61760,0)




       PBUGG            Window Messages und PowerBuilder   Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 24/29
   Starting Syscommands
             Maximize a frame
             To maximize a window when it opens put the following code into
                the Open event.
             CONSTANT Integer WM_SYSCOMMAND = 274
             CONSTANT UInt SC_MAXIMIZE = 61488
             //
             Send(Handle(This), WM_SYSCOMMAND, SC_MAXIMIZE, 0)




       PBUGG            Window Messages und PowerBuilder             Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 25/29
   Starting Syscommands
       CONSTANT Integer WM_SYSCOMMAND = 274

       CONSTANT UInt SC_MAXIMIZE = 61488
       CONSTANT UInt SC_CLOSE   = 61536    // 0xF060
       CONSTANT UInt SC_SCREENSAVE = 61760 // 0xF140
       CONSTANT UInt SC_RESTORE = 61728 // 0xF120

       CONSTANT UInt             SC_MINIMIZE = 61472 // 0xF020

       Send(Handle(w_test), WM_SYSCOMMAND, SC_MINIMIZE, long(0,0) )

        …………
       send(Handle(Parent),16,0,0) //Close


       PBUGG            Window Messages und PowerBuilder         Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 26/29
   Ein Window ohne Titlebar verschieben

             Um ein Window ohne Titlebar zu
              verschieben muss der folgende Code in
              das mousedown event.

                  CONSTANT uint WM_NCLBUTTONDOWN = 161
                  CONSTANT uint HTCAPTION = 2
                  Post( Handle( this ), WM_NCLBUTTONDOWN,
                    HTCAPTION, Long( xpos, ypos ) )



       PBUGG            Window Messages und PowerBuilder    Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 27/29
   Einige Events …
                      message              lowword                          long




           Keyboard   WM_KEYDOWN = 256     ASCII Value of the nonsystem     0
                      WM_KEYUP = 257               Key
                                                   Backspace            8
                                           Tab     9
                                           carriage return            13

           Mouse      WM_LBUTTONDBLCLK=    MK_LBUTTON          0x0001           The low-order word specifies
                                           MK_RBUTTON          0x0002                the x-coordinate of the
                           515
                                           MK_SHIFT            0x0004                cursor.
                                           MK_CONTROL          0x0008           The high-order word specifies
                                           MK_MBUTTON          0x0010                the y-coordinate of the
                                                                                     cursor.
                                                                                The coordinate is relative to the
                                                                                     upper-left corner of the
                                                                                     client area.

           Slider     WM_HSCROLL = 276     SB_LINEUP       0                0
                      WM_VSCROLL = 277     SB_LINELEFT       0
                                           SB_LINEDOWN         1
                                           SB_LINERIGHT       1
                                           SB_PAGEUP        2
                                           SB_PAGELEFT        2
                                           SB_PAGEDOWN          3
                                           SB_PAGERIGHT        3
                                           SB_THUMBPOSITION 4
                                           SB_THUMBTRACK          5
                                           SB_TOP       6
                                           SB_LEFT       6
                                           SB_BOTTOM         7
                                           SB_RIGHT       7
                                           SB_ENDSCROLL         8


       PBUGG                         Window Messages und PowerBuilder                                               Ludwin Feiten
Düsseldorf 26.05.2006
                                                     Folie 28/29
                                     Sind noch Fragen offen?

                                     Bei Rückfragen oder Anregungen bitte an:

                                                 Ludwin Feiten

                                                 Power People
                                                 Inh. Ludwin Feiten
                                                 Am Borsigturm 50

                                                 D-13507 Berlin

                                                 fon +49 (0)30 43032350
                                                 fax +49 (0)30 43032355
           Kontakt                               http://www.powerpeople.de
                                                 mailto:ludwin.feiten@powerpeople.de

       PBUGG            Window Messages und PowerBuilder                        Ludwin Feiten
Düsseldorf 26.05.2006
                                   Folie 29/29

								
To top