C ++/SDK Interface Development Summary

Source: Internet
Author: User

C ++/SDK Interface Development Summary

For programmers who are not used to using MFC, writing interfaces should be a headache. We will not discuss the use of open-source interface libraries such as duilib. This article mainly describes the development of native interface functions of Windows, as a summary to help beginners.

1. Window

The layout is implemented by creating a resource window, and the interface is displayed by calling DialogBox and CreateDialog. DialogBox is a modal window, while CreateDialog is a non-modal window. The difference is briefly described as follows:

Modal window: when no parent window exists, call DialogBox to display the window. The system is stuck in DialogBox until the window is closed and the following code continues.

Non-modal window: After CreateDialog is called, the Code continues to be executed. If there is no parent window, run the code GetMessage TranslateMessage DispatchMessage. If the parent window exists, you only need to enter the message loop of the parent window, And the subwindow can also perform message loop Response.

2. Controls

There are many types of controls in Windows. Here I will briefly introduce the usage of several types of controls.

2.1. Tray Icon

 

/// File: yyicon. h // class: hpolicyicon // main function: Implement System Tray Icon settings // # pragma once # include
 
  
Class hpolicyicon {policyicondata h_nid; public: hpolicyicon (HWND hWnd, HICON hIcon, lpTitle, lptstr lpTips = NULL, int iTimeOut = 5 );~ Hpolicyicon (); BOOL Show (); BOOL Hide (); BOOL Message (LPCTSTR lpMsg, UINT niif_InfoWarningError); BOOL IsShow ();};
 
//// File: policyicon. cpp // class: hpolicyicon // main function: Implement System Tray Icon settings // # include "policyicon. h "# pragma comment (lib," Shell32.lib ") hpolicyicon: hpolicyicon (HWND hWnd, HICON hIcon, LPCTSTR lpTitle, LPCTSTR lpTips, int iTimeOut) {this-> h_nid.cbSize = sizeof (policyicondata); this-> h_nid.hWnd = hWnd; this-> h_nid.uID = GetTickCount () & 0 xFFFF; this-> h_nid.dwState = this-> h_nid.dwStateMask = 0; this-> h_nid.uCallbackMessage = WM_USER + 1; this-> condition = this-> h_nid.hIcon = hIcon; if (lpTips) lstrcpy (LPTSTR) this-> h_nid.szTip, lpTips); elselstrcpy (LPTSTR) this-> h_nid.szTip, lpTitle); lstrcpy (LPTSTR) this-> h_nid.szInfoTitle, lpTitle); this-> h_nid.uTimeout = iTimeOut;} hpolicyicon ::~ Hpolicyicon () {if (this-> IsShow () this-> Hide ();} BOOL hpolicyicon: Show () {this-> h_nid.uFlags = NIF_ICON | NIF_INFO | NIF_MESSAGE; BOOL bRet = (BOOL) shell_policyicon (NIM_ADD, & this-> h_nid); this-> h_nid.uFlags = NIF_INFO; this-> delimiter = NIIF_INFO; return bRet;} BOOL hpolicyicon :: hide () {this-> h_nid.uFlags = NULL; return (BOOL) shell_policyicon (NIM_DELETE, & this-> h_nid);} BOOL hpolicyicon: Message (LPCTSTR lpMsg, UINT messages) {this-> response = niif_InfoWarningError; lstrcpy (this-> h_nid.szInfo, lpMsg); return (BOOL) shell_policyicon (NIM_MODIFY, & this-> h_nid);} BOOL hpolicyicon :: isShow () {return (BOOL) this-> h_nid.uFlags ;}

 

The implementation is very simple. Similar to MFC, it encapsulates functions such as display, hiding, and sending bubble notifications. You need to create an object when using it, and simply call it a few times.

2.2. ListView/ListCtrl

 

// Style DWORD dwStyle = ignore (hList); dwStyle | = LVS_EX_FULLROWSELECT; // select the whole line dwStyle | = LVS_EX_CHECKBOXES; // check box ListView_SetExtendedListViewStyle (hList, dwStyle ); // Add the header LV_COLUMN lc; lc. mask = LVCF_TEXT | LVCF_WIDTH; lc. cchTextMax = MAX_PATH; lc. cx = 100; lc. pszText = TEXT ("column 1"); ListView_InsertColumn (hList, 0, & lc); lc. cx = 100; lc. pszText = TEXT ("column 2"); ListView_InsertColumn (hList, 1, & Lc );...... // Add the row LVITEM li; li. mask = LVIF_TEXT; li. cchTextMax = MAX_PATH; li. iSubItem = 0; li. iItem = 0; // The number of rows inserted, starting from 0. pszText = TEXT ("column 1"); ListView_InsertItem (hList, & li); ListView_SetItemText (hList, li. iItem, 1, TEXT ("column 2 "));...... Li. iItem = 1; li. pszText = TEXT ("column 1"); ListView_InsertItem (hList, & li); ListView_SetItemText (hList, li. iItem, 1, TEXT ("column 2 "));............
ListView/ListCtrl is much easier to use. For a large number of functions starting with ListView _, you can choose.

 

2.3. TabCtrl, the so-called paging Control

In two steps, the first step is initialization.

 

#include 
 
  hwndTab = GetDlgItem();hwndChild[0] = CreateDialog();hwndChild[1] = CreateDialog();TCITEM ti = { 0 };ti.mask = TCIF_TEXT;ti.cchTextMax = MAX_PATH;ti.pszText = TEXT("tab1");TabCtrl_InsertItem(hwndTab, 0, &ti);ti.pszText = TEXT("tab2");TabCtrl_InsertItem(hwndTab, 1, &ti);
 
Step 2: process the WM_NOTIFY message
Case WM_NOTIFY: if (LOWORD (wParam) = IDC_TAB_MAIN) & (LPNMHDR) lParam)-> code = TCN_SELCHANGE )) {for (int I = 0; I
 
  
Simple and Convenient. 2.4 taskbar progress bar
  

 

This implementation is quite troublesome. I put it on the cloud disk. I need to download two packages here. The components can be used directly. The source code can be used to see the implementation method. In addition, do not try XP or Vista, and the system does not have this interface. 2.5. Other common Windows controls

Write a line of code:

 

#include 
   
Click in, and all other items will be available, such as RadioButton and CheckBox. Not all are available. The SDK interface development is waiting for your exploration.
3. C ++/SDK calls Gdiplus
With the standard controls, can't there be no plotting? GDI is too scum, complicated, and complex. It does not support png and sawtooth. Here I will briefly talk about how to reference Gdiplus.

 

First, there are few header files and libraries, and the namespace can be left blank.

 

#include 
   
    #pragma comment(lib, "gdiplus.lib")using namespace Gdiplus;
   
Then, the following code begins with WinMain.

 

 

ULONG_PTR gdiplusToken;GdiplusStartupInput gdiplusStartupInput;GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Finally, the following code throws on WinMain before returning
GdiplusShutdown(gdiplusToken);
The introduction is similar. Win32 is profound and profound. If you have any omissions, please correct them.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.