
- •The ministry of education and science of ukraine kharkiv national university of radio electronics
- •1. The Basics of Microsoft Foundation Classes
- •Mfc general information
- •A Framework of mfc-program
- •Creating the Application Class
- •Creating the Frame-Window Class
- •Declaring a Message Map and instantiation of application object global instance
- •Defining a Message Map
- •Messages and their processing in mfc-programs
- •Writing Message Map Functions
- •Message boxes and menus in mfc-programs
- •2. Dialog windows
- •2.1 Modal and modeless dialog windows
- •2.2 The control elements of dialog window
- •CListBox::AddString (lpctstr lpszItem ); // Call this member function to add a string (lpszItem) to a list box;
- •3. Additional control elements in mfc-programs. Working with icons, cursors, raster images
- •3.1 Additional control elements
- •Radio buttons
- •Afx_msg void cWnd::OnVScroll( uint nSbCode, uint nPos, cScrollBar* pScrollBar ); afx_msg void cWnd::OnHScroll( uint nSbCode, uint nPos, cScrollBar* pScrollBar );
- •Afx_msg void OnVScroll( uint nSbCode, uint nPos, cScrollBar* pScrollBar );
- •Working with icons, cursors, raster images
- •The icons and cursor registration
- •Icon and cursor loading
- •4. The elements of text processing in mfc
- •The redrawing problem decision
- •5. The Elements of working with graphics
- •5.1 The graphics functions.
- •Working with brushes
- •5.2 The mapping modes and output regions
- •6. Common control elements
- •Windows Common Controls
- •6.2 The toolbar using
- •On resizing, the message wm_size is sent and the standard handler OnSize() is called.
- •The working with Spins
- •The working with slider
- •To set the range (minimum and maximum positions) for the slider in a slider control use the following function:
- •The working with progress bar
- •The tree control using in mfc programs
- •Adding elements to the tree
- •The status bars usage
- •Bool cStatusBarCtrl::SetParts( int nParts, int* pWidths );
- •Tab controls using in mfc-programs
- •Int cTabCtrl::GetCurSel(); To Selects a tab in a tab control use SetCurSel() function:
- •Int cTabCtrl::SetCurSel( int nItem );
- •The property sheets and wizards
- •7. Thread multitasking and it’s implementation in mfc
- •7.1 The basic features of multitasking
- •7.2 The Synchronization
- •7.3 The working with semaphore
- •7. 4 The working with event object
- •8. The concept of Document view
- •8.1 Introduction to document conception
- •The control of documents storing
- •8.2 The dynamic creation of objects
- •The application framework creation
- •The main window and application classes creation
- •Listing 8.1 The example of main window class in Document / View concept
- •Listing 8.2 The example of document class in Document / View concept
- •8.3 The document framework creation
- •8.4 The initiation of application
- •8.5 The standard id’s, used in Document / View concept
- •9. The special types of menu and their implementation in mfc
- •9.1 The description of special menu styles
- •The mechanism to make changes in menus
- •9.2 The dynamic and floating menus implementation
- •CMenu::CreatePopupMenu
- •The example programs to work with dynamic menus
- •10. The system of help
- •10.1 The basic information on help structures
- •The call of help
- •The file of help
- •The Help file creating
- •The example of rtf file
- •10.2 The Help system including to the mfc-program
- •Parameters:
- •Return Values: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
- •10.3 The handlers of help messages
- •The processing of help calls
- •Wm_commandhelp message processing
- •10.4 Wm_contextmenu message processing
- •11. Manipulating Device-Independent Bitmaps
- •11.1 The types of bitmap
- •11.2 The structures included to bitmap
- •Introducing the cDib Class
- •11.3 Programming the cDib Class
- •Loading a dib into Memory
- •Other cDib Member Functions
- •Creating ShowDib program
- •Modifying ShowDib's Resources
- •Adding Code to ShowDib
- •Examining the OnFileOpen() Function
- •Examining the OnDraw() Function
- •12. The elements of Database Programming
- •12.1 Understanding Database Concepts
- •Accessing a Database
- •12.2 Mfc odbc Classes
- •Registering the Database
- •Creating the Basic Employee Application
- •Creating the Database Display
- •Adding and Deleting Records
- •12.4 Sorting and Filtering
- •12.5 Odbc versus dao
- •13. Remote Automation
- •13.1 The introduction to Remote Automation
- •13.2 The Remote Automation Connection Manager and user components
- •13.3 Automation
- •Automation Clients
- •13.4 ActiveX
- •ActiveX Document Servers
- •ActiveX Document Containers
- •ActiveX Document Views
- •13.5 ActiveX Documents
- •ActiveX Controls
- •Interaction Between Controls with Windows and ActiveX Control Containers
- •13.6 Optimization of ActiveX Controls
- •13.7 Automation Servers
- •13.8 Connection Points
- •14. Microsoft DirectX and the main items of its using
- •14.2 The Component Object Model
- •IUnknown Interface
- •DirectX com Interfaces
- •DirectDraw Architecture
- •Other DirectDraw Features
- •Width and Pitch
- •14.5 Support for 3d Surfaces in DirectX
- •14.6 Direct3d Integration with DirectDraw
- •Direct3d Device Interface
- •Direct3d Texture Interface
- •The Basics of DirectDraw
- •Step 6: Writing to the Surface.The first half of the wm_timer message in ddex1 is devoted to writing to the back buffer, as shown in the following example:
- •Loading Bitmaps on the Back Buffer
- •Step 1: Creating the Palette. The ddex2 sample first loads the palette into a structure by using the following code:
- •Step 4: Flipping the Surfaces. Flipping surfaces in the ddex2 sample is essentially the same process as that in the first example. Blitting from an Off-Screen Surface
- •Step 1: Creating the Off-Screen Surfaces. The following code is added to the doInit function in ddex3 to create the two off-screen buffers:
- •Color Keys and Bitmap Animation
- •Dynamically Modifying Palettes
- •Optimizations and Customizations
- •Blitting with Color Fill
- •Determining the Capabilities of the Display Hardware
- •Storing Bitmaps in Display Memory
- •Triple Buffering
- •15. General information on OpenGl
- •15.1 Common information
- •Primitives and Commands
- •OpenGl Graphic Control
- •Execution Model
- •15.2 Basic OpenGl Operation
- •OpenGl Correctness Tips
- •15.3 OpenGl example program
- •Ph.D. Assosiate prof. Tsimbal Alexander m. System software, summary of lectures.
2.2 The control elements of dialog window
The list box usage in dialog window programs
List or ListBox is a one of control elements. It’s organized by CListBox class. Listbox can send and receive messages. Therefore, the messages are send to list on it’s initialization. When list is initialized, it’s receive messages on actions, produced by user.
The Listbox generates messages of different types. For example messages on double mouse click on list element, on losing of active state (on inactivity of listbox), on elment selection in the list. Every event is described by identifier code.
Following is a list of potential message-map entries and a description of the cases in which they would be sent to the parent:
ON_LBN_DBLCLK The user double-clicks a string in a list box. Only a list box that has the LBS_NOTIFY style will send this notification message.
ON_LBN_ERRSPACE The list box cannot allocate enough memory to meet the request.
ON_LBN_KILLFOCUS The list box is losing the input focus.
ON_LBN_SELCANCEL The current list-box selection is canceled. This message is only sent when a list box has the LBS_NOTIFY style.
ON_LBN_SELCHANGE The selection in the list box is about to change. This notification is not sent if the selection is changed by the CListBox::SetCurSel member function. This notification applies only to a list box that has the LBS_NOTIFY style. The LBN_SELCHANGE notification message is sent for a multiple-selection list box whenever the user presses an arrow key, even if the selection does not change.
ON_LBN_SETFOCUS The list box is receiving the input focus.
ON_WM_CHARTOITEM An owner-draw list box that has no strings receives a WM_CHAR message.
ON_WM_VKEYTOITEM A list box with the LBS_WANTKEYBOARDINPUT style receives a WM_KEYDOWN message.
To speak the truth, every macro has standard handle, so usually you have no need rewrite them. Generally macro has the following view (on example):
ON_LBN_DBLCLK(ID, HandlerName)
CListBox class has a number special function to work with information in the list:
CListBox::AddString (lpctstr lpszItem ); // Call this member function to add a string (lpszItem) to a list box;
CListBox::GetCurSel( ); // Retrieves the zero-based index of the currently selected item, if any, in a single-selection list box.
CListBox::GetText( int nIndex, LPTSTR lpszBuffer ); // Gets a string from a list box, there is nIndex - specifies the zero-based index of the string to be retrieved; lpszBuffer Points to the buffer that receives the string. The buffer must have sufficient space for the string and a terminating null character. The size of the string can be determined ahead of time by calling the GetTextLen member function.
Other functions: DeleteString() – deletes string from the list, FindString() – finds the string, SetCurSel() – set the selection cursor on the element, InsertString() – inserts the string at set index, GetCount() – returns the number of elements in the list. All of that functions belong to the CListBox class.
But there is the question, how to implement the function to the list. It’s need to receive the pointer to the list by GetDlgItem(), which returns the pointer on object, whose identifier is pointed out. If object isn’t exist function returns NULL.
The initialization of lists
Initially list is created as some empty element, it’s initialisated every time, when dialog window is displayed. To make that there is created its own version of OnInitDialog() function. Here is an example of dialog window initialization:
Listing 2.5 The Initialization of dialog window.
BOOL CSampleDialog::OnInitDialog()
{CDialog::OnInitDialog();
ll= (CListBox *)CWnd::GetDlgItem(IDC_LIST1);
ll->AddString("Apple!"); ll->AddString("Orange!");
return TRUE;}
There can be such question – what is the ll-variable. That variable is usually set in the dialog window class description: CListBox ll; (usually in private section of the class). After that, by GetDlgItem() function object ll is linked to identifier of resource (IDC_LIST1). The last strings are addition of text strings to our list (strings "Apple!", "Orange!").
The creation of Edit control
The CEdit class provides the functionality of a Windows edit control. An edit control is a rectangular child window in which the user can enter text.
You can create an edit control either from a dialog template or directly in your code. In both cases, first call the constructor CEdit to construct the CEdit object, then call the Create member function to create the Windows edit control and attach it to the CEdit object.
Construction can be a one-step process in a class derived from CEdit. Write a constructor for the derived class and call Create from within the constructor.
CEdit inherits significant functionality from CWnd. To set and retrieve text from a CEdit object, use the CWnd member functions SetWindowText and GetWindowText, which set or get the entire contents of an edit control, even if it is a multiline control. Also, if an edit control is multiline, get and set part of the control's text by calling the CEdit member functions GetLine, SetSel, GetSel, and ReplaceSel.
The initialization of edit control is provided in similar manner:
ed = (CEdit *)CWnd::GetDlgItem(IDC_EDIT1);
The next function makes interesting thing – the information collection from edit control ed (by GetWindowText() function to string str) to Listbox ll. Action is produced after OK button pressing in the dialog window.
Listing 2.6 The OnOK redefined handler.
void CSampleDialog::OnOK()
{char str[10];
ed->GetWindowText(str,sizeof(str));
ll->AddString(str);}
Listing 2.7 The program with list box and edit box using.
// d01.h: interface for the classes.
class CApp : public CWinApp
{public:
BOOL InitInstance();
};
class CSampleDialog : public CDialog
{public:
void OnClear();
void OnDelete();
void OnAdd();
BOOL OnInitDialog();
CSampleDialog(UINT id, CWnd *Owner) :
CDialog (id,Owner) {}
DECLARE_MESSAGE_MAP()
private:
CButton *bt_clear;
CButton *bt_delete;
CButton *bt_add;
CEdit *ed;
CListBox *lb;
};
// d01.cpp: implementation of the CApp class.
#include <afxwin.h>
#include <string.h>
#include "d01.h"
#include "resource.h"
BOOL CApp::InitInstance()
{CSampleDialog a(IDD_DIALOG1,m_pMainWnd);
a.DoModal();
return TRUE;
}
CApp App;
BEGIN_MESSAGE_MAP(CSampleDialog,CDialog)
ON_COMMAND(IDC_BUTTON1,OnAdd)
ON_COMMAND(IDC_BUTTON2,OnDelete)
ON_COMMAND(IDC_BUTTON3,OnClear)
END_MESSAGE_MAP()
BOOL CSampleDialog::OnInitDialog()
{CDialog::OnInitDialog();
lb=(CListBox*)GetDlgItem(IDC_LIST1);
ed=(CEdit*)GetDlgItem(IDC_EDIT1);
bt_add=(CButton*)GetDlgItem(IDC_BUTTON1);
bt_delete=(CButton*)GetDlgItem(IDC_BUTTON2);
bt_clear=(CButton*)GetDlgItem(IDC_BUTTON3);
return TRUE;
}
void CSampleDialog::OnAdd()
{char a[50];
ed->GetWindowText(a,sizeof(a));
int i=lb->GetCurSel();
if(strlen(a)==0)MessageBox("You've set empty string","Error");
else {if(i==LB_ERR)lb->AddString(a);
else lb->InsertString(i,a);}
}
void CSampleDialog::OnDelete()
{int i=lb->GetCurSel();
if(i==LB_ERR)MessageBox("You need string selection","Error");
if(i!=LB_ERR)lb->DeleteString(i);
}
void CSampleDialog::OnClear()
{int i=lb->GetCount();
for(int j=0;j<i+1;j++)lb->DeleteString(0);
}
Pic 2.1 The view of dialog window resource for program in Listing 2.7.