Announcement

Collapse
No announcement yet.

Pressing button or key

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Adam, Thank you very much for the code. If you use #include "win32api.inc", you don't need #include "ddt.inc". What about push buttons? Jeffrey.

    ------------------

    Comment


    • #22
      If you edit the line:

      hBrush = CreateSolidBrush(GetSysColor(%COLOR_BTNTEXT))

      to become:

      hBrush = CreateSolidBrush(GetSysColor(%COLOR_BTNTEXT + 1))

      ...then the labels will take up the color of buttons. The +1 is required as a result of a decision MS made back in the Windows 3.0 days and carried forward to continue compatibility! (duh!)

      However, this little 'demo' only works until you add a button to the dialog - if this button receives focus all keyboard messages are routed to the button's window procedure which means you need to subclass this also. With the addition of a single button, the button will never lose focus and your interface design (as the "demo" code stands) will cease working.

      Bypassing the standard windows keyboard interface behavior creates all sorts of problems that have to be handled by your own code. If you stick with the standard interface behavior then you do not need to spend hours trying to fluff about to get the design exactly as you require.




      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #23
        Well, having a big heart - I think sometimes my desire to help someone overrides using common sense. Of course, Lance is right about adding a button to it. At least it gives you some examples of changing colors on ddt labels and dialogs, if nothing else. Actually Lance, it might be better if you deleted that last post. I think I will gracefully bow out of this thread since I think I will let discretion be the better part of valor and let the guys who really know what they are talking about "do the talking".

        My apologies,
        Adam

        ------------------

        Comment


        • #24
          Adam, didn’t you just finish telling Jeffery not to give up??? The real “know it all” guys can’t reply to every message on the forum! Note that Lance didn’t get into the discussion until post-number 11. If you say something wrong some one will be bound to fix it (“programmer-ic” nature) and at that point both you and the person you where trying to help has learned something. I for one can’t count the number of times I’ve said something stupid around here, but I have learned a lot more than I would have otherwise with many thanks to those who have corrected me.

          Of course I might be wrong about all this as well, in which case I’ll probably lose my posting privileges any moment now I’ll let you know if that happens.

          Colin Schmidt

          ------------------
          Colin Schmidt & James Duffy, Praxis Enterprises, Canada

          Comment


          • #25
            Lance, I won't add push buttons and radio buttons to my program because the code that processes keystrokes won't work with controls created using DDT. I will have to write the program using WIN32API calls. I wish that I would put the keyboard, mouse, and monitor next to control panel for my model train layout but I have to build shelves for the monitor, keyboard, and mouse and I need extension cables for monitor, keyboard, and mouse. Right now, my computer desk is about six feet from the control panel for my model train layout. Because of the furniture in my bedroom, the tracks are about six feet off the floor and I need a drafting chair with its seat raised all the way up to sit at the control panel. I may buy a remote control that controls the transformer using a receiver. Jeffrey.

            ------------------

            Comment


            • #26
              Adam, Please see my reply to Lance about my model train layout. Jeffrey.

              ------------------

              Comment


              • #27
                Colin, I don't think that you will lose your posting privileges unless you say bad words to someone. I got confused over the differences between PB/DLL and Visual BASIC. I didn't know that if PB/DLL program has DDT controls, it can't process keystrokes unless you subclass the controls. Jeffrey.

                ------------------

                Comment


                • #28
                  I didn't know that if PB/DLL program has DDT controls, it can't process keystrokes unless you subclass the controls.
                  Jeffrey --
                  about what you ?
                  There are at least three ways :
                  1) my "experimental" variant (during two monthes nobody said that there are problems with it)
                  2) Lance's variant of subclassing (see Source code forum) -
                  through initial callback function
                  3) SetWindowHook

                  ------------------

                  Comment


                  • #29
                    Semen, How can I use SetWindowHook function? Jeffrey.

                    ------------------

                    Comment


                    • #30
                      I may be a day late and a dollar short here However, I just wanted to put my piece in:

                      On my Options dialog box, if a user presses OK I want the same function to happen as if he pressed "Apply", and I got lazy so I said, hmmmmmmmm rather than write a new function just send a BN_CLICK message:


                      Code:
                              Case %IDOK, 130 'OK
                      
                                  'Resume normal procedure after install is complete:
                                  If g_lInstallingFlag = 1 Then
                                      g_lInstallingFlag = 0
                                      SaveSetting %HK,g_sInstKey,"ApplicationName",g_sWinLogEXE
                                      SaveSetting %HK,g_sInstKey,"DisplayName",g_szMINE
                                      SaveSetting %HK,g_sInstKey,"UninstallString",g_sWinLogFilePath & "wUnwise.exe"
                                      SaveSetting %HK,g_sMainKey, g_sInstallDir,g_sWinLogFilePath
                                  End If
                      
                                  'Click the Apply button
                                  If IsWindowEnabled(GetDlgItem(CbHndl,132)) Then SendMessage GetDlgItem(CbHndl,132) , %BM_CLICK, 0, 0
                                  Dialog End CbHndl, 1
                                  Exit Function

                      ------------------
                      Scott
                      mailto:[email protected][email protected]</A>
                      Scott Turchin
                      MCSE, MCP+I
                      http://www.tngbbs.com
                      ----------------------
                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                      Comment


                      • #31
                        Jeffrey --
                        You can find necessary information about keyboard hook, starting with http://msdn.microsoft.com/library/ps...hooks_8k6b.htm

                        In this sample program imitates button's click, when you press digits 1-9 on numpad.
                        Code:
                        #Compile Exe
                        #Register None
                        #Dim All
                        #Include "win32Api.inc"
                        Global ghKbrdHook As Long
                        Global lpfnKbrdHook  As Long
                        Global hDlg As Long
                        
                        Function KeyboardHook(ByVal iCode As Integer, ByVal wParam As Long, ByVal lParam As Long) As Dword
                           If iCode = %HC_ACTION Then
                              Select Case wParam
                                 Case %VK_NUMPAD1 To %VK_NUMPAD9 ' NumPad  1-9
                                    If (lParam And &H80000000) = 0 Then _
                                       Control Send hDlg, wParam - %VK_NUMPAD1 + 101, %BM_CLICK, 0, 0
                              End Select
                              Function = 1: Exit Function ' sample of ignoring !!!
                           End If
                           Function = CallNextHookEx(ghKbrdHook, iCode, wParam, lParam)
                        End Function
                        
                        CallBack Function Cb
                           Select Case CbMsg
                              Case %WM_INITDIALOG
                                 ghKbrdHook = SetWindowsHookEx(%WH_KEYBOARD, CodePtr(KeyboardHook), _
                                    0, GetCurrentThreadId)
                              Case %WM_DESTROY: UnhookWindowsHookEx ghKbrdHook
                              Case %WM_COMMAND
                                 If CbCtl >=101 And CbCtl <= 109 Then _
                                    SetWindowText CbHndl, "[" + Str$(CbCtl - 100) + " ] " + Time$       
                           End Select
                        End Function
                        
                        Function PbMain
                          Local i As Long
                          Dialog New 0,"Test",,, 100, 180, %ws_sysmenu To hdlg
                          For i = 1 To 9
                          Control Add Button, hdlg,100+ i, "Button" + Str$(i), 10, i * 15 - 10, 80, 12, %WS_BORDER
                          Next
                          Dialog Show Modal hdlg Call Cb
                        End Function
                        Another variant - control of %WM_CHAR (1-9 on any part of keyboard)

                        Code:
                         #Compile Exe
                        #Register None
                        #Dim All
                        #Include "win32Api.inc"
                        Global gHook As Long
                        Global hDlg As Long
                        
                        Sub ButtonClicked (i As Integer)
                           SetWindowText hDlg, "Button" + Str$(i) + " " + Time$
                        End Sub
                        
                        Function SysMsgProc(ByVal nCode As Integer, ByVal wParam As Long, Msg As tagMsg Ptr) As Long
                           If nCode = %MSGF_DIALOGBOX Then
                              If @Msg.Message = %WM_CHAR Then
                                 Select Case Chr$(@Msg.wParam)
                                    Case "1" To "9"
                                       ButtonClicked @Msg.wParam - Asc("0")
                                       Function = 1: Exit Function ' sample of ignoring !!!
                                 End Select
                              End If
                           End If
                           Function = CallNextHookEx(gHook, nCode, wParam, Msg)
                        End Function
                        
                        CallBack Function Cb
                           Select Case CbMsg
                              Case %WM_INITDIALOG
                                 gHook = SetWindowsHookEx(%WH_MSGFILTER, CodePtr(SysMsgProc), _
                                    0, GetCurrentThreadId)
                              Case %WM_DESTROY: UnhookWindowsHookEx gHook
                              Case %WM_COMMAND
                                 If CbCtl >= 101 And CbCtl <= 109 Then ButtonClicked CbCtl - 100
                           End Select
                        End Function
                        
                        Function PbMain
                          Local i As Long
                          Dialog New 0,"Test",,, 100, 180, %ws_sysmenu To hdlg
                          For i = 1 To 9
                             Control Add Button, hdlg,100 + i, "Button" + Str$(i), 10, i * 15 - 10, 80, 12, %WS_BORDER
                          Next
                          Dialog Show Modal hdlg Call Cb
                        End Function
                        ------------------


                        [This message has been edited by Semen Matusovski (edited April 06, 2000).]

                        Comment


                        • #32
                          Semen, Thank you very much for the example code on using SetWindowsHookEx function. I will use the second example in my program that has DDT controls. I found code that simulates pressing keys in a program and used it in my program that has textboxes created using WIN32API calls. Jeffrey.

                          ------------------

                          Comment

                          Working...
                          X