• 网站刚刚上线,难免有不足的地方,敬请谅解!欢迎提出宝贵意见!

  •    3年前 (2015-06-18)  windows开发 专业技术 |   5 条评论  2185 
    文章评分 5 次,平均分 4.6

    【Windows编程】系列第二篇:Windows SDK创建基本控件

    前一篇文章我们一起学习了Windows编程基本框架,几乎所有的Windows编程都是以这个模式开始,剩下的就是如何怎么框架的基础上如何添加枝叶实现不同的功能了。在Windows平台下,肯定少不了最基本的界面控件,这些控件方便了应用程序与用户之间的交互,也成了Windows独霸个人PC市场近20年的关键因素。

    在Win32 SDK环境下,怎么来创建常用的那些基本控件呢?我们知道如果用MFC,简单的拖放即可完成大多数控件的创建,但是我们既然是用Windows SDK API编程,当然是从根上解决这个问题,实际上MFC的下层也是通过这些API完成的。

    实际上控件也是窗口,只不过是被微软预先创建好的一种窗口类,比如button就是一个类名为“BUTTON”的类。既然控件实际上是窗口,当然也是用CreateWindow或者CreateWindowEx这个函数来完成的,第二个函数除了多一个扩展风格之外,其他完全一样,下面以主要以CreateWindow为例说明,该函数原型如下(实际上在第一篇已经讲过了):

    lpClassName:控件的类名

    lpWindowName:控件的名字或者文本

    dwStyle:控件风格

    x,y,nWidth,nHeight:控件的坐标和宽高

    hWndParent:控件的父窗口

    hMenu:控件的ID

    hInstance:控件设置为空

    lpParam:控件设为空

    那么具体怎么实现各个基本的控件呢?下面我们来先依次举例。

    • 创建标签/静态文本

    •  创建button

    •  创建编辑框

    •  创建Groupbox

    •  创建单选框

    •  创建复选框

    •  创建列表框

    •  创建组合框

    •  创建滚动条

     

    以上创建各个控件都很差傻瓜化,你可以复制下来改改坐标、文本、风格、ID等就可以按照你的需要创建了。

    下面我们就来实战一下,把这些常用的控件在程序中实现,下面我们来实现一个完整的windows程序,程序中包含了这些常用的控件和更多的用法。

    /* 常用控件实例 */

     

    编译一下运行,结果如下:

    【Windows编程】系列第二篇:Windows SDK创建基本控件

    怎么样,是不是很简单,虽然我们的控件创建比MFC麻烦一下,但是我们是从“根”上来解决问题的,感觉是不一样的!有了这些基本的用法,你就可以构建更加复制的Windows界面了。赶快去试试吧。

    转载请注明原地址:http://www.coderonline.net/?p=680

    更多经验交流可以加入Windows编程讨论QQ群454398517

     

    身为一名IT技术人员磨练自己的技术是必不可少的,欢迎加入QQ群:程序员互动联盟(254241126),可以与大牛在线随时讨论自己感兴趣的话题,大牛每天为你奉献一篇技术原创,让自己用最少的时间学到很多东西,我在程序员互动联盟期待您的加入:)

    如果大家想更深入了解更多的编程知识,请关注我们的公众号,及时沟通,这里有各种大牛帮你解决问题。微信公众平台:程序员互动联盟(coder_online)。

    欢迎加入我们的QQ群:程序员互动联盟(254241126)

     

    本文原始地址:http://www.coderonline.net/programming-windows-second-series-windows-sdk-to-create-a-basic-control.html

    本站所有文章,除特别注明外,均为本站原创,转载请注明出处来自http://www.coderonline.net/

    否则保留追究法律责任的权利!

    关于

    发表评论

    表情 格式
    1. I discovered your 【Windows编程】系列第二篇:Windows SDK创建基本控件 – 程序员互动联盟 page and noticed you could have a lot more traffic. I have found that the key to running a website is making sure the visitors you are getting are interested in your subject matter. We can send you targeted traffic and we let you try it for free. Get over 1,000 targeted visitors per day to your website. Check it out here: http://priscilarodrigues.com.br/url/v

      Elisa Brown 评论达人 LV.1 1年前 (2017-05-07) [0] [0]
    2. I came across your 【Windows编程】系列第二篇:Windows SDK创建基本控件 – 程序员互动联盟 website and wanted to let you know that we have decided to open our POWERFUL and PRIVATE website traffic system to the public for a limited time! You can sign up for our targeted traffic network with a free trial as we make this offer available again. If you need targeted traffic that is interested in your subject matter or products start your free trial today: http://tdil.co/3p

      Elisa Brown 评论达人 LV.1 1年前 (2017-05-04) [0] [0]
    3. Hello my name is Sabrina Warren and I just wanted to send you a quick note here instead of calling you. I discovered your 【Windows编程】系列第二篇:Windows SDK创建基本控件 – 程序员互动联盟 website and noticed you could have a lot more traffic. I have found that the key to running a successful website is making sure the visitors you are getting are interested in your subject matter. There is a company that you can get keyword targeted traffic from and they let you try their service for free for 7 days. I managed to get over 300 targeted visitors to day to my site. http://deaf.im/zyr-x

      Sabrina Warren 评论达人 LV.1 2年前 (2017-02-14) [0] [0]
    4. This is a message to the admin. I discovered your 【Windows编程】系列第二篇:Windows SDK创建基本控件 – 程序员互动联盟 page by searching on Google but it was difficult to find as you were not on the first page of search results. I know you could have more traffic to your website. I have found a website which offers to dramatically improve your rankings and traffic to your site: http://webhop.se/1ix I managed to get close to 500 visitors/day using their service, you can also get many more targeted traffic from search engines than you have now. Their services brought significantly more visitors to my site. I hope this helps!

      Evelyn Serrell 评论达人 LV.1 2年前 (2016-12-11) [0] [0]
    5. Hi my name is Teresa and I just wanted to send you a quick message here instead of calling you. I came to your 【Windows编程】系列第二篇:Windows SDK创建基本控件 – 程序员互动联盟 page and noticed you could have a lot more traffic. I have found that the key to running a successful website is making sure the visitors you are getting are interested in your website topic. There is a company that you can get keyword targeted traffic from and they let you try their service for free for 7 days. I managed to get over 300 targeted visitors to day to my website. http://www.isugarbox.com/yourl/b5

      Teresa 评论达人 LV.1 2年前 (2016-08-30) [0] [1]
    切换注册

    登录

    忘记密码 ?

    切换登录

    注册