CDialog class problem ( MFC ).

Started by
5 comments, last by DXnut 17 years, 9 months ago
Is CDialog class can use with GDI? If I want to display graphics that use GDI in the "dialog window" that derived from class CDialog ,Can I do this ??? If I can use CDialog with GDI ,how can I do? Thank you very much...........
Advertisement
last i recall you can use WM_PAINT and WM_ERASEBKGND to draw stuff with GDI in a dialog, however, i'm not sure if BitBlt's will work or not. I don't know if this has changed over the years (in the old days you couldn't, but try it and find out), as I haven't messed with GDI drawing in dialogs for quite some time now and I have the tendencies to still do things "the old way," but an old hack (i.e. for splash dialogs that need to draw bitmaps) is to draw or place the bitmap in a child window, such as a static control or another window. so just override your OnPaint or OnEraseBkgnd and give some GDI drawing a go... it should work.
You can use GDI in every HWND (or CWnd derived), so it works without any problems in CDialog as well. Depending on your design you can do the drawing in OnPaint or OnEraseBkGnd. Simply override one of these two and use the CPaintDC (or CDC) you get passed.

Problems can arise if you try to use GDI inside a standard control like CEdit since you interfere with its default painting.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thank you very much.
And if I want to use GDI in other function that is not OnPaint or OnEraseBkGnd.
Can I do this????

Thanks.......
You can (in general) use the GDI in any place where you have access to the appropriate handles - namely, the window handle (HWND) and device context (HDC).

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Quote:Original post by _mito_
Thank you very much.
And if I want to use GDI in other function that is not OnPaint or OnEraseBkGnd.
Can I do this????

Thanks.......


Yes, you can use it whereever you want. As ApochPiQ said, all you need to access it is the HWND. From there you can get access to the HDC.

The default place is WM_PAINT/WM_ERASEBKGND though, so be aware, that things may not work that smoothly if you do painter from other places.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I have been using owner draw buttons for things like display a COLORREF. You can do a LOT with owner drawn controls. There are a lot of cool tutorials and samples at:

http://www.codeproject.com/

--------------------------Most of what I know came from Frank D. Luna's DirectX books

This topic is closed to new replies.

Advertisement