钢窟.

ShellEx的钢窟.

全金属外壳ID:ShellEx
49817次访问,排名2098好友0人,关注者0
ShellEx的文章
原创 44 篇
翻译 1 篇
转载 8 篇
评论 123 篇
全金属外壳(ShellEx)的公告
很遗憾,ShellEx要和CSDN Blog说88了. 以后再也不会受到*访问速度*, *更新延迟*, *服务器错误*...等困扰了. 以后,我ShellEx的新文章将全面转移至China Unix Blog: 地址: http://shellex.cublog.cn/ 欢迎各位新老贵客来访.
最近评论
hdnero:wow power leveling
人:new enevt 是什么意思啊
李佳:我要告诉全世界:"我真的很爱王守满"]真的很爱

我答应等他三年
他三年之后会回来找我
我相信他
他不会骗我的




我要告诉全世界
:"我爱(王守满)"
李佳:我要告诉全中国:"我真的很爱王守满"]真的很爱
SmartJacky:你好,我需要VA的注册包,谢谢!

smartjacky@126.com
文章分类
收藏
    相册
    Games
    文字配图
    作者的设计/手绘作品
    作者作品
    钢窟1号通信接口
    CSDN
    Milw0rm(RSS)
    安全焦点
    科幻世界
    黑客防线
    钢窟2号通信接口
    Asoft's 记忆碎片
    battle_Elf的鹰巢
    lake2的地盘(RSS)
    phixcoco@icdesign(RSS)
    Rejetto's Play House
    Wenisy的爱情流放地
    北斗星君的专栏(RSS)
    爱唱歌的狗狗(RSS)
    秋镇菜?的专栏
    老妖洞
    钢窟3号通信接口
    Looby's
    乌托邦帮主的地盘
    钢窟内部通信接口
    我的163相册
    钢窟.个人主页
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 扩展你的WIndows标准控件收藏

    新一篇: 与Ajax邂逅. | 旧一篇: gcc 内嵌汇编的学习笔记 IV

          扩展你的WIndows标准控件
     作者:ShellEx
     www.shellex.cn && blog.csdn.net/shellex 版权所有。

    标准控件嘛,意味着他们默认的功能和表现力都是有限的.比如说,当鼠标点击Edit控件时,虽然
    作为子窗体的Edit控件(Edit也是窗体)会接受到WM_LBUTTONUP和WM_LBUTTONDOWN消息,
    但是它并不会向父窗体发送相关的通知。也就是说,我们在处理WM_COMMAND消息时,不会
    在Edit的通知中获知Edit是否被点击了。
    下列是标准Edit所支持的通知,它们将被放在wParam的高字位中,其中并没有我想要的
    WM_LBUTTONUP或者类似的消息。

    EN_CHANGE :The user has modified text in an edit control. Windows updates the display before sending this message (unlike EN_UPDATE).
    EN_ERRSPACE :The edit control cannot allocate enough memory to meet a specific request.
    EN_HSCROLL : The user has clicked the edit control's horizontal scroll bar. Windows sends this message before updating the screen.
    EN_KILLFOCUS :The user has selected another control.
    EN_MAXTEXT  :  While inserting text, the user has exceeded the specified number of characters for the edit control. Insertion has been truncated. This message is also sent either when an edit control does not have the ES_AUTOHSCROLL : style and the number of characters to be inserted exceeds the width of the edit control or when an edit control does not have the ES_AUTOVSCROLL style and the total number of lines to be inserted exceeds the height of the edit control.
    EN_SETFOCUS  :  The user has selected this edit control.
    EN_UPDATE  :  The user has altered the text in the edit control and Windows is about to display the new text. Windows sends this message after formatting the text, but before displaying it, so that the application can resize the edit control window.
    EN_VSCROLL  :  The user has clicked the edit control's vertical scroll bar. Windows sends this message before updating the screen.

    想实现能对Edit单击鼠标事件发出响应,有个很简单的方法,那就是只需子类化Edit,自
    定义Edit的消息处理过程就可以了。有两个相关函数:
    LONG GetWindowLong(

        HWND hWnd, // handle of window
        int nIndex  // offset of value to retrieve
       );
      
    LONG SetWindowLong(

        HWND hWnd, // handle of window
        int nIndex, // offset of value to set
        LONG dwNewLong  // new value
       );
    前者可以得到窗体的若干信息,后者可以设置窗体的若干属性。包括处理消息的回调函数。
    关于函数的参数,请查阅MSDN。下面是具体实现。
    我先创建一个基于对话框的Win32 GUI工程,在相应WM_INITDIALOG消息的函数
    Main_OnInitDialog中写入如下代码:

    ////////////////////////////////////////////////////////////////////////////////


    //先得到原来的Edit的消息处理回调函数,最后一个参数使用GWL_WNDPROC
    oldEditProcAddr = GetWindowLong(GetDlgItem(hwnd,IDC_EDIT_PROCESS),GWL_WNDPROC);
    //子类化Edit,让他能发送EN_LBUTTONUP通知。
    SetWindowLong(GetDlgItem(hwnd,IDC_EDIT_PROCESS),GWL_WNDPROC ,(long) _NewEditProc);

    ////////////////////////////////////////////////////////////////////////////////

    EN_LBUTTONUP是我自定义的一个常量,是WM_USER + 101,IDC_EDIT_PROCESS是一个Edit
    控件的ID。hwnd是父窗体的句柄。_NewEditProc是我自己写的回调函数,以后发给Edit的
    消息会被送到_NewEditProc处理。
    下面是_NewEditProc函数的代码:

    ////////////////////////////////////////////////////////////////////////////////
    LRESULT CALLBACK _NewEditProc(HWND hwnd, UINT uMsg, WPARAM wParam,LPARAM lParam ) {
     //如果鼠标左键在Edit上放开
     if ( WM_LBUTTONUP == uMsg ) {
      //将本Edit的ID放到wparam的低字位,自定义的响应通知放在高字位
      WPARAM wp = MAKEWPARAM(IDC_EDIT_PROCESS, EN_LBUTTONUP);
      //lparam放着Edit的句柄
      LPARAM lp = (LPARAM)hwnd;
      把这个消息组合一下,作为WM_COMMAND发给父窗体
      SendMessage(GetParent(hwnd), WM_COMMAND, wp, lp);
     }
     //其他的消息由默认的处理函数处理
     return CallWindowProc((WNDPROC)oldEditProcAddr, hwnd, uMsg, wParam, lParam);
    }
    ////////////////////////////////////////////////////////////////////////////////

    现在,我在主窗体的消息循环里就可以轻易地得到鼠标单击的通知了:

    ////////////////////////////////////////////////////////////////////////////////
    void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) {
        switch(id) {
      case IDC_EDIT_PROCESS:
       if (codeNotify == EN_LBUTTONUP)
        Main_OnEditProcess_Click(hwnd,id,hwndCtl,codeNotify);
      break;
            default:break;
        }
    }
    ////////////////////////////////////////////////////////////////////////////////

    在函数Main_OnEditProcess_Click中可以轻松实现你希望实现的功能了。: )
        www.shellex.cn && blog.csdn.net/shellex 版权所有。

     

     

     

    发表于 @ 2006年12月15日 13:33:00|评论(loading...)|编辑

    新一篇: 与Ajax邂逅. | 旧一篇: gcc 内嵌汇编的学习笔记 IV

    评论

    #ShellEx 发表于2007-01-30 08:34:56  IP: 124.226.108.*
    可以匿名评论了咩?
    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © 全金属外壳(ShellEx)