Announcement

Collapse
No announcement yet.

MS Visual Studio 6.0 Tools

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

  • MS Visual Studio 6.0 Tools

    How can I use the tools in MS Visual Studio 6.0 to create and compile a dialog box for a PB/DLL program? I created a dialog box but I couldn't compile it. I used PowerGen to create a BASIC program for the dialog box but I got error messages when I tried to use PB/DLL to compile the program. Jeffrey.

  • #2
    I use this DDT-code:
    Code:
    #COMPILE EXE
    #DIM ALL
    #REGISTER NONE
    #RESOURCE "Script1.pbr"
    #INCLUDE "win32api.inc"
    #INCLUDE "commctrl.inc"
    #INCLUDE "resource.inc"    ' Translation of resource.h
     
    GLOBAL hInst AS LONG
     
    FUNCTION PBMAIN
        hInst = GetModuleHandle(BYVAL 0)
        DialogBox hInst, BYVAL %IDD_DIALOG1, 0, CODEPTR(MainDlgProc)
    END FUNCTION
     
    CALLBACK FUNCTION MainDlgProc
     
        SELECT CASE CBMSG
        CASE %WM_INITDIALOG
    '       DIALOG SEND CBHNDL, %WM_SETICON, %ICON_BIG, LoadIcon(hInst,"ICON")
        CASE %WM_COMMAND
            SELECT CASE LOWRD(CBWPARAM) 
            CASE %IDOK
            CASE %IDCANCEL
                DIALOG END CBHNDL
            END SELECT
        CASE %WM_SYSCOMMAND
            IF CBWPARAM = %SC_CLOSE THEN DIALOG END CBHNDL
        END SELECT
     
    END FUNCTION

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

    Comment


    • #3
      Switch off the MFC-features in Visual Studio (it's in the Properties list of the resource you are creating), otherwise it will cause you trouble.

      BTW, when you save the resource file, follow it with a SAVE-AS, and select .RES from the list - this saves you using the RC.EXE as supplied with Visual Studio, leaving just the PBRES.EXE utility to convert the resource to a .PBR file.

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

      Comment


      • #4
        Jeffrey, I edited your posting as my reply by mistake. However, your huge code posting is not appropriate for this type of question anyway - a BAS file that relies on a PBR file is almost not worth posting.

        Your question was:

        How can I add RichTextBox control to the program?
        Simple... use Visual Studio and place a RichEdit control on your dialog, then regenerate your template with PowerGEN.

        However, instead of just losing all of your changes (which will happen if you just run PowerGEN over the top of your changes), save a copy of your existing code elsewhere first.

        Then, rerun PowerGEN on the dialog you have been using until now, and save this code elsewhere. This gets you the "base code".

        Next, add the richedit control with VS, and then run PowerGen on this code. This gets you the "updated code".

        Finally, compare the "base code" with the "updated code" - the differences are what you will need to add to your existing code in order to get the rich edit control working!

        There is a visual file compare utility supplied with Visual Studio that is great for this little job (at least, there is with VS 5.0)

        Lance
        PowerBASIC Support

        Comment


        • #5
          Lance, I searched the forum messages related to RichEditBox control and after trials and errors, I added RichEditBox controls to my subway stop program using WIN32API calls. I tried to add code to change color of text but the code that worked in the program that uses DDT calls didn't work in the program that uses WIN32API calls. Jeffrey.



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

          Comment


          • #6
            Jeffrey,

            Post *just* the RICHEDIT code - the DDT code that you successfully used, and your conversion of this code into SDK style code. (ie, don't post the whole file!)

            Thanks!

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

            Comment


            • #7
              Lance, Here are the programs:

              Code:
              DDT Version:
              function setrichtextcolor(byval newcolor as long) as long
                local cf as charformat2
                cf.cbsize=len(cf)
                cf.dwmask=%cfm_color
                cf.crtextcolor=newcolor
                call sendmessage(hedit1,%em_setcharformat,%scf_selection,varptr(cf))
              end function
              sub markstring(byval alltext as string,byval mytext as string,byval ccol as long)
                local stoppos as long
                stoppos=instr(alltext,mytext)
                if stoppos then
                   call sendmessage(hedit1,%em_setsel,stoppos-1,stoppos+len(mytext)-1)
                   call setrichtextcolor(ccol)
                   call sendmessage(hedit1,%em_setsel,stoppos+len(mytext)-1,stoppos+len(alltext)-1)
                   call setrichtextcolor(0)
                end if
              end sub
              function markall(byval mytext as string) as long
                local alltext as string,tlen as long
                tlen=sendmessage(hedit1,%wm_gettextlength,0,0)+1
                alltext=space$(tlen)
                call sendmessage(hedit1,%wm_gettext,tlen,strptr(alltext))
                call sendmessage(hedit1,%wm_setredraw,0,0)
                call markstring(alltext,"Change",&h80)
                call markstring(alltext,"Stop",&h80)
                call markstring(alltext,"Skip",&h008000)
                call sendmessage(hedit1,%em_setsel,0,0)
                sendmessage hedit1,%wm_setredraw,1,0
                invalidaterect hedit1,byval %null,0
                updatewindow hedit1
              end function
              sub text01(string01 as string)
                call sendmessage(hedit1,%wm_settext,0,strptr(string01))
              end sub
              sub text02(string02 as string)
                call sendmessage(hedit2,%wm_settext,0,strptr(string02))
              end sub
              sub text03(string03 as string)
                call sendmessage(hedit3,%wm_settext,0,strptr(string03))
              end sub
              sub text04(string04 as string)
                call sendmessage(hedit4,%wm_settext,0,strptr(string04))
              end sub
              sub text05(string05 as string)
                call sendmessage(hedit5,%wm_settext,0,strptr(string05))
              end sub
              sub text06(string06 as string)
                call sendmessage(hedit6,%wm_settext,0,strptr(string06))
              end sub
              sub cleartext
                local string01 as string
                string01=""
                call sendmessage(hedit2,%wm_settext,0,strptr(string01))
                call sendmessage(hedit3,%wm_settext,0,strptr(string01))
                call sendmessage(hedit4,%wm_settext,0,strptr(string01))
                call sendmessage(hedit5,%wm_settext,0,strptr(string01))
              end sub
              function pbmain() as long
                  local hriched as long
                  local loop01 as long
                  hriched=loadlibrary("riched32.dll")
                  call initcommoncontrols
                  dialog new 0,"NYCTA Subway Program",1,1,312,213,%ws_maximize + %ws_sysmenu to hform1
                  control add button,hform1,%ctlcommand02,"Cancel",340,250,100,15 call evtcommand02
                  control add button,hform1,%ctlcommand01,"OK",340,230,100,15 call evtcommand01
                  control add option,hform1,%ctloption50,"Pelham Bay Park    ",340,210,100,15 call evtoption50
                  control add option,hform1,%ctloption49,"East 177th Street  ",340,190,100,15 call evtoption49
                  control add option,hform1,%ctloption48,"Woodlawn           ",340,170,100,15 call evtoption48
                  control add option,hform1,%ctloption47,"125th Street       ",340,150,100,15 call evtoption47
                  control add option,hform1,%ctloption46,"Brooklyn Bridge    ",340,130,100,15 call evtoption46
                  control add option,hform1,%ctloption45,"Bowling Green      ",340,110,100,15 call evtoption45
                  control add option,hform1,%ctloption44,"241st Street       ",340,90,100,15 call evtoption44
                  control add option,hform1,%ctloption43,"Dyre Avenue        ",340,70,100,15 call evtoption43
                  control add option,hform1,%ctloption42,"East 180th Street  ",340,50,100,15 call evtoption42
                  control add option,hform1,%ctloption41,"148th Street       ",340,30,100,15 call evtoption41
                  control add option,hform1,%ctloption40,"242nd Street       ",340,10,100,15 call evtoption40
                  control add option,hform1,%ctloption39,"South Ferry        ",230,250,100,15 call evtoption39
                  control add option,hform1,%ctloption38,"Flatbush Avenue    ",230,230,100,15 call evtoption38
                  control add option,hform1,%ctloption37,"Utica Avenue       ",230,210,100,15 call evtoption37
                  control add option,hform1,%ctloption36,"New Lots Avenue    ",230,190,100,15 call evtoption36
                  control add option,hform1,%ctloption35,"8th Avenue         ",230,170,100,15 call evtoption35
                  control add option,hform1,%ctloption34,"Rockaway Parkway   ",230,150,100,15 call evtoption34
                  control add option,hform1,%ctloption33,"Metropolitan Avenue",230,130,100,15 call evtoption33
                  control add option,hform1,%ctloption32,"Myrtle Avenue      ",230,110,100,15 call evtoption32
                  control add option,hform1,%ctloption31,"Chambers Street    ",230,90,100,15 call evtoption31
                  control add option,hform1,%ctloption30,"Broad Street       ",230,70,100,15 call evtoption30
                  control add option,hform1,%ctloption29,"Main Street        ",230,50,100,15 call evtoption29
                  control add option,hform1,%ctloption28,"Times Square       ",230,30,100,15 call evtoption28
                  control add option,hform1,%ctloption27,"Ditmars Boulevard  ",230,10,100,15 call evtoption27
                  control add option,hform1,%ctloption26,"Lexington Avenue   ",120,250,100,15 call evtoption26
                  control add option,hform1,%ctloption25,"Whitehall Street   ",120,230,100,15 call evtoption25
                  control add option,hform1,%ctloption24,"36th Street        ",120,210,100,15 call evtoption24
                  control add option,hform1,%ctloption23,"95th Street        ",120,190,100,15 call evtoption23
                  control add option,hform1,%ctloption22,"Bay Parkway        ",120,170,100,15 call evtoption22
                  control add option,hform1,%ctloption21,"Kings Highway      ",120,150,100,15 call evtoption21
                  control add option,hform1,%ctloption20,"Church Avenue      ",120,130,100,15 call evtoption20
                  control add option,hform1,%ctloption19,"Smith Street       ",120,110,100,15 call evtoption19
                  control add option,hform1,%ctloption18,"Stillwell Avenue   ",120,90,100,15 call evtoption18
                  control add option,hform1,%ctloption17,"Brighton Beach     ",120,70,100,15 call evtoption17
                  control add option,hform1,%ctloption16,"Franklin Avenue    ",120,50,100,15 call evtoption16
                  control add option,hform1,%ctloption15,"Prospect Park      ",120,30,100,15 call evtoption15
                  control add option,hform1,%ctloption14,"179th Street       ",120,10,100,15 call evtoption14
                  control add option,hform1,%ctloption13,"Jamaica Center     ",10,250,100,15 call evtoption13
                  control add option,hform1,%ctloption12,"71st Avenue        ",10,230,100,15 call evtoption12
                  control add option,hform1,%ctloption11,"Queens Plaza       ",10,210,100,15 call evtoption11
                  control add option,hform1,%ctloption10,"205th Street       ",10,190,100,15 call evtoption10
                  control add option,hform1,%ctloption09,"207th Street       ",10,170,100,15 call evtoption09
                  control add option,hform1,%ctloption08,"168th Street       ",10,150,100,15 call evtoption08
                  control add option,hform1,%ctloption07,"145th Street       ",10,130,100,15 call evtoption07
                  control add option,hform1,%ctloption06,"21st Street        ",10,110,100,15 call evtoption06
                  control add option,hform1,%ctloption05,"World Trade Center ",10,90,100,15 call evtoption05
                  control add option,hform1,%ctloption04,"Euclid Avenue      ",10,70,100,15 call evtoption04
                  control add option,hform1,%ctloption03,"Lefferts Boulevard ",10,50,100,15 call evtoption03
                  control add option,hform1,%ctloption02,"Rockaway Park      ",10,30,100,15 call evtoption02
                  control add option,hform1,%ctloption01,"Far Rockaway       ",10,10,100,15 call evtoption01
                  hfont=createfont(14,7,0,0,0,0,0,0,0,0,0,0,0,"lucida console")
                  for loop01=0 to 49
                    control send hform1,111+loop01,%wm_setfont,hfont,%true
                  next loop01
                  dialog new 0,"NYCTA Subway Program",0,0,312,213,%ws_maximize + %ws_sysmenu to hform2
                  control add button, hform2,%ctlcommand10,"E&xit",70,320,50,20 call evtcommand10
                  control add button, hform2,%ctlcommand09,"New &Route",10,320,50,20 call evtcommand09
                  control add button, hform2,%ctlcommand08,"&Stop Type",10,270,50,20 call evtcommand08
                  control add button, hform2,%ctlcommand07,"Route &4",10,220,50,20 call evtcommand07
                  control add button, hform2,%ctlcommand06,"Route &3",10,170,50,20 call evtcommand06
                  control add button, hform2,%ctlcommand05,"Route &2",10,120,50,20 call evtcommand05
                  control add button, hform2,%ctlcommand04,"Route &1",10,70,50,20 call evtcommand04
                  control add button, hform2,%ctlcommand03,"&Next Station",10,20,50,20 call evtcommand03
                  control add "richedit",hform2,%ctltextbox6,"",70,260,450,40,%ws_visible or %ws_child,%ws_ex_clientedge
                  control add "richedit",hform2,%ctltextbox5,"",70,210,450,40,%ws_visible or %ws_child,%ws_ex_clientedge
                  control add "richedit",hform2,%ctltextbox4,"",70,160,450,40,%ws_visible or %ws_child,%ws_ex_clientedge
                  control add "richedit",hform2,%ctltextbox3,"",70,110,450,40,%ws_visible or %ws_child,%ws_ex_clientedge
                  control add "richedit",hform2,%ctltextbox2,"",70,60,450,40,%ws_visible or %ws_child,%ws_ex_clientedge
                  control add "richedit",hform2,%ctltextbox1,"",70,10,450,40,%ws_visible or %ws_child,%ws_ex_clientedge
                  hfont=createfont(60,30,0,0,0,0,0,0,0,0,0,0,0,"arial")
                  for loop01=0 to 5
                    control send hform2,161+loop01,%wm_setfont,hfont,%true
                  next loop01
                  control send hform2,%ctltextbox6,%wm_setfont,hfont,%true
                  control send hform2,%ctltextbox5,%wm_setfont,hfont,%true
                  control send hform2,%ctltextbox4,%wm_setfont,hfont,%true
                  control send hform2,%ctltextbox3,%wm_setfont,hfont,%true
                  control send hform2,%ctltextbox2,%wm_setfont,hfont,%true
                  control send hform2,%ctltextbox1,%wm_setfont,hfont,%true
                  control handle hform2,%ctltextbox6 to hedit6
                  control handle hform2,%ctltextbox5 to hedit5
                  control handle hform2,%ctltextbox4 to hedit4
                  control handle hform2,%ctltextbox3 to hedit3
                  control handle hform2,%ctltextbox2 to hedit2
                  control handle hform2,%ctltextbox1 to hedit1
                  dialog show modal hform1 call form1proc
              end function
              
              WIN32API Version:
              sub text01(string01 as asciiz)
                call setwindowtext(hwnd01edit01,string01)
              end sub
              sub text02(string02 as asciiz)
                call setwindowtext(hwnd01edit02,string02)
              end sub
              sub text03(string03 as asciiz)
                call setwindowtext(hwnd01edit03,string03)
              end sub
              sub text04(string04 as asciiz)
                call setwindowtext(hwnd01edit04,string04)
              end sub
              sub text05(string05 as asciiz)
                call setwindowtext(hwnd01edit05,string05)
              end sub
              sub text06(string06 as asciiz)
                call setwindowtext(hwnd01edit06,string06)
              end sub
              sub cleartext
                call setwindowtext(hwnd01edit02,"")
                call setwindowtext(hwnd01edit03,"")
                call setwindowtext(hwnd01edit04,"")
                call setwindowtext(hwnd01edit05,"")
              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
                local wclass as wndclassex
                local hwnd01 as dword
                local szappname as asciiz*7
                szappname="nycta01"
                wclass.cbsize=sizeof(wclass)
                wclass.style=%cs_hredraw or %cs_vredraw
                wclass.lpfnwndproc=codeptr(wndproc)
                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)
                hwnd01=createwindow(szappname,"NYCTA Subway Program",%ws_overlappedwindow,%cw_usedefault,%cw_usedefault,%cw_usedefault,%cw_usedefault,%null,%null,hcurrinstance,%null)
                call showwindow(hwnd01,%sw_showmaximized)
                call updatewindow(hwnd01)
                call dialogbox(hcurrinstance,byval %idd_dialog1,0,codeptr(routedlgproc))
                while getmessage(msg,%null,0,0)
                  call translatemessage(msg)
                  call dispatchmessage(msg)
                wend
                function=msg.wparam
              end function
              function wndproc(byval hwnd01 as dword,byval wmsg as dword,byval wparam as dword,byval lparam as dword) export as long
                static lpcs as createstruct ptr
                select case wmsg
                  case %wm_create
                    lpcs=lparam
                    hlib=loadlibrary("riched32.dll")
                    call initcommoncontrols
                    hwnd01edit01=createwindow("richedit",byval %null,%ws_child or %ws_visible or %ws_border,25,25,750,50,hwnd01,1,@lpcs.hinstance,%null)
                    hwnd01edit02=createwindow("richedit",byval %null,%ws_child or %ws_visible or %ws_border,25,100,750,50,hwnd01,1,@lpcs.hinstance,%null)
                    hwnd01edit03=createwindow("richedit",byval %null,%ws_child or %ws_visible or %ws_border,25,175,750,50,hwnd01,1,@lpcs.hinstance,%null)
                    hwnd01edit04=createwindow("richedit",byval %null,%ws_child or %ws_visible or %ws_border,25,250,750,50,hwnd01,1,@lpcs.hinstance,%null)
                    hwnd01edit05=createwindow("richedit",byval %null,%ws_child or %ws_visible or %ws_border,25,325,750,50,hwnd01,1,@lpcs.hinstance,%null)
                    hwnd01edit06=createwindow("richedit",byval %null,%ws_child or %ws_visible or %ws_border,25,400,750,50,hwnd01,1,@lpcs.hinstance,%null)
                    hfont=createfont(48,24,0,0,0,0,0,0,0,0,0,0,0,"arial")
                    call sendmessage(hwnd01edit01,%wm_setfont,hfont,%true)
                    call sendmessage(hwnd01edit02,%wm_setfont,hfont,%true)
                    call sendmessage(hwnd01edit03,%wm_setfont,hfont,%true)
                    call sendmessage(hwnd01edit04,%wm_setfont,hfont,%true)
                    call sendmessage(hwnd01edit05,%wm_setfont,hfont,%true)
                    call sendmessage(hwnd01edit06,%wm_setfont,hfont,%true)
                    function=0
                  case %wm_char
                    if wparam=13 then call dialogbox(hcurrinstance,byval %idd_dialog1,0,codeptr(routedlgproc))
                    if wparam=27 then
                      call deleteobject(hfont)
                      call postquitmessage(0)
                    end if
                    if wparam=49 and key01 then
                      buttonpressed=1
                      incr stopindex
                      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=54 then
                      boolean=isfalse(boolean)
                      if boolean=-1 then
                        string07="Skip "
                        call text06("Express Stops")
                      end if
                      if boolean=0 then
                        string07="Stop at "
                        call text06("Local Stops")
                      end if
                    end if
                    function=0
                  case %wm_destroy
                    call deleteobject(hfont)
                    call postquitmessage(0)
                    function=0
                  case else
                    function=defwindowproc(hwnd01,wmsg,wparam,lparam)
                end select
              end function
              I tried to copy some of the code from the DDT version to the WIN32API version but when I tried to compile the WIN32API version, I get compiler error messages. Jeffrey.


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

              Comment


              • #8
                "I got compiler error messages".

                Did you get any particular error messages, or did they just says "ERROR"?

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

                Comment


                • #9
                  Lance, The MarkString subroutine is not working properly. The first time that it is called, "Change" is printed in red and the rest of the text is printed in black. The next time that it is called, the whole text is printed in red.

                  Code:
                  sub markstring(byval alltext as string,byval mytext as string,byval ccol as long)
                    local stoppos as long
                    stoppos=instr(alltext,mytext)
                    if stoppos then
                       call sendmessage(hwnd01edit01,%em_setsel,stoppos-1,stoppos+len(mytext)-1)
                       call setrichtextcolor(ccol)
                       call sendmessage(hwnd01edit01,%em_setsel,stoppos+len(mytext)-1,stoppos+len(alltext)-1)
                       call setrichtextcolor(0)
                    end if
                  end sub
                  Jeffrey.


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

                  Comment


                  • #10
                    Lance, I fixed the problem - I forgot to put "call markall("Stop")" line in the select case/end case loop in the WndProc function. Jeffrey.


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

                    Comment

                    Working...
                    X