2010.12.9 近期总结

近期汇总

 

1. CString问题

    CString有很多个版本,ATL/MFC/WTL.ATL和MFC统一有模板实现,WTL有自己的一套.

    WTL::CString 和 ATL::CString不同实现

    看ATL中CStringData成员

    IAtlStringMgr* pStringMgr;  // String manager for this CStringData

    int nDataLength;  // Length of currently used data in XCHARs (not including terminating null)

    int nAllocLength;  // Length of allocated data in XCHARs (not including terminating null)

    long nRefs;     // Reference count: negative == locked

 

    看WTL中CStringData成员

    long nRefs;     // reference count

    int nDataLength;

    int nAllocLength;

 

    成员不同,顺序也不同.

    不过有一个思想是一致的,统一用引用实现.

 

    在跨模块调用时如果使用CString有时候会导致问题,而且问题比较隐蔽.

    如果你使用/MD链接dll的话,会没有问题,但是如何你使用/MT链接的话,有时候会让你摸不着头脑.

 

   /MD静态链接运行时库,所以CString的代码会在各自的dll中驻留一份.

   而CString如果判断是否为空呢,是与一个全局的变量_afxInitData比较得到的.

   这样判断CString为空所对应的地址就不一样了.

   如果你只是一个模块内使用CString传来传去,这时候没有问题.

   但是一旦你在多个模块之间调用的时候,很容易引发问题.

 

   so,有一点,模块之间传递字符串,慎用CString

 

2. WM_COMMAND WM_NOTIFY

    关于COMMAND和NOTIFY的渊源,下面这段话讲的很清楚了.

    Notification Messages in Windows 3.x

In Windows 3.x, controls notify their parents of events such as mouse clicks, changes in content and selection, and control background painting by sending a message to the parent. Simple notifications are sent as special WM_COMMAND messages, with the notification code (such as BN_CLICKED) and control ID packed into wParam and the control's handle in lParam. Note that since wParam and lParam are full, there is no way to pass any additional data — these messages can be only simple notification. For instance, in the BN_CLICKED notification, there's no way to send information about the location of the mouse cursor when the button was clicked.

When controls in Windows 3.x need to send a notification message that includes additional data, they use a variety of special-purpose messages, including WM_CTLCOLOR, WM_VSCROLL, WM_HSCROLL, WM_DRAWITEM, WM_MEASUREITEM, WM_COMPAREITEM, WM_DELETEITEM, WM_CHARTOITEM, WM_VKEYTOITEM, and so on. These messages can be reflected back to the control that sent them. For more information, see TN062: Message Reflection for Windows Controls.

Notification Messages in Win32

For controls that existed in Windows 3.1, the Win32 API uses most of the notification messages that were used in Windows 3.x. However, Win32 also adds a number of sophisticated, complex controls to those supported in Windows 3.x. Frequently, these controls need to send additional data with their notification messages. Rather than adding a new WM_* message for each new notification that needs additional data, the designers of the Win32 API chose to add just one message, WM_NOTIFY, which can pass any amount of additional data in a standardized fashion. 

 

3. LockWindowUpdate

    此api可以限制住某一个窗口句柄的刷新,等解锁的时候统一刷新

    这样可以避免绘制的时候界面闪动.不过有个问题,微软的bug.在解锁刷新的时候,会导致桌面的抖动.

    不过用另外一种方法可以解决这个问题.

    When an application is minimized and LockWindowUpdate/UnlockWindowUpdate is called on one of it's controls           the Desktop window will flash. WM_SETREDRAW does the job without the flicker.

 

4. Shlwapi.h

   分享一个API

   此文件中包含

   String Routines

   Path Routines

   Registry Routines

   Stream Routines

   Multi Language UI Routines

   HTTP helper Routines

 

5. 创建快捷方式 

   IShellLink

   http://msdn.microsoft.com/en-us/library/aa969393.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值