| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 604 人关注过本帖
标题:这个代码效果不是很好,谁帮优化一下,谢谢!
只看楼主 加入收藏
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
结帖率:89.13%
收藏
 问题点数:0 回复次数:0 
这个代码效果不是很好,谁帮优化一下,谢谢!
VB6使用API即时改变桌面图标大小
        
窗体拖入控件:Command1


Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
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 Const GWL_STYLE = (-16)
Private Const LVM_FIRST = &H1000
Private Const LVM_SETICONSPACING = LVM_FIRST + 53

Private Sub Command1_Click()
    Dim hWnd As Long
    Dim hListView As Long
    Dim lStyle As Long
    Dim lResult As Long
    Dim iIconSize As Integer
   
    '获取桌面窗口句柄
    hWnd = GetDesktopWindow()
   
    '获取桌面ListView控件句柄
    hListView = FindWindowEx(hWnd, 0, "Progman", vbNullString)
    hListView = FindWindowEx(hListView, 0, "SHELLDLL_DefView", vbNullString)
    hListView = FindWindowEx(hListView, 0, "SysListView32", vbNullString)
   
    '获取当前图标大小
    lStyle = GetWindowLong(hListView, GWL_STYLE)
    If lStyle And &H4000 Then
        iIconSize = 32
    Else
        iIconSize = 48
    End If
   
    '切换图标大小
    If iIconSize = 32 Then
        lResult = SendMessage(hListView, LVM_SETICONSPACING, 0, ByVal CLng(48 * 65536 + 48))
        SetWindowLong hListView, GWL_STYLE, lStyle And Not &H4000
    Else
        lResult = SendMessage(hListView, LVM_SETICONSPACING, 0, ByVal CLng(32 * 65536 + 32))
        SetWindowLong hListView, GWL_STYLE, lStyle Or &H4000
    End If
   
    '刷新桌面
    SendMessage hWnd, &H111, &HB, ByVal 0&
End Sub
搜索更多相关主题的帖子: ByVal Function Long hWnd Private 
2023-03-28 19:47
快速回复:这个代码效果不是很好,谁帮优化一下,谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049680 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved