The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on July 23, 2008, 05:34:22 AM

Title: Creating picture box
Post by: Farabi on July 23, 2008, 05:34:22 AM
How to create a picture box using CreateWindowEx? And is it flicker free if I redraw into its DC?
Title: Re: Creating picture box
Post by: hutch-- on July 23, 2008, 09:25:32 AM
Farabi,

If you don't have to modify the image, use a static control with the SS_BITMAP style. Easiest way to do it.
Title: Re: Creating picture box
Post by: Farabi on July 23, 2008, 10:01:03 AM
Quote from: hutch-- on July 23, 2008, 09:25:32 AM
Farabi,

If you don't have to modify the image, use a static control with the SS_BITMAP style. Easiest way to do it.
No, I want to modify the image.
Title: Re: Creating picture box
Post by: MichaelW on July 23, 2008, 03:08:18 PM
By "picture box" I assume you mean something like a VB PictureBox control. What sort of image(s) does the control need to handle? A PictureBox control can expand to fit the image or clip the image to fit the control. I think with GDI+ you could do either, or resize the image to fit the control, or transform the image, or draw in the control, and handle a wider range of image types than a static control. There are some examples, in PowerBASIC syntax,  here (http://www.jose.it-berater.org/smfforum/index.php?PHPSESSID=1912dcf3693dac21fd8ae77a7ba59eae&topic=262.0).
Title: Re: Creating picture box
Post by: Farabi on July 24, 2008, 01:32:01 AM
Quote from: MichaelW on July 23, 2008, 03:08:18 PM
By "picture box" I assume you mean something like a VB PictureBox control. What sort of image(s) does the control need to handle? A PictureBox control can expand to fit the image or clip the image to fit the control. I think with GDI+ you could do either, or resize the image to fit the control, or transform the image, or draw in the control, and handle a wider range of image types than a static control. There are some examples, in PowerBASIC syntax,  here (http://www.jose.it-berater.org/smfforum/index.php?PHPSESSID=1912dcf3693dac21fd8ae77a7ba59eae&topic=262.0).
If I draw directly to the window DC, the button also the richedit picture is overwriten . Thats why I want to draw it to a picture box, so the button and the richedit picture can still exist.
Title: Re: Creating picture box
Post by: donkey on July 24, 2008, 02:36:03 AM
I used a custom control in TBPaint for the picture box (though in reality it is little more than a static control), early on it only handled the WM_PAINT message, sending the rest to the default static proc but over development it grew to quite a size handling all sorts of messages as well as routing all drawing functions. All you have to do is create a bitmap, modify it as you like then when the control receives a WM_PAINT message blt the bitmap into the control, just be sure to invalidate the control after drawing to the MemDC. Any overwriting of other children can be handled through clipping so that is not an issue. I found that using a backbuffer when drawing to the control kept it virtually flicker free and allowed me more flexibility when drawing since I was essentially drawing directly to memory then blting the result. Actually the memory DC that is used for drawing in TBPaint is permanent, always containing the current bitmap, the control is only used to display the results, all drawing is done directly to the memory DC not the control's DC.
Title: Re: Creating picture box
Post by: Farabi on July 24, 2008, 03:56:21 AM
Donkey:
Here is my project, its very complicated and mess up. I dont understand how to implement your answers. Please take a look at my code.

PS:
If one or more function on my project is usefull for you, dont hestitate to take it. Its all yours.

[attachment deleted by admin]
Title: Re: Creating picture box
Post by: Farabi on July 24, 2008, 03:56:59 AM
Take a look at "ButtonCheck" procedure, the bottom line is the blit function.
Title: Re: Creating picture box
Post by: donkey on July 24, 2008, 04:36:01 AM
Hi Farabi,

It's close to 11PM here so I won't have time to look it over tonight but I will try to take a look tomorrow aftter work. Thanks for the offer but I don't do very much with graphics right now, I am more interested in ODBC and SQL with assembly and all of my current projects revolve around that however I will archive it and if I ever need it I will give you a heads up.

Donkey
Title: Re: Creating picture box
Post by: hutch-- on July 24, 2008, 05:18:10 AM
Farabi,

If you want to modify the image, use a window and the API BitBlt, fast slick and reliable.
Title: Re: Creating picture box
Post by: Relvinian on July 24, 2008, 07:29:40 PM
This is some very old code (9-10 yrs ago) from a project of mine (the function calls to the system routines might not be the same as MASM32 but they are very close so little work is needed to change it).

This will draw any HBITMAP handle on the screen and should be flicker-free for your normal use.  Hope this old code will help you with what you are doing.

Relvinian


[attachment deleted by admin]
Title: Re: Creating picture box
Post by: Farabi on July 25, 2008, 03:44:58 AM
Quote from: Relvinian on July 24, 2008, 07:29:40 PM
This is some very old code (9-10 yrs ago) from a project of mine (the function calls to the system routines might not be the same as MASM32 but they are very close so little work is needed to change it).

This will draw any HBITMAP handle on the screen and should be flicker-free for your normal use.  Hope this old code will help you with what you are doing.

Relvinian


Hi, thanks for your code. Have you look into my code? My problem is, when I blit to the window DC the edit box and push button draw dissapear.
Title: Re: Creating picture box
Post by: Farabi on July 25, 2008, 03:52:16 AM
Quote from: hutch-- on July 24, 2008, 05:18:10 AM
Farabi,

If you want to modify the image, use a window and the API BitBlt, fast slick and reliable.
I already use it, But It overwrote the textbox and the push button. On delphi I can mix the GDI and the control button like this

(http://www.geocities.com/realvampire2006/Clipboard.jpg)
But I dont know how to do it on MASM.
Title: Re: Creating picture box
Post by: jj2007 on July 25, 2008, 09:00:11 AM
You might have a look at the regions functions, e.g. CreatePolygonRgn, then:

The PaintRgn function paints the specified region by using the brush currently selected into the device context.

Now, a brush can be simply a bitmap...
Title: Re: Creating picture box
Post by: Tedd on July 25, 2008, 11:47:34 AM
You need to paint the bitmap as 'background', then any buttons or other controls will be drawn on top and show nicely.

When processing WM_PAINT, just do the usual BeginPaint/EndPaint, and bitblt the image data within that.
To avoid flicker, you'll want to create a memory-dc and do all drawing onto that. Then it will actually be displayed on screen during the WM_PAINT. Also, you'll need to InvalidateRect to force repaints when the image changes.
Title: Re: Creating picture box
Post by: donkey on July 26, 2008, 02:53:44 AM
For the buttons you can use owner drawn buttons, here's an example from my website...



[attachment deleted by admin]