玩酷之家

 找回密码
 立即注册
查看: 59|回复: 0

VB 右下角升级、广告窗口提示代码

[复制链接]
发表于 2021-1-8 16:42:07 | 显示全部楼层 |阅读模式
用以下代码可以让窗体自动定位到屏幕的右下角处,非常适合升级提示提示等功能界面。
  1. 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
  2. Private Const HWND_NOTOPMOST = -2
  3. Private Const HWND_TOPMOST = -1
  4. Private Const SWP_NOACTIVATE = &H10
  5. Private Const SWP_NOMOVE = &H2
  6. Private Const SWP_NOSIZE = &H1
  7. Private Const SWP_SHOWWINDOW = &H40

  8. Private Declare Function GetForegroundWindow Lib "user32" () As Long
  9. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

  10. Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
  11. Private Const SPI_GETWORKAREA = 48

  12. Private Type RECT
  13. Left As Long
  14. Top As Long
  15. Right As Long
  16. Bottom As Long
  17. End Type

  18. Private Sub Form_Load()
  19. Dim h As Long
  20. Dim ret As Long
  21. Dim rectVal As RECT

  22. h = GetForegroundWindow
  23. ret = SystemParametersInfo(SPI_GETWORKAREA, 0, rectVal, 0)
  24. Me.Move Screen.Width - Me.Width, rectVal.Bottom * Screen.TwipsPerPixelX - Me.Height
  25. SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW
  26. ret = SetForegroundWindow(h)
  27. End Sub
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|玩酷之家 ( 鄂ICP备14012049号 )

GMT+8, 2021-1-25 19:14 , Processed in 1.076402 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表