zoukankan      html  css  js  c++  java
  • DSAPI 生成桌面图标(带数字)

    功能:在桌面上创建一个带有指定数字的图标。

    效果图:

    生成的ICO图标

    代码

    Private Sub 生成桌面图标(消息数量 As Integer)
            Try
                Dim B As New Bitmap(My.Resources.ICO)
                Using G As Graphics = Graphics.FromImage(B)
                    G.Clip = New Region(New RectangleF(0, 0, B.Width, B.Height))
                    Dim Cnt As String = If(消息数量 > 999, "999+", 消息数量)
                    Dim Ft As Font = New Font("黑体", 24, FontStyle.Bold)
                    Dim Sz As Size = DSAPI.图形图像.获取绘制文字所需大小(Cnt, Ft)
                    Using Tb As Bitmap = DSAPI.图形图像.绘制圆角矩形(Sz + New Drawing.Size(6, 4), 8, Color.Red, Color.DarkRed, Color.Transparent)
                        G.DrawImage(Tb, New Rectangle(B.Width - Tb.Width, 0, Tb.Width, Tb.Height), New Rectangle(0, 0, Tb.Width, Tb.Height), GraphicsUnit.Pixel)
                        G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
                        G.DrawString(Cnt, Ft, Brushes.White, New Point(B.Width - Tb.Width + 6, 0))
                    End Using
                End Using
                Dim Pth As String = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                Dim Stm As New IO.MemoryStream
                DSAPI.图形图像.图像生成ICO图标(B, 128).Save(Stm)
                IO.File.WriteAllBytes("c:	mp.ico", Stm.ToArray)
                Stm.Close()
                Dim Lnk As New DSAPI.文件.快捷方式 With
                {
                           .图标路径 = "c:	mp.ico",
                           .文件路径或URL = "https://www.cnblogs.com/dylike/",
                           .提示说明 = "有新的消息"
                }
                Lnk.保存快捷方式到(String.Concat(System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "程序.lnk"))
            Catch
            End Try
        End Sub
    

      

  • 相关阅读:
    Epoll技术深入学习
    nginx
    epoll案例
    Linux网络编程初步
    链表快速排序(已通过ACM在线评测)
    C++内存管理
    c++11并发语法初步
    数据库与SQL优化笔记(一)
    C++面向对象模型(虚表与虚表指针)
    c++的一些杂项
  • 原文地址:https://www.cnblogs.com/dylike/p/10677331.html
Copyright © 2011-2022 走看看