Announcement

Collapse
No announcement yet.

New PB Graphic commands

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

  • New PB Graphic commands

    I'm trying to get away from the windows API and use the PB graphics commands. I think I did everything correctly in the code below, but it doesn't work. Anyone have any ideas?


    Code:
    #compile exe
    
    #include "\pbwin80\winapi\win32api.inc"
    
    declare function testproc(byval long,byval long,byval long,byval long) as long
    
    function winmain(byval hinst&,byval hprev&,byval cmdline as asciiz ptr,byval cmdshow&) as long
    
         dim wmsg as tagmsg
    
         xsize&=getsystemmetrics(%sm_cxscreen)
         ysize&=getsystemmetrics(%sm_cyscreen)
         ysize&=ysize&*(.95)
    
    ''create class and register it with windows
    
         dim wclass as wndclass
         dim wclassname as asciiz*80
         dim wcaption as asciiz*80
    
         wclassname="TestProg"
    
         if isfalse(hprev&) then
           wclass.style=%cs_hredraw or %cs_vredraw
           wclass.lpfnwndproc=codeptr(testproc)
           wclass.cbclsextra=0
           wclass.cbwndextra=0
           wclass.hinstance=hinst&
           wclass.hicon=%null
           wclass.hcursor=loadcursor(%null,byval %idc_arrow)
           wclass.hbrbackground=getstockobject(%gray_brush)
           wclass.lpszmenuname=%null
           wclass.lpszclassname=varptr(wclassname)
           registerclass wclass
         end if
    
         wcaption="Test Window"
         style&=%ws_popup or %ws_visible or %ws_caption or %ws_sysmenu
    
         hwnd&=createwindow(wclassname,_            ''window class name
                            wcaption,_              ''window caption
                            style&,_                ''window style
                            0,_                     ''initial x position
                            0,_                     ''initial y position
                            xsize&,_                ''initial x size
                            ysize&,_                ''initial y size
                            %null,_                 ''parent window handle
                            %null,_                 ''window menu handle
                            hinst&,_                ''program instance handle
                            %null)                  ''creation parameters
    
         showwindow hwnd&,cmdshow&
         updatewindow hwnd&
    
         while istrue(getmessage(wmsg,byval %null,0,0))
           translatemessage wmsg
           dispatchmessage wmsg
         wend
    
         function=wmsg.wparam
    end function
    
    function testproc(byval hwnd&,byval msg&,byval wparam&,byval lparam&) as long
    
         select case msg&
           case %wm_create
    
             dim wndrect as rect
    
             getclientrect hwnd&,wndrect
    
             xsize&=wndrect.nright-wndrect.nleft
             ysize&=wndrect.nbottom-wndrect.ntop
    
             control add graphic,hwnd&,1000,"",0,0,xsize&,ysize&,%ws_visible or %ws_child or %ss_notify
    
             graphic attach hwnd&,1000
    
             gosub prtest
    
             updatewindow hwnd&
    
           case %wm_paint
             dim ps as paintstruct
             hdc&=beginpaint(hwnd&,ps)
    
             endpaint hwnd&,ps
           case %wm_syscommand
             if lowrd(wparam&)<>%sc_close then exit select
    
             destroywindow hwnd&
             function=1
             exit function
           case %wm_destroy
             postquitmessage 0
             function=0
             exit function
         end select
    
         function=defwindowproc(hwnd&,msg&,wparam&,lparam&)
         exit function
    
    prtest:
    
         graphic clear %white
         graphic color %black,%white
    
         graphic get client to xsize&,ysize&
    
         xsize&=int(xsize&*(.9))
         ysize&=int(ysize&*(.9))
    
         xdiff#=round((xsize&/(highx&-lowx&)),4)
         ydiff#=round((ysize&/(highy&-lowy&)),4)
    
         if xdiff#<ydiff# then diffmult#=xdiff# else diffmult#=ydiff#
    
         if xsize&>ysize& then
           extra&=int(xsize&*(.002))
         else
           extra&=int(ysize&*(.002))
         end if
    
         d$=""
    
         graphic color %black,%white
    
         for z&=1 to 200
           x1&=z&
           y1&=z&+z&
           x2&=z&+z&
           y2&=z&
           graphic line (x1&,y1&) - (x2&,y2&)
         next z&
    
         if xsize&>ysize& then
           extra&=int(xsize&*(.0075))
         else
           extra&=int(ysize&*(.0075))
         end if
    
         graphic color %black,%yellow
    
         for z&=1 to 30
           x1&=z&*10
           y1&=(z&*10)+10
           graphic ellipse ((x1&-extra&),(y1&-extra&)) - ((x1&+extra&),(y1&+extra&)),%black,%yellow,fillstyle&
           'arc hdc&,(x1&-extra&),(y1&-extra&),(x1&+extra&),(y1&+extra&),(x1&-extra&),(y1&-extra&),(x1&-extra&),(y1&-extra&)
           'arc hdc&,(x1&-extra&),(y1&-extra&),(x1&+extra&),(y1&+extra&),(x1&+extra&),(y1&+extra&),(x1&+extra&),(y1&+extra&)
         next z&
    
         graphic color %black,%white
    
         graphic redraw
    
         return
    
    end function
    Last edited by Jim Seekamp; 6 Nov 2007, 03:04 PM.
    Jim Seekamp

  • #2
    > control add graphic,

    AFAIK 'CONTROL ADD' is only valid for use with a window created by DIALOG NEW.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Sigh

      Well, that would explain it!
      Thanks!
      Jim Seekamp

      Comment


      • #4
        Originally posted by Jim Seekamp View Post
        I'm trying to get away from the windows API and use the PB graphics commands.
        Just curious Jim. If you are trying to get away from API (a good thing IMO) then why would you use API to create the Dialog? (I suspect the reason is you are using a C&P from an existing program or template.)

        ===========================
        Each year, one vicious habit rooted out,
        in time ought to make the worst man good.
        Ben Franklin
        ===========================
        It's a pretty day. I hope you enjoy it.

        Gösta

        JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
        LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

        Comment


        • #5
          Good question, Gösta.

          What I meant was I'm trying to get away from the Windows API GRAPHICS (which are a pain).

          But overall I still prefer (and use almost exclusively) the Windows API over trhe PB DDT, just because it makes more sense to me.

          And PB works great that way. I've written a couple hundred apps that way and they never have any problems. (That's my plug for PB)
          Jim Seekamp

          Comment


          • #6
            Jim,

            You have an unusual redundancy in your code.

            Code:
            if isfalse(hprev&) then
            In 32 bit API code there is no previous instance, the form is retained for compatibility with 16 bit Windows only. If you need to test before creating the window with CreateWindowEx() test the RegisterClassEx() return value.
            hutch at movsd dot com
            The MASM Forum - SLL Modules and PB Libraries

            http://www.masm32.com/board/index.php?board=69.0

            Comment

            Working...
            X