1. Final: code (using Win32lib) that doesnt seem to work proper.
- Posted by euman at bellsouth.net May 30, 2002
- 941 views
----- Original Message ----- From: "Derek Parnell" <Derek.Parnell at SYD.RABOBANK.COM> > G'day, > nice to hear from you again. Thanks for responding so quickly. > The reason you would be having trouble is that there are two DC's involved > in the example code. I finally broke down and looked into this in the library. > The one you get, and the one that drawEllipse() uses. > They are NOT the same one. In Win32lib, each of the wrapped graphics > routines, gets its own DC and releases it again before returning to the > caller. The one exception is if all the draw routines are called inside a > Paint event. In that case, all share the same DC until the paint event > completes. This would be a problem for graphic objects and slow the library down not to mention bloat the library with repeat code. If you were to use "OwnDC" then a Window DC would be allocated for the life of the Window and no other DC would be required, unless you were using a Double buffering method ofcourse. > Hope that helps. I'm currently rewriting the DC handling inside the library. > One of the things you will be able to do is get a DC and then use that DC > with the wrapped graphics routines until you decide to release it. I mostly > got that working except for Pixmap and Bitmaps, so I should probably finish > it this weekend. You answered my reply above and this is a good thing for the library. for example, there are some API's that arent wrapped yet that would require a DC handle and we dont really need to obtain a handle, use it then destroy each time we use a particular object. "one will do just fine" Thanks Big-D I attached some more of that demo program for everyone to look at (below) I think its a neat demo and has lots of potential written all over it. P.S Derek look at the pInitExtent, I can use this "InitExtent = getClientRect(MainWin)" to obtain my client coords but must poke them if I need to use pointers. Is there already a routine for this? P.P.S if you need any help with pixmaps and Bitmaps I could probably help out in that area now. Im still working on my Installers but I need a small break before I go insane. > ---------- > Derek. Euman -- Similar but not a copy of Chapter 10 - Windows 2000 Graphics API Black Book (Coriolis & Damon Chandler)) -- Highly recommended Book for the Serious Windows API Programmers. -- Euman 2002 without warning include Win32Lib.ew constant xSetViewportExtEx = registerw32Function(gdi32, "SetViewportExtEx", {C_LONG,C_INT,C_INT,C_INT},C_INT) ,xSetWindowExtEx = registerw32Function(gdi32, "SetWindowExtEx",{C_LONG,C_INT,C_INT,C_POINTER},C_INT) ,iEllipse = registerw32Procedure(gdi32, "Ellipse",{C_LONG,C_INT,C_INT,C_INT,C_INT}) ,iDrawText = registerw32Procedure(user32, "DrawTextA",{C_LONG,C_POINTER,C_INT,C_POINTER,C_UINT}) object junk constant MainWin = create( Window, "Mapping Mode Scaling Demo", NULL, 25, 25, 300, 200, 0 ) sequence InitExtent atom MainWinDC, hFont, oldMapMode, pInitExtent, pText constant MM_ANISOTROPIC = 8 -- onOpen_MainWin procedure onOpen_MainWin( integer self, integer event, sequence parms ) sequence Text InitExtent = getClientRect( MainWin ) pInitExtent = allocate(16) poke4(pInitExtent , InitExtent[1]) poke4(pInitExtent+4 , InitExtent[2]) poke4(pInitExtent+8 , InitExtent[3]) poke4(pInitExtent+12, InitExtent[4]) MainWinDC = getDC ( MainWin ) hFont = EzCreateFont(MainWin, MainWinDC,"Times New Roman",120,0,0,1,0) junk=w32Func(xSelectObject,{MainWinDC,hFont}) oldMapMode = w32Func(xSetMapMode,{MainWinDC,MM_ANISOTROPIC}) Text = "Euman's Win32lib Demo's" pText = allocate_string(Text) if w32Func(xSetGraphicsMode,{MainWinDC, GM_ADVANCED}) then end if end procedure setHandler(MainWin, w32HOpen, routine_id("onOpen_MainWin")) -- onResize_MainWin procedure onResize_MainWin( integer self, integer event, object parms ) sequence CurExtent CurExtent = getClientRect( MainWin ) setPenColor( MainWin, White ) repaintRect( MainWin, CurExtent[1], CurExtent[2], CurExtent[3], CurExtent[4]) if w32Func(xSetWindowExtEx,{MainWinDC,InitExtent[3]-InitExtent[1],InitExtent[4]-InitExtent[2],0}) then if w32Func(xSetViewportExtEx,{MainWinDC,CurExtent[3]-CurExtent[1],CurExtent[4]-CurExtent[2],0}) then w32Proc(iEllipse,{MainWinDC, InitExtent[1], InitExtent[2], InitExtent[3], InitExtent[4]}) w32Proc(iDrawText,{MainWinDC, pText, -1, pInitExtent, or_all({DT_CENTER, DT_VCENTER, DT_SINGLELINE})}) end if end if end procedure setHandler(MainWin, w32HResize, routine_id("onResize_MainWin")) -- onPaint_MainWin procedure onPaint_MainWin( integer self, integer event, sequence parms ) object junk junk = w32Func( xInvalidateRect, {MainWin, NULL, 1} ) end procedure setHandler(MainWin, w32HPaint, routine_id("onPaint_MainWin")) -- onFocus_MainWin procedure onFocus_MainWin( integer self, integer event, sequence parms ) onResize_MainWin( 0,0,0) end procedure setHandler(MainWin, w32HGotFocus, routine_id("onFocus_MainWin")) -- onClose_MainWin procedure onClose_MainWin( integer self, integer event, sequence parms ) free(pText) free(pInitExtent) releaseDC ( MainWin ) end procedure setHandler(MainWin, w32HClose, routine_id("onClose_MainWin")) WinMain( MainWin, Normal )