Posts

Showing posts with the label MFC

An editable MFC List Control

Image
A run-through on how to create a editable MFC List Control by making the CListCtrl editable. Visual Studio 2010 project downloadable from here . Much of the credit for this must go to Zafir Anjum on the Codeguru site for an article called "Editable subitems" from which this post borrows quite heavily.

Getting started with Windows GDI graphics applications in C++

Image
A guide to getting started with Windows graphics applications for the very first time. The Windows Graphics Device Interface (GDI) forms the basis of drawing lines and objects, and from this device contexts. I will not go into any detail about these concepts in this post. I just want to show a simple means of getting started with things like the drawing of lines and objects in Windows applications. There is nothing stopping you from reading further on the subject to increase your understanding.

Creating a Tabbed Dialog using MFC Property Sheets

Image
This post assumes that you are working on an existing MFC project and wish to add a tabbed dialog to your application. This example was created in Visual Studio 2008. Like most of the other postings here, there is not much in the way of extra bells and whistles, just a very simple example to get you started... VS2003 download available here . Create a Property Sheet: In the main menu, click Project -> Add Class -> MFC Class. Set the Class Name eg CImageSheet and set the Base Class to a CPropertySheet . Click Finish and OK: This will generate the "ImageSheet.h" header file and class definition. Create Property Pages: In the main menu, click Project -> Add Class -> MFC Class. Set the Class Name eg CImageDimensions and set the Base Class to a CPropertyPage : Repeat for as many other property pages as needed: Modify the Property Sheet class: Modify this class so that it contains additional includes for all the property pages you want to ...

Dynamically Created MFC Controls and their Notifications

Image
I was required to create a dialog application with dynamically created checkboxes (CButtons).  Given that selection of a certain hardware types in the software would result in completely different checkbox layouts.  In these situations, it is the software that has to automatically do the work normally done by using the Dialog Editor toolbox to insert static controls. This involves the following steps:

Simple Multithreading in C++ / MFC

Right now I am just starting with a very simple example - no fancy stuff - just a single thread to demonstrate a sequence that updates a counter 20 times per second.

'Blitting' a Bitmap Image to the Screen.

I recently needed to revisit this to create simple monochrome bitmaps representing the sets of nozzles turned off/on on a Xaar microarrayer printhead. Sample code here .  Essential steps are outlined in the following code [code language="cpp"] // 1. Create the uninitialized bitmap, that is compatible // with the the specified device context CPaintDC dc( this ); CBitmap bitmap; bitmap.CreateCompatibleBitmap( &dc, 20, 20 ); // 2. Create memory device context, that is compatible // with the specified device (dc in this case) CDC dcMem; dcMem.CreateCompatibleDC( &dc ); // 3. Obtain/create the bitmap and select into // the memory device context. CBrush brushblue( RGB( 0, 0, 255 ) ); CBrush brush( RGB( 0, 255, 255 ) ); CBitmap* pOldBitmap = dcMem.SelectObject( &bitmap ); dcMem.FillRect( CRect( 0, 0, 10, 10 ), &brushblue ); dcMem.FillRect( CRect( 10, 0, 20, 10 ), &brush ); dcMem.FillRect( CRect( 0, 10, 10, 20 ), &brush ); dcMem.FillRect( CRect(...

Creating Bitmap Files from Raw Pixel Data in C++

Image
Creating the byte array This post describes a means of taking data in the form of raw pixels containing RGB values as well as the image height, width and the number of bits per pixel (24 in this case) and converting this into a bitmap (BMP) file. Example Visual Studio 2010 project is downloadable from here: www.technical-recipes.com/Downloads/BitmapRawPixels.zip In this this post I originally described how I needed a means of representing binary array values (inkjet printhead nozzles turned ON/OFF) as a set of colored 'squares' or pixels, so that nozzles switched ON/OFF could be represented by two different colours - black or white. The bitmap width was always going to be 128, while the bitmap length ("SizeValue") was one of a set of discrete set of values in the range { 1000, 1250, 1251, 1350 }. For this example I did not have to worry about padding additional values

Maintaining Recent File Lists in MFC Applications

A simple application in Visual Studio 2003 that builds on the "MyPad" application provided by Jeff Prosise in Programming Windows with MFC. Alternatively you could probably create the same by running the AppWizard to create a standard view-based application, but making sure to uncheck the Document/View architecture box, as well as the ActiveX Controls box to avoid unnecessary code.

How to Create Resizable Dialogs in MFC

Image
Example 1: Using Paulo Messina's Code Project sample A minimalist use of the CResizeableDialog class as described by Paulo Messina at CodeProject .   Hope you find the following recipe useful. Visual Studio 2003 source code is downloadable from here . 1. Create a new MFC Project 2.  In the resource editor, add a simple edit control that will be used to demonstrate how this resizing works: 3. Download the CodeProject library to a location of your choice. 4. Add this downloaded project to the same dialog project you are working on.  To do this, right-click the topmost solution folder and select Add Existing Project: So that the extra project is added: 5. Right-click on the Dialog (or whatever you called your project)  folder and select "Set Project Dependencies", making sure ResizableLib is checked: 6. In the Dialog code make sure CDialog is replaced with CResizeableDialog at the following appropriate points. (i) In the Dialog class (header file) be su...

Finding Minimal Spanning Trees using Kruskal's Algorithm in MFC / C++ / Boost libraries

Image
Kruskal's algorithm is used to find the minimal spanning tree for a network with a set of weighted links. This might be a telecoms network, or the layout for planning pipes and cables, or one of many other applications.