Chinaunix首页 | 论坛 | 博客

  • 博客访问: 289986
  • 博文数量: 57
  • 博客积分: 2014
  • 博客等级: 大尉
  • 技术积分: 605
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-18 14:30
文章存档

2015年(3)

2009年(5)

2008年(32)

2007年(17)

我的朋友

分类: C/C++

2008-11-08 22:13:42

找了好久, 都没有找到一个很完善的TabCtrl解决方案, 做外挂的话没有这个东西实在是不方便, 而我又不愿因为一点小东西就去动用庞大的MFC, 苦恼啊, 终于在无意间发现了CP上面的一个C语言的实例, 居然是基于LCC的, 代码写的不错, 美中不足的是代码不完全符合C99标准, 不支持Unicode, 而且在C++中用起来也不够爽快, 今天晚上就来看看能不能把它搞定吧.
 
先总体浏览一下, 边看边分析, 改写的工作, 改天再来吧, 这个是给自己看的, 所以可能会很乱很乱的,如果路人无意间看见了, 那就见谅了.
 
 

//宿主对话框的初始化过程

BOOL FormMain_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
    //这里定义了几个TabControl的标签

    static LPSTR tabnames[]= {"Tab Page 1", "Tab Page 2", "Tab Page 3", "Tab Page 4", 0};
    //然后是每个属性页的内容对话框名称

    static LPSTR dlgnames[]= {MAKEINTRESOURCE(TAB_CONTROL_1_PAGE_1),
                              MAKEINTRESOURCE(TAB_CONTROL_1_PAGE_2),
                              MAKEINTRESOURCE(TAB_CONTROL_1_PAGE_3),
                              MAKEINTRESOURCE(TAB_CONTROL_1_PAGE_4),0};

    //同上面

    static LPSTR tab2names[]= {"Page 1", "Page 2", "Page 3", "Page 4", 0};
    static LPSTR dlg2names[]= {MAKEINTRESOURCE(TAB_CONTROL_2_PAGE_1),
                             MAKEINTRESOURCE(TAB_CONTROL_2_PAGE_2),
                             MAKEINTRESOURCE(TAB_CONTROL_2_PAGE_3),
                             MAKEINTRESOURCE(TAB_CONTROL_2_PAGE_4),0};
    //用作最小矩形的存储区域

    RECT rc;
    //这个函数就是把宿主窗体的句柄和主菜单句柄存放到全局变量中

    InitHandles (hwnd);
    
    //调用封装好的函数来创建(New)一个TabControl

    New_TabControl( &TabCtrl_1,// address of TabControl struct

                    GetDlgItem(hwnd, TAB_CONTROL_1), // handle to tab control

                    tabnames, // text for each tab

                    dlgnames, // dialog id's of each tab page dialog

                    &FormMain_DlgProc, // address of main windows proc

                    &TabCtrl1_TabPages_OnSize, // optional address of size function or NULL

                    TRUE); // stretch tab page to fit tab ctrl

    //同上

    New_TabControl( &TabCtrl_2,
                    GetDlgItem(hwnd, TAB_CONTROL_2),
                    tab2names,
                    dlg2names,
                    &FormMain_DlgProc,
                    &TabCtrl2_TabPages_OnSize,
                    TRUE);
    //设定Tab Control 2 中Edit Cntrol中的初始文字

    Edit_SetText(GetDlgItem(TabCtrl_2.hTabPages[0],LBL_3),
        "Use the Tab key to navagate between\r\ntab controls.\r\n\r\n"
        "Use the arrow keys or PageUp/Down keys\r\nto select a tab.\r\n\r\n"
        "Use the arrow keys to enter a tab page.\r\n\r\n"
        "Use the Tab key or arrow keys to navagate\r\ntab page child commands.\r\n\r\n"
        "Use Enter key to execute selected command.\r\n\r\n"
        "Try resizing the dialog while looking\r\nat different tabs.");

    //----Everything else must follow the above----//


    //Get the initial Width and height of the dialog

    //in order to fix the minimum size of dialog

    GetWindowRect(hwnd,&rc);
    gMinSize.cx = (rc.right - rc.left);
    gMinSize.cy = (rc.bottom - rc.top);

    return 0;
}

看看Tab究竟是怎么构造的吧

阅读(2114) | 评论(0) | 转发(0) |
0

上一篇:幸运? 公平!

下一篇:我心目中的编程高手

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