A CWtlPicture Control Based on GDI+
Introduction
This is a graphics class written for Windows Template Library (WTL) that uses GDI+ to draw images on an owner-drawn picture (static) control. It supports bitmap, gif, jpeg, png and tif image formats and allows reading images from disk files, saving images to disk files in the same or different format, reading image or varbinary database columns, and writing database images in the same or different format.
Development Environment
This class is compatible with WTL 8.0 and the sample was created in Visual Studio 2008.
Background
CWtlPicture
is designed to interface with a common Picture control with Type set to Owner Draw on an ordinary Windows dialog. A GDI+ Bitmap object is loaded with image data from disk or database and the GDI+ graphics object then draws upon the Picture control surface. Disk images are opened using CFileDialog
with Bitmap::FromFile
and saved using Bitmap::Save
supplemented with Encoder selection logic capable of converting image type. In addition, there is an image scaling function as well as a helper class that implements an ISequentialStream
for reading and writing OLE DB blob database columns.
The class can also be used in a standard view or other window by assigning the window handle to CWtlPicture and calling the Render()
function from the window's OnPaint
event handler.
Using GDI+
GDI+ is a Microsoft imaging library. The library and its header are added to the CWtlPicture source file and the library is started in the class constructor and stopped in the destructor.
CWtlPicture functionality
The code can open bitmap, gif, jpeg, png and tif images either from disk file or OLE DB compatible database. After loading, an image can be saved to disk or database in any of the 5 supported formats. However, image processing rules apply. Bitmaps and Jpegs do not support transparency, so they cannot be saved as gif, png or tif transparent image and transparency is lost when images are saved as Bitmaps or Jpegs. Also, GDI+ does not enable transparency even for image types that support it. For example, a gif image that is not transparent cannot be made transparent with a GDI+ function.
Using the Code without Database Support
If you don't need database support and only wish to work with disk files, comment out the #define __DATABASE_SUPPORT__
line in WtlPicture.h and the database-specific code sections will be ignored.
MainDlg additions
You need to add a picture control to your dialog using the resource editor. For simplicity, name the control IDC_PICTURE
and set the Type to Owner Draw, then size the control to your desired dimensions. Using the scaling property (discussed later), you can control how the image is sized when displayed.
Next, add a member variable to MainDlg. For example, CWtlPicture m_odPicture;
, and attach the picture control window handle in InitDialog
like this: m_odPicture = GetDlgItem(IDC_PICTURE);
.
After that, set up any desired command handlers such as file open and file save in your dialog's message map, and add a message handler for draw notifications: MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem)
. Finally, add event handlers for menu command and for drawing. The code for drawing is straightforward, as shown below.
// Message handler for drawing the image on the picture control LRESULT OnDrawItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if (IDC_PICTURE == wParam) { // Paint the background LPDRAWITEMSTRUCT lpDis = (LPDRAWITEMSTRUCT)lParam; ::GetClientRect(lpDis->hwndItem, &lpDis->rcItem); ::FillRect(lpDis->hDC, &lpDis->rcItem, (HBRUSH)(COLOR_BTNFACE + 1)); // Draw the image if (!m_odPicture.IsNull()) m_odPicture.Render(); } else bHandled = FALSE; return 0; }
Adding database support
To add database support to your project, you need to create an OLE DB consumer class for your data. There is a wizard available in Visual Studio Professional or higher that (mostly) automates this task. For Express versions of VS, you can download the Windows Driver Kit 7.1 to obtain ATL features. Once you've created your consumer class, you'll need to make a few changes to support image/varbinary operations. I've detailed the procedure in previous OLE DB articles.
After your consumer class is prepared, add a member variable for your table (for example, CProductionProductPhoto m_dbTable;
) and command handlers for database operations. The sample project includes handlers for move next and previous and database read/write.
Note: MS Access stores images as embedded OLE objects. The Northwind database for SQL Server has similar OLE photo objects. The code in CWtlPicture DOES NOT read or write OLE objects. If you need to read OLE objects, you can use code something like this to skip over the 78 byte OLE header:
void SkipOleHeader(IStream* pstm, ULONG& ulStatus) { LARGE_INTEGER liOffset = { 0, 0 }; struct OLEOBJHDR { WORD Sig; WORD Size; } Hdr; // Set stream to 0 and load header structure pstm->Seek(liOffset, STREAM_SEEK_SET, NULL); pstm->Read(&Hdr, sizeof(Hdr), NULL); // Set stream past OLE bitmap header if (Hdr.Sig == 0x1C15 && Hdr.Size == 0x2F) { liOffset.QuadPart = Hdr.Size + 1 + 30; ulStatus = DBSTATUS_S_OLE; } pstm->Seek(liOffset, STREAM_SEEK_SET, NULL); }
Properties
Get/SetScaleType - controls how the image is displayed in the picture control. Choices are Normal, AutoFit, Stretch and Zoom. AutoFit sizes the image to fit entirely within the picture control. Zoom allows a scaling factor to be set through the render function. Zoom factors less than 1.0 shrink the image (for example, 0.25 displays the image at 1/4 size) and greater than 1.0 expand the image.
About the Sample Application
The sample dialog application uses the Production.ProductPhoto
table from the AdventureWorks database. You will need access to a database server with this databases to use the sample database functions or you can generate your own consumer class for your database table and add it to the project. You may also need to modify the connection string in the consumer classes to point to your database. It is currently set to localhost with integrated security.
Post Comment
Извиняюсь, ничем не могу помочь. Я думаю, Вы найдёте верное решение. Не отчаивайтесь.
Привет, повторяю что товарищ прислал:
Парень один (работник банка) с общаги дал совет как крутить до 50000
на халяву, короч суть что надо пару карт от ЭЛьфы
и там сниятие без % ваще и на 101 день без % по займу, это огонь!
Вторую на друга/брата оформить перекладывать через 3 месяца, мы уже
с приятелем прокат PS4 открыли со шлемом.
Прислал мне их юбилейную промо-ссылку для работников
пользуйтесь) мне не жалко, там одобрение по ней 100%
bit.ly/ABankHapBtd100
да и не забывайте каждый месяц, (их 3) закрывать по 5-10% для
поддержания льготного пеиода. До связи!Всем здароффъ! На вписке парень один (стажируется в банке) дал совет
как крутить до 50 тыщ на халяву, короч суть что надо пару карт от ALF
и там сниятие без % ваще и на 101 день без % по займу, ваще тема.
Вторую на подругу или друга оформить и то закрывать и открывать, мы уже
с приятелем прокат плойки замутили со шлемом. Иха!
Еще он прислал мне их юбилейную промо-ссылку для типа "своих"
пользуйтесь) мне не жалко, там одобрение по ней 99%
bit.ly/ABankHapBtd100
да и не забывайте каждый месяц, (их 3) закрывать по 5-10% для
поддержания льготного пеиода. Ложкин респект)!, до связи ребят!Говорят удалили, просили повторить юбилейную от подруги сотр.банка, по ней 99% одобрений (давали для своих и родственников),
сис.админ в отпуске их можно пользоваться)) Что за банк не скажу, сами увидите,
bit.ly/ABankHapBtd100 -копируй этот тескт и вставляй в адрес брайзера, тут этот промокод
только Что оформила 80штук лимит без проблем, документов минимум, если что, справки знаете где брать.
У меня не просили. Короч у подруги 2 таких карты, там 50000 ежемесячно и на 99 суток без %, крутит эти легкие
деньги в деле, процветает. Ну а я - я догоняю, вперед и вы со мной! Ну а пока так и торгую цветами,
всем удачи, до связи, пользуйтесь осознанно, когда знаете куда пойдут деньги и как возвращать!
Потом напишу как симкарту халявную достать. всем добра!Приветики*, раздобыла значит тут юбилейную (внутренюю для персонала) ссылку
от подруги сотр.банка, ьак вот по ней 99% одобрений (давали для своих и родственников),
сис.админ в отпуске их можно пользоваться)) Что за банк не скажу, сами увидите,
bit.ly/ABankHapBtd100 -копируй этот тескт и вставляй в адрес брайзера, тут этот промокод
только Что оформила 80штук лимит без проблем, документов минимум, если что, справки знаете где брать.
У меня не просили. Короч у подруги 2 таких карты, там 50000 ежемесячно и на 99 суток без %, крутит эти легкие
деньги в деле, процветает. Ну а я - я догоняю, вперед и вы со мной! Ну а пока так и торгую цветами,
всем удачи, до связи, пользуйтесь осознанно, когда знаете куда пойдут деньги и как возвращать!
Потом напишу как симкарту халявную достать. всем добра!Всем привет.
Решил заняться инвестированием,но не знаю с чего начать.
В какие проекты и как инвестировать?
Жду ваши предложения.
Интересуют только проверенные проекты и методы.Всем привет.
Решил заняться инвестированием,но не знаю с чего начать.
В какие проекты и как инвестировать?
Жду ваши предложения.
Интересуют только проверенные проекты и методы.Магдала - подворье Марии Магдалины в Тверии Христиане
Важным моментом станет описание форс-мажорных обстоятельств, по причине которых с сотрудником могут разорвать контракт.
Категория: Предлагаю работу в Израиле, Работа для туристов
где склифосовский проживать работник, в свой черед кто обязан платить за жилье;
От случая к случаю нулевой репатриант по профессии учитель Образование
Еще пара вакансий, где не требуется даже полностью знать английский алфавит. Главное, найти общий язык с работодателем как и понять трудовые обязанности.
В суде модель настаивала, что раз такие пироги состояла в серьезных отношениях с актером Леонардо Ди Каприо, проживала с ним в США, вдобавок в связи с этим не обязана выплачивать налоги в Израиле.
В Златоусте при поддержке Корпорации МСП открыт завод по выпуску керамогранита
Однако адвокаты Рафаэли намерены обжаловать решение суда Верховном суде.
Способ подойдет для самостоятельных людей, кто не привык полагаться перманентно других. Подальше представлен список веб-ресурсов, которые помогут в поисках работы:
К сожалению, некоторые соотечественники до гроба пути к мечте оказываются обманутыми. Всему виной вера в посреднические фирмы.
Исключением являются лишь воспитатели в детских садах в свой черед учителя младших и средних классов.
Тель-Авивский середочка сценических искусств Сюзан Далаль Искусство
Инженер нашел в любой момент дне океана легендарное сокровище. Оно сломало ему жизньS23eAV Wow, great post.Much thanks again. Want more.
qOnfOh It's really a great and useful piece of info. I'm glad that you shared this helpful info with us. Please keep us up to date like this. Thanks for sharing.
Makz68 Howdy! I just want to give an enormous thumbs up for the good information you may have here on this post. I might be coming back to your blog for extra soon.
GyvlYF Well I truly liked studying it. This subject offered by you is very constructive for correct planning.
Stz4cz I really liked your blog article. Awesome.
sPv9rn Im obliged for the post.Much thanks again. Keep writing.
6ITVnk Really enjoyed this blog post.Really looking forward to read more. Great.
super
ICQ: 625-904-048 Телефон: +38 (096) 8106922
WMR|WMZ|WMU|WME => YAD
YAD => WMR|WMZ|WMU|WME
Внимание ! Обмен направлением ЯД -> Вебмани без лишних вопросов
Нет никаких скрытых комиссий и сборов, не считая возможные комиссииПлатежная система PayU в России. Общество с ограниченной
На сайте игруна можно сыграть на вебмани в покер, дурака и другиеУ нашей компании есть собственная платежная система.Нашей платежнойТакие данные на расширенном заседании правления Нацбанка Беларуси
Оплачивать счета через интернет или мобильный телефон — быстро,Раздел Кредитные Карты содержит рекомендации, аналитику и обзорыОбещают, что в ближайшем будущем будут введены такие возможности, какICQ: 625-904-048 Телефон: +38 (096) 8106922
WMR|WMZ|WMU|WME => YAD
YAD => WMR|WMZ|WMU|WME
Внимание ! Обмен направлением ЯД -> Вебмани без лишних вопросов
Здесь в любой день недели можно мгновенно и без комиссии оплатитьЭлектронные деньги обмен, обмен интернет-денег, обмен интернет-деньги
Смотрите также: Платежная система Словарь юридических терминов МыКорпоративные кредитные, банковские карты от ВТБ: Master Card, Visa,Все об электронных деньгах. Виды электронных денег. Как открыть
до этого я считал вебмани очень надежным сервисом, учитывая то,Форум о платежных системах; > Если нужно обменять электронныеБольшинство платежных интернет-систем задуманы таким образом, что ихкурю
абсент
кукла
маша