注册 登录
编程论坛 C语言论坛

怎么把这个窗口设置为桌面之上,所有程序之下?

不懂才问 发布于 2020-11-18 08:23, 3409 次点击
我要写个常驻桌面的工具栏程序,想让这个窗口程序在桌面之上,所有其他程序之下,也就是除了桌面,它不能盖住任何程序。不要像下图这样,跑到其他程序上面了。要怎么做呢?

放个时钟,总是执行主动失去焦点?有这样的事件吗?请各位大佬指点。谢谢

API太不熟了,要是必须用API,请讲的详细点,谢谢!

只有本站会员才能查看附件,请 登录
11 回复
#2
不懂才问2020-11-18 08:24
昨天百度到一种方法,说是加载此窗口时,将其父窗口设置为桌面,可是在程序里,要怎么描述桌面呢?
#3
lin51616782020-11-18 09:19
GetDesktopWindow
获取桌面句柄
#4
吹水佬2020-11-18 12:04
Windows平台:
1、放到Z序列底部
   SetWindowPos(hWnd, HWND_BOTTOM, ......),但当点击窗口时会回到Z序列顶部
2、嵌入到桌面,先获取真实的桌面窗口句柄 hDesktop (可能有几层,要找对)
   SetParent(hWnd, hDesktop);
#5
不懂才问2021-05-05 17:33
回复 4楼 吹水佬
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long


Private Sub Form_Load()
    Dim Q
    Q = SetParent(Me.hWnd, GetDesktopWindow())
End Sub


还是不能锁定到桌面上,是不是你说的“要找对”那个,我没找到正确的
#6
不懂才问2021-05-05 18:15
回复 4楼 吹水佬
Private Declare Function GetDesktopWindow Lib "user32" () 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 Sub Form_Load()
Dim Q
Q = SetWindowPos(GetDesktopWindow(), 1, 0, 0, 0, 0, 6)
End Sub


两个都试了,没看到我要的效果,还是要继续请教您啊!
#7
不懂才问2021-05-05 19:15
Private Declare Function GetWindow Lib "user32.dll" (ByVal a As Long, ByVal b As Long) As Long
Private Declare Function SetParent Lib "user32.dll" (ByVal a As Long, ByVal b As Long) As Long
Private Declare Function FindWindowA Lib "user32.dll" (ByVal a As String, ByVal b As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal hwnd As Long, ByVal tm As Long, ByVal c As Long, ByVal d As Long) As Long
Private Declare Function SetWindowLongA Lib "user32.dll" (ByVal hwnd As Long, ByVal item As Long, ByVal z As Long) As Long
Private Declare Function GetWindowLongA Lib "user32.dll" (ByVal hwnd As Long, ByVal sx As Long) As Long




Private Sub Form_Load()
  Label1.Caption = "本程序是121038做的,潜入桌面程序,做人就要有个目标,比如我的目标就是要为您服务,支持的就顶"
  Move 0, 0
  Dim bl As Long
  bl = GetWindowLongA(hwnd, -20)
  bl = bl Or 32 Or 800000
  SetWindowLongA hwnd, -20, bl
  SetLayeredWindowAttributes hwnd, 0, 120, 2
  bl = FindWindowA("ProgMan", 0)
  bl = GetWindow(bl, 5)
  SetParent hwnd, bl
End Sub


Private Sub Timer1_Timer()
  Label1.Move Label1.Left - 100
  If Label1.Left < -Label1.Width Then
     Label1.Left = Width
  End If
End Sub
https://bbs.bccn.net/viewthread.php?tid=123570&highlight=%D7%C0%C3%E6
找到了一个,学习一下,再回来
#8
rjsp2021-05-06 09:18
回复 7楼 不懂才问
总之:
 不是 GetDesktopWindow(),
 而是 GetDesktopWindow() 下面的一个子窗体(类名“Progman”,标题“Program Manager”)的子窗体(类名“SHELLDLL_DefView”,标题“”)
#9
不懂才问2021-05-06 18:00
回复 8楼 rjsp
感谢您的全面解释。懂了不少。又研究了一天,又找了一些这方面的例子,“bl = bl Or 32 Or 800000”,这一句,比较重要。
一个例子中的位或结果是524288。整个窗口没边框,还可以操作上面的按钮,窗口即使设置了父窗口为桌面的progman,也不会在最底层,会在其它窗口之上。
但如果是800032,就不能操作上面的按钮,并且有一条比较白的边框,不会遮挡其它窗口。

所以,这个位或的值的取值范围,我很感兴趣。
有没有鱼和熊掌可以兼得的?
又可以操作上面的按钮,又保持不遮挡其它窗口。

还要麻烦您再给点提示。比如做个循环,在哪些取值范围内,都刷新几秒,标签上给个提示,让我每种取值都操作试试。

不过,不太可能是从0到几十万吧?是和2的几次方有关吗?

麻烦了,谢谢!

[此贴子已经被作者于2021-5-6 18:03编辑过]

#10
rjsp2021-05-06 21:15
VB看着难受,你是想问 SetWindowLongA( hwnd, GWL_EXSTYLE, 这里可以填哪些属性吗?
见 https://docs.
#11
rjsp2021-05-07 09:37
回复 10楼 rjsp
bl = GetWindowLongA(hwnd, -20)
  bl = bl Or 32 Or 800000
  SetWindowLongA hwnd, -20, bl
  SetLayeredWindowAttributes hwnd, 0, 120, 2

把这些玩意儿去掉,就ok了
#12
不懂才问2021-05-07 15:19
回复 10楼 rjsp
完美的解决了我的问题,非常感谢!
1