duilib duilib Concise Guide to Getting Started tutorial section 11. bug

A, WindowImplBase the bug in the first eight tutorials [2013 duilib Concise Guide to Getting Started - complete painting from the title bar (8)] , you can maximize the window there are two problems found after
    1, the maximize button style or not change   , correct style should be like   
    2, click the maximize button again, you can not restore to normal size.
    This is WindowImplBase a bug, has been submitted to the official for some time, but seemingly not been merged into SVN up, so explain here,
we need to WindowImplBase of OnSysCommand function, in the if (:: IsZoomed (* this) ! = bZoomed) inside with the following code:

  1. if( ::IsZoomed(*this) != bZoomed )
  2. {
  3. CControlUI * pbtnMax = static_cast <CControlUI *> (m_PaintManager.FindControl (_T ( "maxbtn"))); // Maximize button
  4. CControlUI * pbtnRestore = static_cast <CControlUI *> (m_PaintManager.FindControl (_T ( "restorebtn"))); // Restore button
  5. // switch the maximize button and restore the state of the button
  6. if (pbtnMax && pbtnRestore)
  7. {
  8. pbtnMax-> SetVisible (TRUE == bZoomed); // expression used here to avoid compiler warnings conversion BOOL
  9. pbtnRestore->SetVisible(FALSE == bZoomed);
  10. }
  11. }
Copy the code




Two, CDuiString the bug (review a bit Effective C ++, which is found in clause 24 of the issues identified, it appears that reading a hundred times better to write the code again ah)
    have a lot of if statements when processing messages Notify, I usually like to constants : double equal sign on the front, on the back variable, such as
    if (_T ( "the Click") == msg.sType)
    {
    }
    However found into this if not, the debugger found, the constant to the front , and does not enter the overloaded == CDuiString function inside, so there must be a constant bit later.


    IF (msg.sType == _T ( "the Click"))
    {
    }

    The reason is because when the bug in front of the constant, and does not call CDuiString overloaded == function, but CDuiString overloaded call () function, and then use the system comes == compare function, and the system their first address == function simply comparing two pointers are equal. _T ( "click") the first address points to a temporary variable and return a pointer CDuiString msg.sType inside that string, it is clear that the two pointer addresses are not equal, so we can only put it in front of or directly call _tcscmp
    IF (! _tcscmp (_T ( "the Click"), msg.sType))
    {
    }




    course, to solve this bug, the plurality of reload will == operator,
    Since CDuiString is == function as a member of function overloading, so only CDuiString object when the operation left character, will call the overloaded function, if you want to CDuiString object when the right could call overloaded == function, then the operator must reload to the outside. Here we can look at how the MFC CString is overloaded:
 
    CString override 5 == operator, friend functions are defined in #include inside.
    Look at the STL std String :::
 
    std :: String override operator == 3, are global function defined in #include inside.

 
  But need to be reminded that I looked a little under CDuiString code, there are a lot of loopholes, such as when a string is cleared, just call the m_szBuffer [0] = ''; not calling memset, then there will be less problems, we now arbitrarily use two ways to attach CDuiString value, and then monitor the content of the string array, may be found that although the display is correct, but behind all zero distortion value:
 

 

    this is the case, although _tcslen, _tcscmp other functions can be used, but there are many functions will go wrong.
    So this CDuiString can not do it, if too large MFC generated exe volume, you can use CString WTL, if do not want to use WTL, it had to use the STL's string.
    Of course, in order to ensure compatibility of the code, the processing or use some simple CDuiString better, such msg.sType.
    Complex scenes logic processing, preferably with proven code. Although Microsoft's CString very powerful, but can be inconvenient when using string STL, but I now more and more like the STL string you, of course, my definition of a string_t, add a name space to avoid, and some open source libraries conflict,
    Some well-known open source libraries like the following definition:

  1. #ifdef _UNICODE
  2.     typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > string_t;
  3. #else
  4.     typedef std::basic_string<char, std::char_traits<char>, std::allocator<char> > string_t;
  5. #endif
Copy the code


   But I prefer a brief definition:

  1. #ifdef _UNICODE
  2.     typedef std::wstring string_t;
  3. #else
  4.     typedef std::string  string_t;
  5. #endif
Copy the code


   Here is my favorite definition of Unicode:

  1. #include <string>
  2. #include <sstream> 
  3. namespace duilib
  4. {
  5. #ifdef _UNICODE
  6.     typedef wchar_t              char_t;
  7.     typedef std::wstring         string_t;
  8.     typedef std::wstringstream   stringstream_t;
  9. #else
  10.     typedef char                 char_t;
  11.     typedef std::string          string_t;
  12.     typedef std::stringstream    stringstream_t;
  13. #endif
  14. }
Copy the code

Guess you like

Origin www.cnblogs.com/blogpro/p/11427079.html