From: Dee Earley on 3 Mar 2010 08:42 On 03/03/2010 13:09, Norm Cook wrote: > "Mike Williams"<Mike(a)WhiskyAndCoke.com> wrote in message > news:uC9cUXruKHA.800(a)TK2MSFTNGP04.phx.gbl... >> "Webbiz"<nospam(a)noway.com> wrote in message >> news:dblro5tiqingfoajr3uthtkpmeriannhan(a)4ax.com... >>> On Tue, 2 Mar 2010 21:54:07 -0000, "Mike Williams" >> > > Mike, while we're discussing graphics, a slightly OT question > > oldPen = SelectObject(pic.hdc, pen1) > > For the above, I've seen it written > > DeleteObject SelectObject(pic.hdc, pen1) > > It alleviates the need for oldPen, but is it ok coding, resource wise? It depends, you normally need to select the old pen back in when you've finished. If it was one you have previously selected in and no longer need, then yes you can just delete it. You will normally see: oldPen = SelectObject(pic.hdc, NewPen) 'Draw stuff DeleteObject SelectObject(pic.hdc, oldPen) The last line may also be replaced with: SelectObject pic.hdc, oldPen DeleteObject newPen -- Dee Earley (dee.earley(a)icode.co.uk) i-Catcher Development Team iCode Systems
From: Nobody on 3 Mar 2010 08:52 "Norm Cook" <normcook(a)cableone.net> wrote in message news:e9X1OLtuKHA.4492(a)TK2MSFTNGP05.phx.gbl... > "Mike Williams" <Mike(a)WhiskyAndCoke.com> wrote in message > news:uC9cUXruKHA.800(a)TK2MSFTNGP04.phx.gbl... >> "Webbiz" <nospam(a)noway.com> wrote in message >> news:dblro5tiqingfoajr3uthtkpmeriannhan(a)4ax.com... >>> On Tue, 2 Mar 2010 21:54:07 -0000, "Mike Williams" >> > > Mike, while we're discussing graphics, a slightly OT question > > oldPen = SelectObject(pic.hdc, pen1) > > For the above, I've seen it written > > DeleteObject SelectObject(pic.hdc, pen1) > > It alleviates the need for oldPen, but is it ok coding, resource wise? The first line is okay if you need to reuse oldPen then delete it later. The second line is "okay" if you don't need oldPen, but if SelectObject() failed, the pen is not deleted and you get a resource leak.
From: Mike Williams on 3 Mar 2010 11:33 "Ivar" <ivar.ekstromer000(a)ntlworld.com> wrote in message news:%23ymQoRtuKHA.812(a)TK2MSFTNGP06.phx.gbl... > Just to add another point, I think DrawText would be > a better option than TextOut. I say this because of the > alignment parameter. If the point of the arrow or > whatever needs to be in a certain position then it can > be aligned to whatever edge of a RECT rather than > having a right or down pointing arrow always aligned > top left. At least, I think that's how it works, It's been > a while since I did any of this stuff. Yes. Good point (point . . gettit . . oh never mind . . it seemed funny at the time!). DrawText would in this case be better than TextOut. If you use the two flags DT_BOTTOM, DT_SINGLELINE together then the character cell will be aligned so that the bottom edge of the character cell (the botom of its "Descent" portion) aligns with the bottom edge of the specified rectangle. This is the approximate point where the bottom of characters such as "j" normally sit in most fonts, so if Webbiz made sure that the bottom of the arrow went right down to the that position when creating his font characters then he would be able to easily align the point of the arrow in the his desired vertical position when using DrawText to "print" the character without needing to bother checking the "black box" measurement of the character. If he also made sure when creating his font that the arrow character was horizontally aligned centrally within its cell then he would also be able to also use the DT_CENTE flag, which should make it very easy to position his arrow in the correct place. Mike
From: Mike Williams on 3 Mar 2010 11:47 "Norm Cook" <normcook(a)cableone.net> wrote in message news:e9X1OLtuKHA.4492(a)TK2MSFTNGP05.phx.gbl... > Mike, while we're discussing graphics, a slightly OT question > oldPen = SelectObject(pic.hdc, pen1) > For the above, I've seen it written > DeleteObject SelectObject(pic.hdc, pen1) > It alleviates the need for oldPen, but is it ok coding, > resource wise? If you're selecting pen1 into the DC and you want to immediately delete the pen that it previously contained (as is often the case when you are selecting the "old pen" back into the DC after selecting and using a pen you had created yourself) then I suppose it is okay, although as "Nobody" pointed out it can lead to problems if the call fails for some reason. Personally I just don't like it though, on the grounds that it lacks "readability". It's a bit like the call I used in the code I posted recently, in which I used something like: SetWindowOrgEx pic.hdc, p1.x, p1.y, p1 That was just laziness on my part, and it too lacks readability, so I'm not at all surprised that it caused some confusion :-) Mike
From: Webbiz on 3 Mar 2010 14:00 On Wed, 3 Mar 2010 12:49:59 -0000, "Mike Williams" <Mike(a)WhiskyAndCoke.com> wrote: >"Ivar" <ivar.ekstromer000(a)ntlworld.com> wrote in message >news:OBwSboquKHA.5936(a)TK2MSFTNGP04.phx.gbl... > >> Webbiz, Mike. I thought I might throw in an alternative here! >> Mike, you gave me this idea and a few pointer on doing this >> a few years ago . . Remember the card games? > >A few years ago, Ivar? Sheesh! At my age things I did even a few weeks ago >are hidden in the mists of time ;-) Curious. What age would that be, 'old' chap? ;-b > >Actually I'm just joking (well, sort of half joking!) and now that you have >reminded me I do remember your card game and my suggestion about the fonts, >although I don't remember the details. Your idea that Webbiz might like to >consider using fonts for his arrows seems like a good one, especially as I >seem to recall Webbiz having other little shapes he needs to draw from time >to time in his application. If that is the case then he could create a font >that contains his arrows and as many different shapes as he wishes, and he >can then set the text colour to whatever he wants and print them wherever he >wants in his PictureBox using a standard PicBox.Print or, better still, >using the equivalent GDI TextOut method. The Windows font rasterising stuff >seems to be pretty well optimized and TrueType characters are drawn quite >quickly, and that fact (coupled with the fact that Vista has severely >crippled the speed of the GDI Polygon function) means that your idea of >using fonts for WebBiz's arrows will probably be at least as fast, if not >faster . . . > Most of my app's drawing is in the way of lines. Lots of different kinds of lines. Any items that are shapes, such as candlesticks, must take their shape based on a price value so I wouldn't think would be a good candidate for a 'font' solution. As for the arrows, I only need two, both same size. One red, one blue. Actually, this little task is already finished and working nicely. I modified the POINTAPI variable values to the shape I wanted for both the UP and DN arrows and now simply run DrawDownArrow or DrawUpArrow with coordinates as needed. Nice, clean and fast. All done! Thanks for the suggestion though (Ivar, Mike). Webbiz
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Creating Reg-Free DLL situation Next: VB6 With/End With - how to pass the object itself? |