For programmers who are not accustomed to using MFC, the writing interface should be a headache. Call Duilib and other open source interface library is not discussed, this article mainly talk about the Windows native Interface feature development, as a summary, to help beginners get started.
1. Windows
Mainly through the new Resource window to implement the layout, call through DialogBox and Createdialog implementation interface display. Where DialogBox is modal window, createdialog is a non-modal window, briefly speaking the difference:
Modal window: When there is no parent window, call DialogBox to implement the display window. The system is stuck here in dialogbox until the window closes and continues with the following code.
Non-modal window: After calling Createdialog, the code continues to execute down. If there is no parent window, execute the GetMessage translatemessage dispatchmessage code, and if there is a parent window, you only need to enter the parent window's message loop, and the child window can also make a message loop response.
2. Controls
There are a wide variety of controls under Windows, and here I briefly describe several uses
2.1. Tray icon
////file: Notifyicon.h Class: hnotifyicon//Main function: Implement system tray icon setting//#pragma once#include <shellapi.h>class hnotifyicon {notifyicondata h_nid; Public:hnotifyicon (HWND hwnd, Hicon Hicon, LPCTSTR lptitle, lpctstr lptips = NULL, int itimeout = 5); ~hnotifyicon (); BOOL Show (); BOOL Hide (); BOOL Message (LPCTSTR lpmsg, UINT niif_infowarningerror); BOOL isshow ();};
File: notifyicon.cpp//class: hnotifyicon//main function: Implement system tray icon Setting//#include "notifyicon.h" #pragma comment (lib, "Shell32.lib") Hnotifyicon::hnotifyicon (HWND hwnd, Hicon Hicon, LPCTSTR lptitle, LPCTSTR lptips, int itimeout) {this->h_nid.cbsize = sizeof (notifyicondata); This->h_nid.hwnd = Hwnd;this->h_nid.uid = GetTickCount () &0xffff;this->h_ Nid.dwstate = This->h_nid.dwstatemask = 0;this->h_nid.ucallbackmessage = Wm_user+1;this->h_nid.hballoonicon = 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;} Hnotifyicon::~hnotifyicon () {if (This->isshow ()) this->hide ();} BOOL hnotifyicon::show () {this->h_nid.uflags = nif_icon| nif_info| Nif_message; BOOL BRet = (bool) Shell_NotifyIcon (Nim_add, &this->h_nid); this->h_nid.uflags = Nif_info;this->h_ Nid.dwinfoflags = Niif_info;return BRet;} BOOL hnotifyicon::hide () {this->h_nid.uflags = Null;return (BOOL) Shell_NotifyIcon (Nim_delete, &this->h_nid) ;} BOOL hnotifyicon::message (LPCTSTR lpmsg, UINT niif_infowarningerror) {this->h_nid.dwinfoflags = Niif_ infowarningerror;lstrcpy (This->h_nid.szinfo, lpmsg); return (BOOL) Shell_NotifyIcon (nim_modify, &this->h_ NID);} BOOL Hnotifyicon::isshow () {return (BOOL) this->h_nid.uflags;}
Implementation is very simple, and MFC similar to display, hide, send bubble notification and other functions are encapsulated, need to use a direct new object out, simple call a few down.
2.2, Listview/listctrl
Style DWORD dwstyle = Listview_getextendedlistviewstyle (hlist);d wstyle |= lvs_ex_fullrowselect;//Select entire row dwStyle |= LVS_EX_ checkboxes;//check box Listview_setextendedlistviewstyle (Hlist, dwstyle);//Add 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 row Lvitem li;li.mask = Lvif_text;li.cchtextmax = Max_path;li.isubitem = 0; Li.iitem = 0;//Inserts the first few lines, starting with 0 Li.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 the use of more convenient, a large number of listview_ start function, any choice.
2.3, Tabctrl, the so-called paging control
In two steps, the first step is to initialize
#include <commctrl.h>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 two, process wm_notify messages
Case Wm_notify:if ((LoWord (wParam) = = Idc_tab_main) && ((((LPNMHDR) lParam)->code = = Tcn_selchange)) {for ( int i=0; i<n; i++) ShowWindow (Hwndchild[i], sw_hide); ShowWindow (Hwndchild[tabctrl_getcursel (Hwndtab)], sw_show);} Break
Simple and convenient.
2.4. Taskbar progress bar
This implementation is more troublesome, I put in the cloud disk, need to click this download
There are two compressed packages, components can be directly used, the source code can see the implementation method. In addition, XP and Vista do not try, the system does not have this interface.
2.5. Other Windows common controls
Write a line of code:
#include <windowsx.h>
Then go in, and all the others have, such as RadioButton, checkboxes and so on. Does not mean that all are there, SDK interface development awaits your excavation.
3. C++/SDK Call Gdiplus
With standard controls, you can't have a drawing? GDI is too slag, cumbersome and complex, and does not support PNG or aliasing. I'm here to briefly talk about how to quote gdiplus.
First, the header files and libraries are few, namespaces can not be referenced, see personal interests
#include <Gdiplus.h> #pragma comment (lib, "Gdiplus.lib") using namespace Gdiplus;
Then, the following code domineering into the beginning of WinMain
ULONG_PTR Gdiplustoken; Gdiplusstartupinput Gdiplusstartupinput; Gdiplusstartup (&gdiplustoken, &gdiplusstartupinput, NULL);
Finally, the following code domineering into the WinMain before returning
Gdiplusshutdown (Gdiplustoken);
It's about the same. Win32 and profound, if there are omissions, welcome to correct.
C++/SDK Interface Development Summary