What's new for mfc developments? (Translation)

zhaozj2021-02-08  192

What's New for MFC DEVELOPERS? BY ANSON TSAO AND WALTER SULLIVAN Translation: According to Ya Yai (Kevin_kbh@21cn.com) [Translator: Because of the time relationship, 俺 I have omitted some details of some details, but I still have to point. Interested friends can continue. Everyone can reprint at will, but please do not modify any text in this article. If you can, please use the mail to notify you when you reprint. Thank you! Anything that wants to communicate with 俺 is welcome! 15:29 2002-1-8]

MFC and ATL have not been updated for three years. Under the powerful publicity of Microsoft.Net, the MFC and C developers were abandoned. However, don't worry - in the upcoming Visual Studio.NET, Visual C developers not only get a comprehensive and close new IDE developed with the server side, but also improved C compiler, MFC and ATL have also been new. Important features. There is a clear message that MFC is still on all Windows platforms, with many client programs, the best Framework. In this article, we will take you to overview these new features that can be used in your MFC program.

· Using new MFC DLL (MFC70.DLL), it is no longer compatible with MFC42.DLL, but your source program remains compatibility (message mapping is more secure, so certain code violations).

· MFC and ATL are more combined, some universal classes such as CString can be used by two libraries at the same time.

· Header files with new Platform SDK, support new UI features in 2K and XP, such as theme, Manifest Resources, Active Accessibility, and new general dialogs.

· Increases the class of many UI, including supporting DHTML dialogs, and supports the CIMAGE for extending Bitmap.

· New tool classes can be used in MFC and ATL, such as regular expressions, counters, and security.

· The MFC application has strongly supports Web Services. ATL Server Class Writer Web Services and applications.

· Use the new OLE DB characteristics to enable efficient access to the database, it is easy to be like this.

· STL is updated

Integrated MFC and ATL

Can you use CString in ATL or use ATL to implement COM objects in large MFC? Ha, now you can. There have been many tool classes in MFC 7.0 to share between ATL and MFC: CString, Cpoint, CRECT, CSIZE, and CIMAGE. Moreover, ATL can be used without MFC support. CString is completely rewritten, now based on template cstringt <>. It supports various character types (CHAR, WCHAR_T, TCHAR) and based on CRT. You can also manage memory allocation in CString. [Translator: such as typedef struct my_chr {unsigned int a; unsigned int b; unsigned int C;} my_chr;

CStringt my_str; ...】

MFC7.0 adds a new string class called cfixedstringt <>. Such a fixed length string provides a method of user-defined length that does not require additional memory before depleting internal spaces. CfixedStringT is used to efficiency when the stack-based variables or elements in the combined container. It significantly reduces the allocation based on the heap. [Translator: This is also confused, huh, huh, please correct it. It reads as follows: CFixedStringT's are very efficient when used as stack-based variables or as keys in associativecontainers, dramatically reducing the number of heap-based allocations] The following example creates an instance of the 1024-character:

// Allocating 1024 Character Internal Buffercfixedstringt string;

The new UI feature and upgrade MFC 7.0 provide DHTML dialog support, with a DHTML editor class, new graphics API (GDI ), updated the BitMap Support (CIMAGE), add a general dialog box package (CLINKCTRL), The update controls and dialogs support 2K and XP, enhance the ActiveX Control container and improve the type of message mapping. Let's take a look one by one.

The DHTML dialog and the DHTML editor class DHTML dialog box bring colorful HTML user interfaces to desktop applications. Now your desktop app has a fashionable graphical interface and a refreshing interactivity that a general web application is not available. MFC 7.0 provides CDHTMLDIALOG and CMULTIPAGEDHTMLDIALOG to support DHTML. The DHTML dialog box can display an HTML page from a resource file or any valid URL. If you have used ChtmlView, you know that the HTML element needs to be obtained through the IHTMLDocument2 object, and the HTML event is very painful. CDHTMLDialog greatly simplifies this interaction and uses a set of extended macros and DHTML event mappings similar to DDX. DDX_DHTML_ Macro and traditional DDX_ macro is used in the DODataExchange function. It allows you to get and set properties of various HTML elements. For example, DDX_DHTML_CHECKBOX Binds the value of the check box, ddx_dhtml_elementinnerhtml sets and gets an HTML of an element. Binding an HTML element to DDX requires a 'ID =' attribute of this element, just like the code below:

filename:
r EAD -only void CPropertiesDlg :: DoDataExchange (CDataExchange * pDX) {CDHtmlDialog :: DoDataExchange (pDX); // {{AFX_DATA_MAP (CPropertiesDlg) //}} AFX_DATA_MAP DDX_DHtml_ElementInnerText (pDX, _T ( "filename "), m_strFileName); DDX_DHtml_CheckBox (pDX, _T (" readonly "), m_nReadOnly);} to respond to HTML control events, you have to define a DHTML event map: BEGIN_DHTML_EVENT_MAP (CDHtmlExploreDlg) DHTML_EVENT_ONCLICK (_T (" browse "), Onbrowse) DHTML_EVENT_CLASS (DISPID_HTMLELEMENTEVENTS_ONMOUSEOVER, T ("HOTELEMENT"), ONMOUSEOVERELEMENT) END_DHTML_EVENT_MAP ()

These events map the style similar to MFC, including definition of declare_dhtml_event_map and definitions between begin_dhtml_event_map and end_dhtml_event_map. CMULTIPAGEDHTMLDIALOG is suitable for the dialog that is related to the orientation and property pages. It can load multiple pages in a dialog and use intrinsic event mapping response events. This new version also provides a DHTML editor for WySIWYG. This means that adjusting an HTML element in your program is not difficult to adjust a text control. Similar to MFC6.0 support for Rich Edit controls, MFC7.0 provides ChTMleditctrl, similar to document view class: ChtmleditView / Chtmleditdoc. But you still need to adjust the UI element, such as font, style, color, and more.

GDI GDI is a new graphics subsystem, providing a set of graphics API rendering 2D images, pictures, and text. It is the only API in .NET, but in C , it adds GDI's rendering capabilities. GDI can be obtained: stronger 2D drawing, Alpha channel support, universal coordinate conversion, floating point support, and gradient brush, Cardinal Splines, Scalable Regions, and new programming mode. GDI is released in the form of a C style, although a set of C classes will be packaged, but not supported by MFC but in .NET. Use GDI to use GDIPLUS.H and link GDIPLUS.LIB. This library must also be initialized before use. GDI is part of XP, if you want to use on 98, ME, NT4.0, and 2K, copy GDIPLUS.DLL to the appropriate directory. GDI uses different programming models with GDI. In GDI must pass into the pen or brush in each draw command. Graphic elements are not working with the pen; the outline border and fill are separated into different functions (such as DrawRectangle and FillRectangle). The following example shows a rectangle (3.5 inches × 4.4 inches). Using Namespace Gdiplus; Void CMYVIEW :: OnDraw (CDC * THEDC) {Graphics Graphics (* THEDC); PEN PEN (Color (128, 255, 0, 0), 2.0); // Alpha Value Set // RealWorld Units Graphics. SetPageUnit (Unitinch); // Floating Point Coordinates Graphics.drawRectangle (& Pen, Rectf (0.0F, 0.0F, 3.5F, 4.4F));}

Bitmap support for the long-awaited Bitmap used to manage Bitmap finally implemented this version. CIMAGE can read and store graphics documents in JPEG, GIF, BMP, and PNG format. But some functions are not supported by the old system (such as 95), and some functions are different in different OS. CIMAGE can be used in MFC and ATL. It also encapsulates the functionality of the DIB, and can operate the pixel point directly. Let's take a look at CImage:

· Alpha pixel points mixed and transparent and translucent effects

· PLGBLT can map a rectangle to a parallelism

· TransparentBLT can be transparent according to a specified color

· Maskblt can be mixed with two pictures to an output device

· CIMAGE :: GETDC can draw a bitmap directly.

Here is an example:

CIMAGE Image; Image.Load ("Test.gif"); cbitmap * pbitmap = cbitmap :: fromHandle (image.m_hbitmap);

CLINKCTRL General dialog box CLINKCTRL Packages the syslink control, you can easily place hyperlinks on Windows, but only in XP. It supports one or more hyperlinks, you can process NM_CLICK and NM_RETURN messages in ONNOTIFY to click on events.

For 2K and XP support all general controls, cchecklistbox, file processing, and printing are updated to support 2k and XP. The method of CWnd is also updated to support new features such as Layered Windows and Active Windows. ClistView supports tiling style in XP. MFC7.0 supports XP topics (themes). CWND now supports ACTIVE Accessibility. The new CPrintDialoGex updated the print dialog. Enhanced ActiveX containers MFC7.0 and ATL supports ActiveX-free ActiveX, and the container can be rewritten. Now MFC also enjoys the same container optimization as Visual Basic. Now you can rewrite ColecontrolSite to increase your own container behavior.

Type Safety Message Mapping MFC7.0 enhances the check of the return value of the message processing function. For example, if you return VOID in OK instead of LRESULT, the compiler will think is an error.

There should be a new tool for tools: Regular Expression Class, 64-bit Date Time Functions, Collect Template Class, Security Class, Packaging CryptoAPI Functions and Classes, Macro and Thread Pool Support for Counting. We will introduce later.

Regular Expression Class This template class is used for query and comparison of strings while supporting MBCS and Unicode. There are two templates classes: CATLREGEXP and CATLREMATCHCONTEXT. One will be given below: CATLREGEXP <> Re; // useing the default character traitre.parse ("ab.d"); CATLRematchContext mc; Re.match ("ABCD", & MC); // Returns True, Successful matchre. Match ("BBCD", & MC); // Returns False, NO Match

64-bit date Time Functions Your code may not have a millennium problem, but the standard C running library will go wrong from 19:14:07, 2038. The new 64-bit datetime function can stick to December 39, 3,000. CTIME, CTimeSpan and C runners are updated __INT64 data types, including ctimespan :: getDays64, ctimespan :: gettotalhours64, ctimespan :: gehouse64, ctimespan :: serialize64, ctime :: gettime64, and ctime :: serialize64; _ctime64, _wctime64, _ftime64, _futime64, _gmtime64, _localtime64, _time64, _utime64, _wutime64; _findfirst64, _wfindfirst64, _findnext64, _wfindnext64; and _stat64, and _wstat64.

ATL's Collection Class and Matrix ATL7.0 offers five new sets: Atlarray, Catllist, Catlmap, CRBMAP, and CRBMULTIMAP. They can better support non-standard data types. Use some classes that describe elemental quality, these class description elements are copied, moved, and more cleared. There is CautopTrelementTraits, Cautovectorptrelementtraits, CCOMQIPTRELEMENTTRAITS, CSTRINGELEMENTTRAITS, and more. These ATL set classes do not support serialization. Use them to specify element types and description elements: crbmap , cautoptr , CAUTOPTRELEMENTTRAITS >> A dictionary is defined, mapping CString to CMYObject automatic pointer. The element of CMYObject will automatically destroy when the set class is destroyed.

Safety class security classes package NT all security mechanisms. ATL7.0 packages:

· Access Control List (CACL)

· Any access control list (CDACL)

· System Access Control List ()

· SID Safety Identity (CSID)

· Access node (CaccessToken)

· Access node group (ctokengroups)

· Access Number License (CTOKENPRIVILEGES)

· Safety description (CSecurityDesc)

· CsecurityAttributes

· Some global functions

Unfortunately, ATL 7.0 does not provide advanced security models, you still need to know in-depth understanding of Win32 security mechanism.

The Cryptographic Cyptographic class wrapped Win32's CryptoAPI, providing encryption, decoding, hash, digital signature, and key management.

That's it! If you do not want to use C attributes, there are corresponding classes and macrosthat you can use instead. You should also be aware that setting counters to specific values ​​isgenerally safe without having to worry about thread synchronization, but performing calculationson the Counters, Such As Incrementing OR Decrementing, Requires The Use of Atomsuch AS InterlockedIncrement Or Synchronization Using Critical Sections.

Performance Counters uses performance tests in your program that requires three types of objects: Performance Monitoring Management Objects, Performance Objects, and Performance Tester. Below demonstrate how to define performance monitoring management objects:

[perfmon (name = "myapplication", register = true)] class cmyapplicationperfmon {};

You can then use a performance tester:

Void setCounter (ulong value) {if (g_pstatsObject) g_pstatsobject-> samplecounter = value;} Use them don't have to worry about thread synchronization, but the tester requires atomic operations, such as InterlocKedInCrement or Synchronization.

Thread pool MFC 7.0 thread pool is based on NT I / O Completion Port. CThreadPool is a template class that supports working threads. When a thread is working, your execution function of your working thread will be called. The query and execution of the working thread follow the principle of FIFO (first in the first out). Use the thread pool must be:

· Initialization once a thread

· Execute threads in the request queue one by one

· One thread destroyed one time

· Declare a requestType Typedef in the work thread class, it will be processed during execution

RequestType is an opaque type that cannot be greater than sizeof (Ulong_PTR) (ie, 32 bits on the x86 PC), so you don't use the instance of the class or a large original type (such as floating point). Here is an example:

class CMyWorker {public: typedef CMyData * RequestType; BOOL Initialize (void * initParam); void Execute (CMyData * request, void * initParam, OVERLAPPED * pOverlapped); void Terminate (void * initParam);};

Here's how to initialize and query a task in the thread pool:

CthreadPool threadpool; threadpool.initialize (); threadpool.queuerequest (new cmydata ()); threadpool.shutdown (1000L);

Web services, web applications, and NetWork class MFC7.0 support web services, write web services, and write web applications with ATL server classes. In the following paragraph, we will demonstrate how to access the web service and calling services. How to generate HTML and write it to ISTREAM, how to use the HTTP client and how to send mail with MFC.

To call the methods exposed by the Web Service, Simply Instantiate An Instance of The Proxy Class and Call ITS Methods, Just Like a Native C Class!

#include "myservice.h" ??? myService :: cmyservice service; hResult hr = service.mymethod (CCOMBSTR (L "a parameter");

Web services are supported in the MFC, and the web service is easy to access through firewalls, providing a real loose connection. Using a web service will not be more difficult than #import. Use the command line program Sproxy.exe to generate a C client code that accesses the web service. The generated Proxy class contains everything you need. Here is an example:

SPROXY /OOUT: MyService.h http: //myserver/myservice.dll? Handler = genmyServiceWSDL

When you call the web service, you will initialize this proxy class and call it directly, just like a normal C class: #include "myservice.h" ... myservice :: cmyservice service; hResult HR = Service.Mymethod CCOMBSTR (L "a parameter");

HTML Builder Chtmlgen Class and Template ChtmlGenBase <> supports this feature. Chtmlgen writes a complete HTML to iStream. Use it as long as you initialize it with an istream and call the appropriate method.

Chtmlgen out; out.initialize (astream); out.html (); out.head (); out.bitle ("test html"); out.Headend (); out.body (); out.a ("http : //www.microsoft.com "," Microsoft "); Out.BodyEnd (); out.htmlend ();

HTTP Customer CatlhttpClient is a lightweight HTTP customer class that can be requested and respond. It supports proxy and various validation (currently, support BASIC and NTLM). CatlhttpClient will issue a request synchronously, so it is best to place it in the multi-thread.

CatlhttpClient Client; Client.naviGate (_t (http://www.microsoft.com)); CSTRING ContentType; Client.getHeaderValue (_T ("Content-Type"), ContentTyPE; BYTE * PBODY = Client.getBody ();

CBASICAUTHOBJECT and CNTLMAUTHOBJECT support verification. Here is an example:

CNTLMAUTHOBJECT NTLMAUTH; Client.addAuthObject (_T ("ntlm"), & ntlmauth;

SMTP supports MIME encoding messages to support SMTP support to support you no other MAIL client support. CSMTPConnection directly connects an SMTP server and sends MIME encoded MAIL. CmimeMessage can add an attachment, raw data, and other MIME encoded messages to Mail. This example demonstrates how to construct the MIME message:

CmimeMessage Message; Message.SetSender (_T ("someone@microsoft.com"); message.addreceipient (receipient); message.setsubject (_t ("a test message")); message.addtext (_t ("this is a Test Message "); csmtpConnection Connection; connection.connect (somesmtpserver); connection.sendMessage (Message);

Efficient OLE DB database access [translator: This is much more easy than the previous programming. However, DB is always more complicated, and a short period of means there is no problem. Lazy is not translated :)]

Updated STL added hash_map, haveh_multimap, and have a new Hash-Table-Based extension class. They are similar to std :: map, std :: multimap and std :: set, but there is very different performance characteristics. Hash-Table-Based is much better than binary tree-based. Unlike MAP and SET, the Hash class is not ordered. The new version of STL also eliminates the famous multi-threaded problem of Basic_String. No resembling counter is used, and it has been strictly used. Finally, STL has better DLL support. It is no longer a local static data member. Conclusion Visual Studio .NET is a giant step forward for enhancing programmer productivity, and the Microsoft .NET initiative will likely change the programming landscape in the coming years. With this release of Visual C , MFC 7.0 has been updated to live in this new world of Web Services, while gaining better C standard compliance, full integration with ATL, and numerous enhancements to UI and utility classes. Best of all, these new features can be added to your existing MFC applications.

Summary MFC is better close to C standards, completely and ATL combinations, greatly enhanced in UI and tools. Best or these new features can be added to the existing code.

About the Author:

ANSON TSAO has 12 years of industry experience, engaged in large Windows and C development, recently joined Microsoft Visual C Libraries group.

Walter Sullivan has worked in Microsoft for 11 years, and all of his time is almost spent on the Visual C Product team. He now leads the work of Microsoft C Class Libraries program management.

About TranslatorJust A C Fans. :) Call ME Kamp. I Care Code Performance Before, and now Carethe Performance of a certain project as a.

转载请注明原文地址:https://www.9cbs.com/read-2831.html

New Post(0)