代码改变世界

Visual C++ 2011-07-18

2011-07-19 19:40  Clingingboy  阅读(658)  评论(0编辑  收藏  举报

 

一.Keyboard Accelerators控件快捷键

参考:http://blog.csdn.net/Welson80/article/details/5808277

http://www.cnblogs.com/zengcan/archive/2010/01/25/1655908.html

相关函数:
LoadAccelerators
TranslateAccelerator

二.WSARecvDisconnect && WSASendDisconnect

http://baike.baidu.com/view/567695.htm
http://baike.baidu.com/view/569168.html

三.判断Window

  1. IsWindow The IsWindow function determines whether the specified window handle identifies an existing window.
  2. IsWindowEnabled The IsWindowEnabled function determines whether the specified window is enabled for mouse and keyboard input.
  3. IsWindowVisible  The IsWindowVisible function retrieves the visibility state of the specified window.

四.ATL宏

1.OBJECT_ENTRY_AUTO

指定一个COM可创建类,通常表示类从CComCoClass继承

2.DECLARE_OBJECT_DESCRIPTION

自定COM类描述

3.UpdateRegistry方法

用于注册类信息到注册表中,用4个宏表示

3.1 DECLARE_NO_REGISTRY空实现.表示COM类不注册

3.2 DECLARE_REGISTRY 旧版本使用

3.3 DECLARE_REGISTRY_RESOURCE && DECLARE_REGISTRY_RESOURCEID 使用脚本资源

五.RGS脚本

[NoRemove | ForceRemove | val] Name [ = s | d | m | b 'Value'] { ... optional script entries for subkeys }

ForceRemove表示当发生变更时则强制删除,NoRemove则刚相反

val表示键名,s | d | m | b表示键值类型.下面是一个例子
HKCR表示注册表根路径(HKEY_CLASSES_ROOT)

HKCR
{
    ForceRemove DuckDoer.DuckDoer.1 = s 'DuckDoer Class'
    {
        CLSID = s '{120B72A0-65BF-11D0-9DDC-00A0C9034892}'
    }
    ForceRemove DuckDoer.DuckDoer = s 'DuckDoer Class'
    {
        CurVer = s 'DuckDoer.DuckDoer.1'
    }
    NoRemove CLSID
    {
        ForceRemove {120B72A0-65BF-11D0-9DDC-00A0C9034892} = s 'DuckDoer Class'
        {
            ProgID = s 'DuckDoer.DuckDoer.1'
            VersionIndependentProgID = s 'DuckDoer.DuckDoer'
            LocalServer32 = s '%MODULE%'
        }
    }
}

六.脚本变量

%MODULE%在被调用时会被GetModuleFileName方法替换

自注册变量,重写AddCommonRGSReplacements方法

    HRESULT AddCommonRGSReplacements(IRegistrarBase *pRegistrar) {
    BaseModule::AddCommonRGSReplacements( pRegistrar );
    OLECHAR wszDate [16]; SYSTEMTIME st;
    GetLocalTime(&st);
    wsprintfW(wszDate, L"%.4d/%.2d/%.2d", st.wYear,
        st.wMonth, st.wDay);
    pRegistrar->AddReplacement( OLESTR("INSTALLDATE"), wszDate );
}

替换部分变量,可以在UpdateRegistry方法中手动调用UpdateRegistryFromResource(本来由DECLARE_REGISTRY_RESOURCEID宏自动完成)方法

static HRESULT WINAPI UpdateRegistry(BOOL b) {
    OLECHAR wszDate [16]; SYSTEMTIME st;
    GetLocalTime(&st);
    wsprintfW(wszDate, L"%.4d/%.2d/%.2d", st.wYear,
        st.wMonth, st.wDay);
    _ATL_REGMAP_ENTRY rm[] = {
        { OLESTR("INSTALLDATE"), wszDate},
        { 0, 0 } };
    return _pAtlModule->UpdateRegistryFromResource(
        IDR_DEMAGOGUE, b, rm);
}

七.组件类别

// {0D22FF22-28CC-11d2-ABDD-00A0C9C8E50D}
static const GUID CATID_ATLINTERNALS_SAMPLES =
{0xd22ff22, 0x28cc, 0x11d2, {0xab, 0xdd, 0x0, 0xa0, 0xc9, 0xc8,
     0xe5, 0xd}};

BEGIN_CATEGORY_MAP(CDemagogue)
IMPLEMENTED_CATEGORY(CATID_ATLINTERNALS_SAMPLES)
END_CATEGORY_MAP()

八.ATL调试宏

  1. ATLASSERT下断点
  2. AtlTrace输出Debug视窗 即内部调用了OutputDebugString
  3. AtlTrace2参数更多,可以分类别输出