Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

DDT Questions

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

  • DDT Questions

    I have PowerBASIC DLL Compiler 6.0 running on Windows 98 SE. I am writing a program that has six command buttons and six text boxes. How do I write a function that is similar to Form_KeyPress in Visual BASIC? When I press the "1" key, the function should "press" command button 1. When I press the "2" key, the function should "press" command button 2. When I press the "3" key, the function should "press" command button 3. Jeffrey.

  • #2
    There have been discussions on this type of problem before on this BBS. Essentially, the solution involves intercepting keystroke messages for your controls and the dialog/window itself - this is usually accomplished by subclassing and/or intercepting keystroke messages in the applications message pump loop.

    Note that such keystroke interception is neither straight forward nor within the bounds of conventional GUI interface design techniques. However, if you peruse the Source Code forum, you should find a few examples to get you going.

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

    Comment


    • #3
      Lance, I tried to add the "&" character to front of a character in the string to be printed on command buttons so that I can press ALT-character but some ALT-numbers such as ALT-1 and ALT-2 don't work. How can I change the background color of option buttons? How can I write a function that is similar to Form_KeyPress in Visual BASIC so that I can press keys instead of using the mouse to run the program? The code would look like this:

      Code:
      callback function nextstation as long
        if cbmsg=%wm_char and cbwparam=%vk_return then
          buttonpressed=1
          incr stationnumber
          call selectstation
        end if
      end function
      I didn't try this because I am not sure if it will work. Jeffrey.

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

      Comment


      • #4
        there are a range of ways around this problem - such as using a keyboard hook, or use a modeless dialog and handle the message loop yourself where you can trap wm_keydown and wm_keyup messages. such an example can be seen at http://www.powerbasic.com/support/pb...ad.php?t=12662

        i quickly wrote the following code to text your comment about the "&1" accelerator problem, and it give interesting results - not only does it work, but (at least under windows 2000) just pressing 1, 2, 3, 4, or 5 triggers the appropriate button, in addition to the usual alt+<btn> combination.

        <font face="courier new, courier" size="3"><pre>
        #compile exe
        #include "ddt.inc"

        callback function dlgcallback
        if cbmsg = %wm_command then _
        msgbox "you pressed button " & str$(cbctl)
        end function

        function pbmain () as long
        local hdlg as long
        local result as long

        dialog new 0, "test", 1, 1, 60, 140, %ds_center or _
        %ws_caption or %ws_sysmenu, 0 to hdlg
        for x& = 1 to 5
        control add button, hdlg, 100 + x&, _
        "button &" + chr$(48 + x&), 10, 20 * x&,40,14
        next x&
        dialog show modal hdlg, call dlgcallback
        end function
        [/CODE]

        to find out how to "recolor" controls, take a look at the smtp.bas example in your samples\tcp folder... there is an update to this file on the ftp site too - ftp.powerbasic.com/pub/pbdll32/inet


        ------------------
        lance
        powerbasic support
        mailto:[email protected][email protected]</a>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Lance, Thank you very much for your code and the code in the message that you referred me to. When I run your code and press a key, I hear the bell. I will try the code in the message in my program. Jeffrey.

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

          Comment


          • #6
            Does ALT+1 and ALT+2 work in my code snippet?

            Interestingly, it seems that Windows 2000 handles non-ALT keystrokes slightly differently than Win95/98. Can anyone else verify this difference in dialog box behavior?

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

            Comment


            • #7
              About Win2000: I see the same - if button has focus and another buttons have "hot" keys, it's not necessary to press Alt.

              But there is also another interesting moment.
              If a window has a menu and to press single Alt.

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

              Comment


              • #8
                Lance, ALT-1, ALT-2, etc work in your code snippet on my computer running Windows 98 SE. I tried to use some of the code in the message that you referred me to but it didn't work in my program. I will try IF/THEN tests to see if they work. When I press a key, I hear the bell. Here is the code:

                Code:
                #compile exe
                #register none
                #dim all
                #include "win32api.inc"
                global hdlg as long
                global hfont as long
                global buttonpressed as long
                global stationnumber as long
                global string01 as string
                global string02 as string
                global string03 as string
                global string04 as string
                global string05 as string
                global string06 as string
                global string07 as string
                global string08 as string
                global terminal as long
                global stopprogram as long
                sub selectstation
                  select case stationnumber
                    case 1
                      call textbox01("Stop at Beach 67th Street")
                    case 2
                      call textbox01("Stop at Beach 60th Street")
                    case 3
                      call textbox01("Stop at Beach 44th Street")
                    case 4
                      call textbox01("Stop at Beach 36th Street")
                    case 5
                      call textbox01("Stop at Beach 25th Street")
                    case 6
                      call textbox01("Change Direction at Far Rockaway")
                    case 7
                      call textbox01("Stop at Beach 25th Street")
                    case 8
                      call textbox01("Stop at Beach 36th Street")
                    case 9
                      call textbox01("Stop at Beach 44th Street")
                    case 10
                      call textbox01("Stop at Beach 60th Street")
                    case 11
                      call textbox01("Stop at Beach 67th Street")
                      call textbox02("2 - To Broad Channel")
                      call textbox03("3 - To Beach 90th Street")
                      call command02
                      if buttonpressed=2 then
                        call cleartextboxes
                        call command01
                        stationnumber=18
                      end if
                      if buttonpressed=3 then
                        call cleartextboxes
                        call command01
                        stationnumber=11
                      end if
                    case 12
                      call textbox01("Stop at Beach 90th Street")
                    case 13
                      call textbox01("Stop at Beach 98th Street")
                    case 14
                      call textbox01("Stop at Beach 105th Street")
                    case 15
                      call textbox01("Change Direction at Rockaway Park")
                    case 16
                      call textbox01("Stop at Beach 105th Street")
                    case 17
                      call textbox01("Stop at Beach 98th Street")
                    case 18
                      call textbox01("Stop at Beach 90th Street")
                      call textbox02("2 - To Broad Channel")
                      call textbox03("3 - To Beach 67th Street")
                      call command02
                      if buttonpressed=2 then
                        call cleartextboxes
                        call command01
                        stationnumber=18
                      end if
                      if buttonpressed=3 then
                        call cleartextboxes
                        call command01
                        stationnumber=0
                      end if
                    case 19
                      call textbox01("Stop at Broad Channel")
                  end select
                end sub
                sub command01
                  control enable hdlg,101
                  control disable hdlg,102
                  control disable hdlg,103
                  control disable hdlg,104
                  control disable hdlg,105
                  control disable hdlg,106
                  control disable hdlg,107
                end sub
                sub command02
                  control disable hdlg,101
                  control enable hdlg,102
                  control enable hdlg,103
                  control disable hdlg,104
                  control disable hdlg,105
                  control disable hdlg,106
                  control disable hdlg,107
                end sub
                sub command03
                  control disable hdlg,101
                  control enable hdlg,102
                  control enable hdlg,103
                  control enable hdlg,104
                  control disable hdlg,105
                  control disable hdlg,106
                  control disable hdlg,107
                end sub
                sub command04
                  control disable hdlg,101
                  control enable hdlg,102
                  control enable hdlg,103
                  control enable hdlg,104
                  control enable hdlg,105
                  control disable hdlg,106
                  control disable hdlg,107
                end sub
                sub command05
                  control disable hdlg,101
                  control enable hdlg,102
                  control enable hdlg,103
                  control enable hdlg,104
                  control enable hdlg,105
                  control enable hdlg,106
                  control disable hdlg,107
                end sub
                sub command06
                  control disable hdlg,101
                  control enable hdlg,102
                  control enable hdlg,103
                  control enable hdlg,104
                  control enable hdlg,105
                  control enable hdlg,106
                  control enable hdlg,107
                end sub
                sub textbox01(string01 as string)
                  control set text hdlg,112,string01
                end sub
                sub textbox02(string02 as string)
                  control set text hdlg,113,string02
                end sub
                sub textbox03(string03 as string)
                  control set text hdlg,114,string03
                end sub
                sub textbox04(string04 as string)
                  control set text hdlg,115,string04
                end sub
                sub textbox05(string05 as string)
                  control set text hdlg,116,string05
                end sub
                sub textbox06(string06 as string)
                  control set text hdlg,117,string06
                end sub
                sub textbox07(string07 as string)
                  control set text hdlg,118,string07
                end sub
                sub cleartextboxes
                  control set text hdlg,113,""
                  control set text hdlg,114,""
                  control set text hdlg,115,""
                  control set text hdlg,116,""
                  control set text hdlg,117,""
                  control set text hdlg,118,""
                end sub
                callback function nextstation as long
                  buttonpressed=1
                  incr stationnumber
                  call selectstation
                end function
                callback function route01 as long
                  buttonpressed=2
                  call selectstation
                end function
                callback function route02 as long
                  buttonpressed=3
                  call selectstation
                end function
                callback function route03 as long
                  buttonpressed=4
                  call selectstation
                end function
                callback function route04 as long
                  buttonpressed=5
                  call selectstation
                end function
                callback function route05 as long
                  buttonpressed=6
                  call selectstation
                end function
                callback function route06 as long
                  buttonpressed=7
                  call selectstation
                end function
                callback function expressstops as long
                  string08="Skip "
                end function
                callback function localstops as long
                  string08="Stop at "
                end function
                callback function hdlgcb
                   select case cbmsg
                      case %wm_destroy: stopprogram = 1
                   end select
                end function
                function pbmain() as long
                  local msg  as tagmsg
                  dialog new 0,"NYCTA Subway Program",0,0,500,100,%ws_sysmenu + %ws_maximize to hdlg
                  control add button,hdlg,101,"Next Station",10,15,50,20, call nextstation
                  control add button,hdlg,102,"Route 1",10,55,50,20,call route01
                  control add button,hdlg,103,"Route 2",10,95,50,20,call route02
                  control add button,hdlg,104,"Route 3",10,135,50,20,call route03
                  control add button,hdlg,105,"Route 4",10,175,50,20,call route04
                  control add button,hdlg,106,"Route 5",10,215,50,20,call route05
                  control add button,hdlg,107,"Route 6",10,255,50,20,call route06
                  control add button,hdlg,109,"Express stops",75,295,50,20,call expressstops
                  control add button,hdlg,110,"Local stops",140,295,50,20,call localstops
                  control add textbox,hdlg,112,"",75,10,440,30
                  control add textbox,hdlg,113,"",75,50,440,30
                  control add textbox,hdlg,114,"",75,90,440,30
                  control add textbox,hdlg,115,"",75,130,440,30
                  control add textbox,hdlg,116,"",75,170,440,30
                  control add textbox,hdlg,117,"",75,210,440,30
                  control add textbox,hdlg,118,"",75,250,440,30
                  hfont=createfont(40,16,0,0,0,0,0,0,0,0,0,0,0,"arial")
                  control send hdlg,112,%wm_setfont,hfont,%true
                  control send hdlg,113,%wm_setfont,hfont,%true
                  control send hdlg,114,%wm_setfont,hfont,%true
                  control send hdlg, 115,%wm_setfont,hfont,%true
                  control send hdlg, 116,%wm_setfont,hfont,%true
                  control send hdlg, 117,%wm_setfont,hfont,%true
                  control send hdlg, 118,%wm_setfont,hfont,%true
                  dialog show modeless hdlg call hdlgcb
                  stationnumber=6
                  call selectstation
                  while getmessage(msg, %null, 0, 0)
                    select case msg.message
                      case %wm_char:
                        select case msg.wparam
                          case 49:
                            buttonpressed=1
                            incr stationnumber
                            call selectstation
                          case 50:
                            msgbox "2 key pressed"
                            buttonpressed=2
                            call selectstation
                          case 51:
                            buttonpressed=3
                            call selectstation
                          case 52:
                            buttonpressed=4
                            call selectstation
                          case 53:
                            buttonpressed=5
                            call selectstation
                          case 69:
                            string08="Skip "
                          case 108:
                            string08="Stop at "
                        end select
                    end select
                    if isdialogmessage(hdlg, msg) = %false then
                      translatemessage msg
                      dispatchmessage msg
                    end if
                    if stopprogram <> 0 then exit do
                  loop
                end function
                The while getmessage loop doesn't work properly. I press "1" key and it worked but I try to press the other keys and nothing happens except for the bell. How can I get rid of the bell? Jeffrey.

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


                Lance, The IF/THEN tests didn't work. Jeffrey.



                [This message has been edited by Jeffrey Morris (edited March 28, 2000).]

                Comment


                • #9
                  Jeffrey --
                  First, what you should do - to reduce code, al least, at 5 times.
                  Fortunatelly, there are such statements as For ... Next

                  For example

                  control add textbox,hdlg,112,"",75,10,440,30
                  control add textbox,hdlg,113,"",75,50,440,30
                  control add textbox,hdlg,114,"",75,90,440,30
                  control add textbox,hdlg,115,"",75,130,440,30
                  control add textbox,hdlg,116,"",75,170,440,30
                  control add textbox,hdlg,117,"",75,210,440,30
                  control add textbox,hdlg,118,"",75,250,440,30
                  hfont=createfont(40,16,0,0,0,0,0,0,0,0,0,0,0,"arial")
                  control send hdlg,112,%wm_setfont,hfont,%true
                  control send hdlg,113,%wm_setfont,hfont,%true
                  control send hdlg,114,%wm_setfont,hfont,%true
                  control send hdlg, 115,%wm_setfont,hfont,%true
                  control send hdlg, 116,%wm_setfont,hfont,%true
                  control send hdlg, 117,%wm_setfont,hfont,%true
                  control send hdlg, 118,%wm_setfont,hfont,%true

                  Could be converted to
                  Code:
                    Local i As Long
                    hfont = CreateFont (40, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,"arial")
                     For i = 0 To 6
                        Control Add TextBox,hdlg, 112 + i, "", 75, i * 40 + 10, 440, 30
                        Control Send hdlg, 112 + i, %WM_SETFONT, hfont, %True
                     Next
                  It's much readable and clear.
                  Also, don't forget about DeleteObject hFont at the end of program.



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

                  Comment


                  • #10
                    Thats for that suggestion Semen. Jeffrey, can you also post your code using the [ CODE ] and [ /CODE ] "uub" codes so that formatting & indenting is preserved in your code posts. If we can read it we are more likely to be able to help.

                    Also, if you can use Semen's suggestion to reduce the code volume - and strip down as much of the code at necessary for the purposes of finding a solution to your problem, then it is much easier for people such as myself to isolate the problem.

                    Thanks!

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

                    Comment


                    • #11
                      Semen, Thanks for the FOR/NEXT tip. I debugged the program and found out that the subroutines that enable and disable command buttons interferred with the dialog callback subroutine. In Visual BASIC, I would write code like this:

                      Code:
                      Private Sub Form_KeyPress(KeyAscii As Integer)
                        If Command1(0).Enabled = True And KeyAscii = 49 Then Command1(0).Value = True
                        If Command1(1).Enabled = True And KeyAscii = 50 Then Command1(1).Value = True
                        If Command1(2).Enabled = True And KeyAscii = 51 Then Command1(2).Value = True
                        If Command1(3).Enabled = True And KeyAscii = 52 Then Command1(3).Value = True
                        If Command1(4).Enabled = True And KeyAscii = 53 Then Command1(4).Value = True
                        If Command1(5).Enabled = True And KeyAscii = 54 Then Command1(5).Value = True
                        If Command1(6).Enabled = True And KeyAscii = 55 Then Command1(6).Value = True
                        If KeyAscii = 69 Or KeyAscii = 101 Then
                          Option1(0).Value = True
                          string01 = "Skip "
                        End If
                        If KeyAscii = 76 Or KeyAscii = 108 Then
                          Option1(1).Value = True
                          string01 = "Stop at "
                        End If
                        If KeyAscii = 13 Then Command1(7).Value = True
                        If KeyAscii = 27 Then Command1(8).Value = True
                        KeyAscii = 0
                      End Sub
                      In PB/DLL, there is no function that checks to see if a command button is enabled or disabled. I want to use the GetAsyncKeyState function but it needs to be inside a timer loop but I am confused as to how to write the timer loop. Using PB/DLL to write programs is harder than using Visual BASIC to write programs. Jeffrey.

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

                      Comment


                      • #12
                        Lance, I debugged the program and found out that the subroutines that enable and disable command buttons interferred with the dialog callback subroutine. In Visual BASIC, I would write code like this:

                        Code:
                        Private Sub Form_KeyPress(KeyAscii As Integer)
                          If Command1(0).Enabled = True And KeyAscii = 49 Then Command1(0).Value = True
                          If Command1(1).Enabled = True And KeyAscii = 50 Then Command1(1).Value = True
                          If Command1(2).Enabled = True And KeyAscii = 51 Then Command1(2).Value = True
                          If Command1(3).Enabled = True And KeyAscii = 52 Then Command1(3).Value = True
                          If Command1(4).Enabled = True And KeyAscii = 53 Then Command1(4).Value = True
                          If Command1(5).Enabled = True And KeyAscii = 54 Then Command1(5).Value = True
                          If Command1(6).Enabled = True And KeyAscii = 55 Then Command1(6).Value = True
                          If KeyAscii = 69 Or KeyAscii = 101 Then
                            Option1(0).Value = True
                            string01 = "Skip "
                          End If
                          If KeyAscii = 76 Or KeyAscii = 108 Then
                            Option1(1).Value = True
                            string01 = "Stop at "
                          End If
                          If KeyAscii = 13 Then Command1(7).Value = True
                          If KeyAscii = 27 Then Command1(8).Value = True
                          KeyAscii = 0
                        End Sub
                        In PB/DLL, there is no function that checks to see if a command button is enabled or disabled. I want to use the GetAsyncKeyState function but it needs to be inside a timer loop but I am confused as to how to write the timer loop. Using PB/DLL to write programs is harder than using Visual BASIC to write programs. Jeffrey.

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

                        Comment


                        • #13
                          Lance, I took the POPPAD1.BAS program from the PETZOLD.ZIP file, looked through the big fat book, and edited it so that it displays names of subway stations to stop at or skip when I run my model train. I was able to press keys to go to next station or to choose routes. How can I create push buttons and radio buttons using the CreateWindow function. How can I enable and disable the push buttons? How can I change the color of radio button faces? How can I create two client windows - one that lets me choose terminal stations and one that displays names of subway stations to stop at or skip when I run my model train? The program has six edit boxes that were created using the CreateWindow functions. I didn't use DDT functions. Jeffrey.

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

                          Comment


                          • #14
                            Ok.

                            Petzold's code uses the raw API's to create Windows and controls. This approach is often referred to as "SDK-style coding" (SDK meaning the MS Software Developers Kit). It is the "lowest level" you can use to create GUI interfaces by calling the Windows API's directly.

                            It is vastly more complex than using DDT and requires a much greater understanding of how Windows itself works. DDT has the advantage of hiding most of the complexities of the low level code overhead that SDK application coding MUST have - DDT does this "grunt" work for you, saving you a lot of work.

                            To clarify, DDT internally uses the same type of approaches to creating windows as SDK-style coding uses. As a result, you'll find you will hit the same snags with either approach, such as certain things cannot be done during execution of certain callback messages, etc. For example, trying to destroy a button in response to a click on the same button, etc.

                            These kind of restrictions and rules are imposed by Windows on any GUI application that uses Windows to handle the GUI interface.

                            The major difference between DDT and SDK-style coding is that DDT uses the Windows dialog box engine, which in turn uses CreateWindow(), etc. Petzold covers this in his book too - once you learn how to create a dialog at the root level, you'll appreciate how DDT can reduce development time significantly!

                            In summary, there is no easy way to explain all of the techniques you'll need to know for SDK-style coding, especially in a place such as this forum. Afterall, it takes Petzold about 1500 pages to cover these topics at a depth necessary to fully understand the process!

                            My best advice is for you to buy a copy of Petzold for yourself. Once you learn SDK-style coding, you'll find DDT is a real snap. The other good book is Rector/Newcomer's "Win32 Programming" - the ISBN's are listed in the FAQ forum.



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

                            Comment


                            • #15
                              Lance, Here is the code so far:

                              Code:
                              $compile exe
                              $dim all
                              $register none
                              $include "win32api.inc"
                              global hwnd02edit01 as long
                              global hwnd02edit02 as long
                              global hwnd02edit03 as long
                              global hwnd02edit04 as long
                              global hwnd02edit05 as long
                              global key01 as long
                              global key02 as long
                              global key03 as long
                              global key04 as long
                              global key05 as long
                              global szappname as asciiz*9
                              global stationnumber as long
                              global buttonpressed as long
                              global string06 as string
                              global terminal as long
                              sub selectstation
                                select case stationnumber
                                  case 1
                                    call text01("Stop at Beach 67th Street")
                                  case 2
                                    call text01("Stop at Beach 60th Street")
                                  case 3
                                    call text01("Stop at Beach 44th Street")
                                  case 4
                                    call text01("Stop at Beach 36th Street")
                                  case 5
                                    call text01("Stop at Beach 25th Street")
                                  case 6
                                    call text01("Change Direction at Far Rockaway")
                                  case 7
                                    call text01("Stop at Beach 25th Street")
                                  case 8
                                    call text01("Stop at Beach 36th Street")
                                  case 9
                                    call text01("Stop at Beach 44th Street")
                                  case 10
                                    call text01("Stop at Beach 60th Street")
                                  case 11
                                    call text01("Stop at Beach 67th Street")
                                    call text02("2 - To Broad Channel")
                                    call text03("3 - To Beach 90th Street")
                                    call command02
                                    if buttonpressed=2 then
                                      call cleartext
                                      call command01
                                      stationnumber=18
                                    end if
                                    if buttonpressed=3 then
                                      call cleartext
                                      call command01
                                      stationnumber=11
                                    end if
                                  case 12
                                    call text01("Stop at Beach 90th Street")
                                  case 13
                                    call text01("Stop at Beach 98th Street")
                                  case 14
                                    call text01("Stop at Beach 105th Street")
                                  case 15
                                    call text01("Change Direction at Rockaway Park")
                                  case 16
                                    call text01("Stop at Beach 105th Street")
                                  case 17
                                    call text01("Stop at Beach 98th Street")
                                  case 18
                                    call text01("Stop at Beach 90th Street")
                                    call text02("2 - To Broad Channel")
                                    call text03("3 - To Beach 67th Street")
                                    call command02
                                    if buttonpressed=2 then
                                      call cleartext
                                      call command01
                                      stationnumber=18
                                    end if
                                    if buttonpressed=3 then
                                      call cleartext
                                      call command01
                                      stationnumber=0
                                    end if
                                  case 19
                                    call text01("Stop at Broad Channel")
                                end select
                              end sub
                              sub text01(string01 as asciiz)
                                call setwindowtext(hwnd02edit01,string01+chr$(0))
                              end sub
                              sub text02(string02 as asciiz)
                                call setwindowtext(hwnd02edit02,string02+chr$(0))
                              end sub
                              sub text03(string03 as asciiz)
                                call setwindowtext(hwnd02edit03,string03+chr$(0))
                              end sub
                              sub text04(string04 as asciiz)
                                call setwindowtext(hwnd02edit04,string04+chr$(0))
                              end sub
                              sub text05(string05 as asciiz)
                                call setwindowtext(hwnd02edit05,string05+chr$(0))
                              end sub
                              sub cleartext
                                call setwindowtext(hwnd02edit02,""+chr$(0))
                                call setwindowtext(hwnd02edit03,""+chr$(0))
                                call setwindowtext(hwnd02edit04,""+chr$(0))
                                call setwindowtext(hwnd02edit05,""+chr$(0))
                              end sub
                              sub command01
                                key01=1
                                key02=0
                                key03=0
                                key04=0
                                key05=0
                              end sub
                              sub command02
                                key01=0
                                key02=1
                                key03=1
                                key04=0
                                key05=0
                              end sub
                              sub command03
                                key01=0
                                key02=1
                                key03=1
                                key04=1
                                key05=0
                              end sub
                              sub command04
                                key01=0
                                key02=1
                                key03=1
                                key04=1
                                key05=1
                              end sub
                              function winmain(byval hcurrinstance as long,byval hprevinstance as long,lpcmdline as asciiz ptr,byval ncmdshow as long) as long
                                local msg as tagmsg,wclass as wndclassex,hwnd02 as dword
                                szappname = "nycta01"
                                wclass.cbsize = sizeof(wclass)
                                wclass.style = %cs_hredraw or %cs_vredraw
                                wclass.lpfnwndproc = codeptr(mainwndproc)
                                wclass.cbclsextra = 0
                                wclass.cbwndextra = 0
                                wclass.hinstance = hcurrinstance
                                wclass.hicon = loadicon(%null,byval %idi_application)
                                wclass.hcursor = loadcursor(%null,byval %idc_arrow)
                                wclass.hbrbackground = createsolidbrush(&hff0000)
                                wclass.lpszmenuname = %null
                                wclass.lpszclassname = varptr(szappname)
                                wclass.hiconsm = loadicon(%null,byval %idi_application)
                                call registerclassex(wclass)
                                hwnd02 = createwindow(szappname,"NYCTA Subway Program",%ws_overlappedwindow,%cw_usedefault,%cw_usedefault,%cw_usedefault,%cw_usedefault,%null,%null,hcurrinstance,%null)
                                call showwindow(hwnd02,%sw_showmaximized)
                                call updatewindow(hwnd02)
                                while getmessage(msg,%null,0,0)
                                  call translatemessage(msg)
                                  call dispatchmessage(msg)
                                wend
                                function = msg.wparam
                              end function
                              function mainwndproc(byval hwnd02 as dword,byval wmsg as dword,byval wparam as dword,byval lparam as dword) export as long
                                static hfont as long
                                static lpcs as createstruct ptr
                                select case wmsg
                                  case %wm_create
                                    lpcs = lparam
                                    hfont=createfont(48,24,0,0,0,0,0,0,0,0,0,0,0,"arial")
                                    hwnd02edit01 = createwindow("edit",byval %null,%ws_child or %ws_visible or %ws_border  or %es_left or %es_nohidesel,25,25,750,50,hwnd02,1,@lpcs.hinstance,%null)
                                    hwnd02edit02 = createwindow("edit",byval %null,%ws_child or %ws_visible or %ws_border  or %es_left or %es_nohidesel,25,100,750,50,hwnd02,1,@lpcs.hinstance,%null)
                                    hwnd02edit03 = createwindow("edit",byval %null,%ws_child or %ws_visible or %ws_border  or %es_left or %es_nohidesel,25,175,750,50,hwnd02,1,@lpcs.hinstance,%null)
                                    hwnd02edit04 = createwindow("edit",byval %null,%ws_child or %ws_visible or %ws_border  or %es_left or %es_nohidesel,25,250,750,50,hwnd02,1,@lpcs.hinstance,%null)
                                    hwnd02edit05 = createwindow("edit",byval %null,%ws_child or %ws_visible or %ws_border  or %es_left or %es_nohidesel,25,325,750,50,hwnd02,1,@lpcs.hinstance,%null)
                                    call sendmessage(hwnd02edit01,%wm_setfont,hfont,%true)
                                    call sendmessage(hwnd02edit02,%wm_setfont,hfont,%true)
                                    call sendmessage(hwnd02edit03,%wm_setfont,hfont,%true)
                                    call sendmessage(hwnd02edit04,%wm_setfont,hfont,%true)
                                    call sendmessage(hwnd02edit05,%wm_setfont,hfont,%true)
                                    stationnumber=72
                                    terminal=1
                                    string06="Skip "
                                    call command01
                                    call selectstation
                                    function = 0
                                  case %wm_char
                                    if wparam=27 then
                                      call deleteobject(hfont)
                                      call postquitmessage(0)
                                    end if
                                    if wparam=49 and key01 then
                                      buttonpressed=1
                                      incr stationnumber
                                      call selectstation
                                    end if
                                    if wparam=50 and key02 then
                                      buttonpressed=2
                                      call selectstation
                                    end if
                                    if wparam=51 and key03 then
                                      buttonpressed=3
                                      call selectstation
                                    end if
                                    if wparam=52 and key04 then
                                      buttonpressed=4
                                      call selectstation
                                    end if
                                    if wparam=53 and key05 then
                                      buttonpressed=5
                                      call selectstation
                                    end if
                                    if wparam=69 or wparam=101 then string06="Skip "
                                    if wparam=76 or wparam=108 then string06="Stop at "
                                    function = 0
                                  case %wm_destroy
                                    call deleteobject(hfont)
                                    call postquitmessage(0)
                                    function = 0
                                  case else
                                    function = defwindowproc(hwnd02,wmsg,wparam,lparam)
                                end select
                              end function
                              I am not sure if I can rewrite the program so that it uses DDT instead of WIN32API. How about creating a dialog box that lets me choose subway terminals? Jeffrey.

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

                              Comment


                              • #16
                                Hi Jeffrey,
                                I took a look at your code and yes it can be switched to ddt, so far I haven't found too many things that can't, if you really want to. I was curious to see what it looked like so I downloaded the code. If I can ask a question, do you need to use textboxes? If you are not allowing user input and are programmatically changing the text(which it appears you are) then it might be better to use labels instead of textboxes. Just a thought. Also, you have several case statements that "call" the same procedure, so you might want to consolidate them to reduce the code some more.
                                Code:
                                Select case stationnumber
                                  ...
                                  case 2,10
                                    call text01("Stop at Beach 60th street")
                                  ...
                                end select
                                It will reduce your code even more since I found their were several of those in you case block.

                                Regards
                                Adam

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

                                Comment


                                • #17
                                  Adam, I will try using text labels in my program but I am not sure if I can change the background color of the text labels. Text labels usually have gray background and text boxes usually have white background. I will try consolidating my code. Jeffrey.

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

                                  Comment


                                  • #18
                                    I wrote a new version of the subway stop program that uses two dialog boxes created using DDT. When I click on the "X" icon on the top-right corner of the dialog box, the dialog box exits but the program is still running and I have to call up the Task Manager to terminate the program. How can I fix this problem? Jeffrey.

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

                                    Comment


                                    • #19
                                      While the dialog is being dismissed, there must still be part of the code running or the appp would terminate correctly.

                                      As you imply that have two dialogs visible at the same time, I assume that you are using at least one modeless dialog? This means you must have a DIALOG DOEVENTS message pump running too - unless this pump loop drops out when the appropriate dialog is destroyed, the code will run for ever and your app will not terminate naturally.

                                      If you can post the latest version of your code, we may be able to offer a more exacting solution.

                                      Thanks!

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

                                      Comment


                                      • #20
                                        Lance, Here is part of the source code:

                                        Code:
                                        #compile exe
                                        #register none
                                        #dim all
                                        #include "win32api.inc"
                                        global hdlg01 as long
                                        global hdlg02 as long
                                        global hfont as long
                                        global buttonpressed as long
                                        global stopindex as long
                                        global string07 as string
                                        sub selectstation
                                          select case stopindex
                                            case 1
                                              call text01("Stop at Beach 67th Street")
                                            case 2
                                              call text01("Stop at Beach 60th Street")
                                            case 3
                                              call text01("Stop at Beach 44th Street")
                                            case 4
                                              call text01("Stop at Beach 36th Street")
                                            case 5
                                              call text01("Stop at Beach 25th Street")
                                            case 6
                                              call text01("Change Direction at Far Rockaway")
                                            case 7
                                              call text01("Stop at Beach 25th Street")
                                            case 8
                                              call text01("Stop at Beach 36th Street")
                                            case 9
                                              call text01("Stop at Beach 44th Street")
                                            case 10
                                              call text01("Stop at Beach 60th Street")
                                            case 11
                                              call text01("Stop at Beach 67th Street")
                                              call text02("2 - To Broad Channel")
                                              call text03("3 - To Beach 90th Street")
                                              call command02
                                              if buttonpressed=2 then
                                                call cleartext
                                                call command01
                                                stopindex=561
                                                control send hdlg02,101,%bm_click,0,0
                                              end if
                                              if buttonpressed=3 then
                                                call cleartext
                                                call command01
                                                stopindex=11
                                                control send hdlg02,101,%bm_click,0,0
                                              end if
                                            case 12
                                              call text01("Stop at Beach 90th Street")
                                            case 13
                                              call text01("Stop at Beach 98th Street")
                                            case 14
                                              call text01("Stop at Beach 105th Street")
                                            case 15
                                              call text01("Change Direction at Rockaway Park")
                                            case 16
                                              call text01("Stop at Beach 105th Street")
                                            case 17
                                              call text01("Stop at Beach 98th Street")
                                            case 18
                                              call text01("Stop at Beach 90th Street")
                                              call text02("2 - To Broad Channel")
                                              call text03("3 - To Beach 67th Street")
                                              call command02
                                              if buttonpressed=2 then
                                                call cleartext
                                                call command01
                                                stopindex=561
                                                control send hdlg02,101,%bm_click,0,0
                                              end if
                                              if buttonpressed=3 then
                                                call cleartext
                                                call command01
                                                stopindex=0
                                                control send hdlg02,101,%bm_click,0,0
                                              end if
                                            case 19
                                              call text01("Stop at Broad Channel")
                                          end select
                                        end sub
                                        sub command01
                                          control enable hdlg02,101
                                          control disable hdlg02,102
                                          control disable hdlg02,103
                                          control disable hdlg02,104
                                          control disable hdlg02,105
                                        end sub
                                        sub command02
                                          control disable hdlg02,101
                                          control enable hdlg02,102
                                          control enable hdlg02,103
                                          control disable hdlg02,104
                                          control disable hdlg02,105
                                        end sub
                                        sub command03
                                          control disable hdlg02,101
                                          control enable hdlg02,102
                                          control enable hdlg02,103
                                          control enable hdlg02,104
                                          control disable hdlg02,105
                                        end sub
                                        sub command04
                                          control disable hdlg02,101
                                          control enable hdlg02,102
                                          control enable hdlg02,103
                                          control enable hdlg02,104
                                          control enable hdlg02,105
                                        end sub
                                        sub text01(string01 as string)
                                          control set text hdlg02,112,string01
                                        end sub
                                        sub text02(string02 as string)
                                          control set text hdlg02,113,string02
                                        end sub
                                        sub text03(string03 as string)
                                          control set text hdlg02,114,string03
                                        end sub
                                        sub text04(string04 as string)
                                          control set text hdlg02,115,string04
                                        end sub
                                        sub text05(string05 as string)
                                          control set text hdlg02,116,string05
                                        end sub
                                        sub text06(string06 as string)
                                          control set text hdlg02,117,string06
                                        end sub
                                        sub cleartext
                                          control set text hdlg02,113,""
                                          control set text hdlg02,114,""
                                          control set text hdlg02,115,""
                                          control set text hdlg02,116,""
                                        end sub
                                        callback function nextstation as long
                                          buttonpressed=1
                                          incr stopindex
                                          call selectstation
                                        end function
                                        callback function route01 as long
                                          buttonpressed=2
                                          call selectstation
                                        end function
                                        callback function route02 as long
                                          buttonpressed=3
                                          call selectstation
                                        end function
                                        callback function route03 as long
                                          buttonpressed=4
                                          call selectstation
                                        end function
                                        callback function route04 as long
                                          buttonpressed=5
                                          call selectstation
                                        end function
                                        callback function newroute as long
                                          dialog show state hdlg02,%sw_hide
                                          dialog show modal hdlg01
                                        end function
                                        callback function expressstops as long
                                          string07="Skip "
                                          text06("Express Stops")
                                        end function
                                        callback function localstops as long
                                          string07="Stop at "
                                          text06("Local Stops")
                                        end function
                                        callback function exitprogram01 as long
                                          deleteobject hfont
                                          dialog end hdlg01
                                          dialog end hdlg02
                                        end function
                                        callback function exitprogram02 as long
                                          deleteobject hfont
                                          dialog end hdlg01
                                          dialog end hdlg02
                                        end function
                                        callback function runprogram as long
                                          dialog show state hdlg01,%sw_hide
                                          dialog show modal hdlg02
                                          call cleartext
                                          call command01
                                          string07="Skip "
                                          text06("Express Stops")
                                        end function
                                        callback function option01 as long
                                          stopindex=6
                                          call selectstation
                                        end function
                                        callback function option02 as long
                                          stopindex=15
                                          call selectstation
                                        end function
                                        callback function option03 as long
                                          stopindex=21
                                          call selectstation
                                        end function
                                        callback function option04 as long
                                          stopindex=536
                                          call selectstation
                                        end function
                                        callback function option05 as long
                                          stopindex=546
                                          call selectstation
                                        end function
                                        callback function option06 as long
                                          stopindex=276
                                          call selectstation
                                        end function
                                        callback function option07 as long
                                          stopindex=538
                                          call selectstation
                                        end function
                                        callback function option08 as long
                                          stopindex=537
                                          call selectstation
                                        end function
                                        callback function option09 as long
                                          stopindex=31
                                          call selectstation
                                        end function
                                        callback function option10 as long
                                          stopindex=49
                                          call selectstation
                                        end function
                                        callback function option11 as long
                                          stopindex=545
                                          call selectstation
                                        end function
                                        callback function option12 as long
                                          stopindex=241
                                          call selectstation
                                        end function
                                        callback function option13 as long
                                          stopindex=229
                                          call selectstation
                                        end function
                                        callback function option14 as long
                                          stopindex=544
                                          call selectstation
                                        end function
                                        callback function option15 as long
                                          stopindex=543
                                          call selectstation
                                        end function
                                        callback function option16 as long
                                          stopindex=329
                                          call selectstation
                                        end function
                                        callback function option17 as long
                                          stopindex=72
                                          call selectstation
                                        end function
                                        callback function option18 as long
                                          stopindex=540
                                          call selectstation
                                        end function
                                        callback function option19 as long
                                          stopindex=541
                                          call selectstation
                                        end function
                                        callback function option20 as long
                                          stopindex=542
                                          call selectstation
                                        end function
                                        callback function option21 as long
                                          stopindex=91
                                          call selectstation
                                        end function
                                        callback function option22 as long
                                          stopindex=539
                                          call selectstation
                                        end function
                                        callback function option23 as long
                                          stopindex=549
                                          call selectstation
                                        end function
                                        callback function option24 as long
                                          stopindex=535
                                          call selectstation
                                        end function
                                        callback function option25 as long
                                          stopindex=203
                                          call selectstation
                                        end function
                                        callback function option26 as long
                                          stopindex=501
                                          call selectstation
                                        end function
                                        callback function option27 as long
                                          stopindex=521
                                          call selectstation
                                        end function
                                        callback function option28 as long
                                          stopindex=548
                                          call selectstation
                                        end function
                                        callback function option29 as long
                                          stopindex=547
                                          call selectstation
                                        end function
                                        callback function option30 as long
                                          stopindex=216
                                          call selectstation
                                        end function
                                        callback function option31 as long
                                          stopindex=285
                                          call selectstation
                                        end function
                                        callback function option32 as long
                                          stopindex=308
                                          call selectstation
                                        end function
                                        callback function option33 as long
                                          stopindex=355
                                          call selectstation
                                        end function
                                        callback function option34 as long
                                          stopindex=550
                                          call selectstation
                                        end function
                                        callback function option35 as long
                                          stopindex=339
                                          call selectstation
                                        end function
                                        callback function option36 as long
                                          stopindex=367
                                          call selectstation
                                        end function
                                        callback function option37 as long
                                          stopindex=386
                                          call selectstation
                                        end function
                                        callback function option38 as long
                                          stopindex=404
                                          call selectstation
                                        end function
                                        callback function option39 as long
                                          stopindex=456
                                          call selectstation
                                        end function
                                        callback function option40 as long
                                          stopindex=442
                                          call selectstation
                                        end function
                                        callback function option41 as long
                                          stopindex=551
                                          call selectstation
                                        end function
                                        callback function option42 as long
                                          stopindex=552
                                          call selectstation
                                        end function
                                        callback function option43 as long
                                          stopindex=419
                                          call selectstation
                                        end function
                                        callback function option44 as long
                                          stopindex=553
                                          call selectstation
                                        end function
                                        callback function option45 as long
                                          stopindex=478
                                          call selectstation
                                        end function
                                        callback function option46 as long
                                          stopindex=554
                                          call selectstation
                                        end function
                                        callback function option47 as long
                                          stopindex=555
                                          call selectstation
                                        end function
                                        callback function option48 as long
                                          stopindex=556
                                          call selectstation
                                        end function
                                        callback function option49 as long
                                          stopindex=557
                                          call selectstation
                                        end function
                                        callback function option50 as long
                                          stopindex=558
                                          call selectstation
                                        end function
                                        function pbmain() as long
                                          dialog new 0,"NYCTA Subway Program",0,0,500,100,%ws_sysmenu+%ws_maximize to hdlg01
                                          dialog new 0,"NYCTA Subway Program",0,0,500,100,%ws_sysmenu+%ws_maximize to hdlg02
                                          control add button,hdlg02,101,"Next Station",10,15,50,20,call nextstation
                                          control add button,hdlg02,102,"Route 1",10,60,50,25,call route01
                                          control add button,hdlg02,103,"Route 2",10,105,50,25,call route02
                                          control add button,hdlg02,104,"Route 3",10,150,50,25,call route03
                                          control add button,hdlg02,105,"Route 4",10,195,50,25,call route04
                                          control add button,hdlg02,108,"New route",10,285,50,25,call newroute
                                          control add button,hdlg02,109,"Express stops",75,285,50,25,call expressstops
                                          control add button,hdlg02,110,"Local stops",140,285,50,25,call localstops
                                          control add button,hdlg02,111,"Exit program",205,285,50,25,call exitprogram02
                                          control add textbox,hdlg02,112,"",75,10,440,35
                                          control add textbox,hdlg02,113,"",75,55,440,35
                                          control add textbox,hdlg02,114,"",75,100,440,35
                                          control add textbox,hdlg02,115,"",75,145,440,35
                                          control add textbox,hdlg02,116,"",75,190,440,35
                                          control add textbox,hdlg02,117,"",75,235,440,35
                                          hfont=createfont(48,24,0,0,0,0,0,0,0,0,0,0,0,"arial")
                                          control send hdlg02,112,%wm_setfont,hfont,%true
                                          control send hdlg02,113,%wm_setfont,hfont,%true
                                          control send hdlg02,114,%wm_setfont,hfont,%true
                                          control send hdlg02,115,%wm_setfont,hfont,%true
                                          control send hdlg02,116,%wm_setfont,hfont,%true
                                          control send hdlg02,116,%wm_setfont,hfont,%true
                                          control send hdlg02,117,%wm_setfont,hfont,%true
                                          control add option,hdlg01,119,"Far Rockaway",10,10,100,15,call option01
                                          control add option,hdlg01,120,"Rockaway Park",10,30,100,15,call option02
                                          control add option,hdlg01,121,"Lefferts Boulevard",10,50,100,15,call option03
                                          control add option,hdlg01,122,"Euclid Avenue",10,70,100,15,call option04
                                          control add option,hdlg01,123,"World Trade Center",10,90,100,15,call option05
                                          control add option,hdlg01,124,"21st Street",10,110,100,15,call option06
                                          control add option,hdlg01,125,"145th Street",10,130,100,15,call option07
                                          control add option,hdlg01,126,"168th Street",10,150,100,15,call option08
                                          control add option,hdlg01,127,"207th Street",10,170,100,15,call option09
                                          control add option,hdlg01,128,"205th Street",10,190,100,15,call option10
                                          control add option,hdlg01,129,"71st Avenue",10,210,100,15,call option11
                                          control add option,hdlg01,130,"Jamaica Center",10,230,100,15,call option12
                                          control add option,hdlg01,131,"179th Street",10,250,100,15,call option13
                                          control add option,hdlg01,132,"Brighton Beach",10,270,100,15,call option14
                                          control add option,hdlg01,133,"Prospect Park",10,290,100,15,call option15
                                          control add option,hdlg01,134,"Franklin Avenue",10,310,100,15,call option16
                                          control add option,hdlg01,135,"Stillwell Avenue",10,330,100,15,call option17
                                          control add option,hdlg01,136,"Smith Street",120,10,100,15,call option18
                                          control add option,hdlg01,137,"Church Avenue",120,30,100,15,call option19
                                          control add option,hdlg01,138,"Kings Highway",120,50,100,15,call option20
                                          control add option,hdlg01,139,"95th Street",120,70,100,15,call option21
                                          control add option,hdlg01,140,"Bay Parkway",120,90,100,15,call option22
                                          control add option,hdlg01,141,"Whitehall Street",120,110,100,15,call option23
                                          control add option,hdlg01,142,"Lexington Avenue",120,130,100,15,call option24
                                          control add option,hdlg01,143,"Ditmars Boulevard",120,150,100,15,call option25
                                          control add option,hdlg01,144,"Times Square",120,170,100,15,call option26
                                          control add option,hdlg01,145,"Main Street",120,190,100,15,call option27
                                          control add option,hdlg01,146,"Broad Street",120,210,100,15,call option28
                                          control add option,hdlg01,146,"Chambers Street",120,230,100,15,call option29
                                          control add option,hdlg01,147,"Metropolitan Avenue",120,250,100,15,call option30
                                          control add option,hdlg01,148,"Rockaway Parkway",120,270,100,15,call option31
                                          control add option,hdlg01,149,"8th Avenue",120,290,100,15,call option32
                                          control add option,hdlg01,150,"New Lots Avenue",120,310,100,15,call option33
                                          control add option,hdlg01,151,"Utica Avenue",120,330,100,15,call option34
                                          control add option,hdlg01,152,"Flatbush Avenue",230,10,100,15,call option35
                                          control add option,hdlg01,153,"South Ferry",230,30,100,15,call option36
                                          control add option,hdlg01,154,"242nd Street",230,50,100,15,call option37
                                          control add option,hdlg01,155,"148th Street",230,70,100,15,call option38
                                          control add option,hdlg01,156,"241st Street",230,90,100,15,call option39
                                          control add option,hdlg01,157,"Dyre Avenue",230,110,100,15,call option40
                                          control add option,hdlg01,158,"Bowling Green",230,130,100,15,call option41
                                          control add option,hdlg01,159,"Brooklyn Bridge",230,150,100,15,call option42
                                          control add option,hdlg01,160,"Woodlawn",230,170,100,15,call option43
                                          control add option,hdlg01,161,"East 177th Street",230,190,100,15,call option44
                                          control add option,hdlg01,162,"Pelham Bay Park",230,210,100,15,call option45
                                          control add option,hdlg01,163,"36th Street",230,230,100,15,call option46
                                          control add option,hdlg01,164,"Euclid Avenue",230,250,100,15,call option47
                                          control add option,hdlg01,165,"Myrtle Avenue",230,270,100,15,call option48
                                          control add option,hdlg01,166,"East 180th Street",230,290,100,15,call option49
                                          control add option,hdlg01,167,"125th Street",230,310,100,15,call option50
                                          control add button,hdlg01,200,"Run program",230,330,50,15,call runprogram
                                          control add button,hdlg01,201,"Exit program",290,330,50,15,call exitprogram01
                                          dialog show modal hdlg01
                                        end function
                                        If I click on the "Exit" button in either dialog box, the program terminates correctly. Jeffrey.

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

                                        Comment

                                        Working...
                                        X