Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3922322
  • 博文数量: 534
  • 博客积分: 10470
  • 博客等级: 上将
  • 技术积分: 4800
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-26 14:08
文章分类

全部博文(534)

文章存档

2024年(1)

2021年(1)

2019年(1)

2017年(1)

2016年(2)

2013年(2)

2012年(10)

2011年(43)

2010年(10)

2009年(17)

2008年(121)

2007年(252)

2006年(73)

分类: C/C++

2008-07-17 14:31:37

我的学习环境:WinXP + Visual C++ 6.0
本来应该昨天写这东西的,遇到个问题找了好长时间,今天才解决!感觉现在学习VC有点小眉目了,找了一些小的技巧,继续努力哦,还有好多东西没有完成!路漫漫,坚持!

=============================
怎么将CString类型转换为:LPTSTR

CSDN上有一个这样的贴:
但我测试后只有这样好用:
    CString str;
    // ... Other Code for Get str Values

    // Add a New Node0
    TVINSERTSTRUCT  tvInsert;  

    tvInsert.hParent        = NULL;  
    tvInsert.hInsertAfter   = NULL;  
    tvInsert.item.mask        = TVIF_TEXT;
    tvInsert.item.iImage    = IDB_SNAPETCL_NODE0 - IDB_BASE;
    tvInsert.item.iSelectedImage = tvInsert.item.iImage;
    tvInsert.item.pszText    = str.GetBuffer(str.GetLength());
    GetTreeCtrl().InsertItem(&tvInsert);
    str.ReleaseBuffer();

=============================
String Table中的内容怎么使用:

    如果你使用SDK方式编程,可以使用LoadString()函数,其中的ID参数就是资源中的代码。
    如果使用MFC方式编程,可以使用CString::LoadString()函数,它的参数就是资源中的代码

=============================
CTreeCtrl上添加图标:
看到这么用的:
        CTreeCtrl& cThisTree = GetTreeCtrl();

        // load bitmaps for drive types & desktop - ten images
        CBitmap bitmap;
        m_pImageList = new CImageList();
        // 16x16 pixels, 8 of them
        m_pImageList->Create(16, 16, TRUE, 8, 4);
/*
#define IDB_REMOVE                      200
#define IDB_FIXED                       201
#define IDB_REMOTE                      202
#define IDB_CD                          203
#define IDB_DESKTOP                     204
#define IDB_FOLDCLS                     205
#define IDB_FOLDOPEN                    206
#define IDB_DOC                         207
*/
        // the 8 images have conseq resource numbers
        //    see resource.h
        for( int i = IDB_REMOVE; i <= IDB_DOC; i++)  
        {
            bitmap.LoadBitmap( i );
            m_pImageList->Add( &bitmap, (COLORREF)0xFFFFFF);
            bitmap.DeleteObject();
        }
        cThisTree.SetImageList( m_pImageList, TVSIL_NORMAL );

    TV_INSERTSTRUCT    strInsert;

    // must use a selectedimage even if same
    strInsert.item.mask = TVIF_TEXT |
                            TVIF_IMAGE |
                            TVIF_SELECTEDIMAGE;

    // a root item - so parent is NULL
    strInsert.hParent = NULL;
    // index of the image in the list
    strInsert.item.iImage = IDB_DESKTOP - IDB_REMOVE;
    strInsert.item.iSelectedImage = strInsert.item.iImage;
    // force to "Desktop" - the real Explorer uses the
    //    registry-based items (like "Computer")
    strInsert.item.pszText = (LPSTR)"Desktop";
    HTREEITEM hDesktop = cThisTree.InsertItem(&strInsert);

奇怪的是到我这
    strInsert.item.iImage = IDB_DESKTOP - IDB_REMOVE;
    strInsert.item.iSelectedImage = strInsert.item.iImage;
怎么用就是不起作用,没办法用SetItemImage()了

理解了原来哪个CImageList::Create中16, 16是在资源管理中的一个个象素点;16,16就是16x16个象素的小图标了。

=========================
VC中的输入提示好就是好,用习惯了,突然不用还不知道怎么写代码了。目前发现有一点感觉不爽,如str.LoadString()的输入会自动提示:(UINT nID),但是吧,按照编码规范上来说象()这个符号一般最好是成对输入的所以就以下子输入(),但结果提示就没有了。

好可惜,不懂的时候还得改变自己习惯的编码规范。

=========================
VC Debug输出显示技巧:

看来自己多半会选择单步Debug和TRACE输出(用在需要大量输出的时候比较合适)了,再就是MessageBox()了。

=========================
自定义消息的实现http://www.cppblog.com/xpzhou/archive/2007/04/18/22185.html
自己实践了,但总出问题最后找到了,错误的把:
ON_MESSAGE()写成ON_COMMAND()了。

发送消息为:AfxGetApp()->m_pMainWnd->PostMessage(WM_SHOW_TABVIEW_MONITOR, 0, 0);

注意:对某个窗口发送消息前一定要找到该窗口的句柄。同一个消息可以发送到不同的窗口,将会根据自己的设置做不同的处理。最好是子窗口可以给父窗口发送消息,父窗口可以给子窗口发送消息,但子窗口间最好不要来回发送消息。对所有窗口的句柄管理也得多注意,父窗口是可以知道所有子窗口的句柄的,但一个子窗口是比较难知道另外一个子窗口句柄的。

消息多容易搞糊涂,注意自己一定要理清顺序。
阅读(2395) | 评论(0) | 转发(0) |
0

上一篇:VC学习简单笔记 (1)

下一篇:IT的小说

给主人留下些什么吧!~~