西西软件园多重安全检测下载网站、值得信赖的软件下载站!
软件
软件
文章
搜索

首页编程开发VC|VC++ → 窗口处理控件技巧大全

窗口处理控件技巧大全

相关软件相关文章发表评论 来源:本站整理时间:2010/10/21 15:35:49字体大小:A-A+

作者:佚名点击:60次评论:0次标签: 窗口处理 控件

  • 类型:音频处理大小:1M语言:中文 评分:5.1
  • 标签:
立即下载
一下例子中可能用到的api声明和常量、变量声明
private declare function getwindowlong lib “user32″ alias “getwindowlonga” (byval hwnd as long, byval nindex as long) as long
private declare function setwindowlong lib “user32″ alias “setwindowlonga” (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long
private declare function setwindowpos lib “user32″ (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy as long, byval wflags as long) as long
private const swp_nosize = &h1
private const swp_nozorder = &h4
private const swp_nomove = &h2
private const swp_drawframe = &h20
private const gwl_style = (-16)
private const ws_thickframe = &h40000
private const ws_dlgframe = &h400000
private const ws_popup = &h80000000
private const ws_caption = &hc00000
private const ws_sysmenu = &h80000
private const ws_minimizebox = &h20000
private const ws_maximizebox = &h10000
private const ws_minimize = &h20000000
private const ws_maximize = &h1000000

——————————————————————————–

例子一:任何一个控件(只要有窗口,这是我们的前提,下同),你可以在运行时随便更改它的大小。 private sub controlsize(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_thickframe
else
dwstyle = dwstyle – ws_thickframe
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
用法:controlsize picture1,true;设置第二个参数为false取消这种设置,下同

——————————————————————————–

例子二:任何一个控件,我们都可以控制其显示风格为对话框的风格。
private sub controldialog(controlname as control, settrue as boolean)

dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_dlgframe
else
dwstyle = dwstyle – ws_dlgframe
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
用法:controlsize picture1,true

——————————————————————————–

例子三:任何一个控件,我们都可以控制其显示风格为模式对话框的风格
private sub controlmodal(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_popup
else
dwstyle = dwstyle – ws_popup
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
用法:controlmodal picture1,true

——————————————————————————–

例子四:任何一个控件,我们都可以给它加上标题栏,通过拖动标题栏,可以实现控件的运行时移动。
private sub controlcaption(controlname as control, settrue as boolean) dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_caption
else
dwstyle = dwstyle – ws_caption
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
用法:controlcaption picture1,true

——————————————————————————–

例子五:任何一个控件,我们都可以给它加上controlbox(所谓controlbox,就是窗体的图标+最小化+最大化+关闭按钮)。
private sub controlsysmenu(controlname as control, settrue as boolean)
dim dwstyle as long
dwstyle = getwindowlong(controlname.hwnd, gwl_style)
if settrue then
dwstyle = dwstyle or ws_sysmenu
else
dwstyle = dwstyle – ws_sysmenu
end if
dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)
setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe
end sub
用法:controlcaption picture1,true:controlsysmenu picture1,true

    相关评论

    阅读本文后您有什么感想? 已有人给出评价!

    • 8 喜欢喜欢
    • 3 顶
    • 1 难过难过
    • 5 囧
    • 3 围观围观
    • 2 无聊无聊

    热门评论

    最新评论

    发表评论 查看所有评论(0)

    昵称:
    表情: 高兴 可 汗 我不要 害羞 好 下下下 送花 屎 亲亲
    字数: 0/500 (您的评论需要经过审核才能显示)