Page 1 sur 2

Trouver le handle du bureau

Publié : mer. 07/avr./2004 13:44
par Le Soldat Inconnu
Salut,

j'ai fait le programme suivant qui est assez amusant :wink:

le but de ce prog est de pouvoir lancer un icône du bureau par l'intermédiaire d'un trou réalisé dans les application afin de voir le bureau

Code : Tout sélectionner

; taille de la zone de l'écran utilisable (sans la barre des taches)
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @Taille_Ecran.RECT, 0)
Largeur_Ecran = Taille_Ecran\Right - Taille_Ecran\Left
Hauteur_Ecran = Taille_Ecran\Bottom - Taille_Ecran\Top

#Taille = 175

NewList hWndList.l()

If OpenWindow(0, Taille_Ecran\Left, Taille_Ecran\Top, Largeur_Ecran, Hauteur_Ecran, #PB_Window_Invisible | #PB_Window_BorderLess, "Affiche bureau")
  
  DC = GetDC_(0)
  CreateImage(0, Largeur_Ecran, Hauteur_Ecran)
  bitblt_(StartDrawing(ImageOutput()), 0, 0, Largeur_Ecran, Hauteur_Ecran, DC, 0, 0, #SRCCOPY)
  StopDrawing()
  ReleaseDC_(0, DC)
  
  SetWindowLong_(WindowID(), #GWL_EXSTYLE, GetWindowLong_(WindowID(), #GWL_EXSTYLE) | #WS_EX_TOOLWINDOW) ; choix de la barre d'outil réduite
  ShowWindow_(WindowID(), #SW_SHOW) ; montre la fenêtre
  SetWindowPos_(WindowID(), -1, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)
  
  If CreateGadgetList(WindowID())
    ImageGadget(0, 0, 0, Largeur_Ecran, Hauteur_Ecran, UseImage(0))
  EndIf
  
  UpdateWindow_(WindowID())
  
  ; On pousse les fenêtres
  hWnd.l = FindWindow_(0, 0)
  While hWnd <> 0
    If GetwindowLong_(Hwnd, #GWL_STYLE) & #WS_VISIBLE = #WS_VISIBLE
      If GetwindowLong_(Hwnd, #GWL_EXSTYLE) & #WS_EX_TOOLWINDOW <> #WS_EX_TOOLWINDOW
        GetWindowRect_(Hwnd, @Fen.RECT)
        MoveWindow_(Hwnd, Fen\Left + Largeur_Ecran + 50, Fen\Top, Fen\Right - Fen\Left, Fen\Bottom - Fen\Top, #True)
        AddElement(hWndList())
        hWndList() = Hwnd
      EndIf
    EndIf
    hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
  Wend
  
  Timer = SetTimer_(WindowID(), 0, 15, 0)
  
  #HotKeyID = 45
  RegisterHotKey_(WindowID(0), #HotKeyID, 0, #PB_Shortcut_Escape)
  
  Repeat
    Event = WaitWindowEvent()
    Win = GetForeGroundWindow_()
    
    If Event = #WM_Timer
      ; position de la souris
      GetCursorPos_(CursorPos.POINT)
      
      Region1 = CreateRectRgn_(Taille_Ecran\Left, Taille_Ecran\Top, Taille_Ecran\Right, Taille_Ecran\Bottom)
      Region2 = CreateEllipticRgn_(CursorPos\x - #Taille, CursorPos\y - #Taille, CursorPos\x + #Taille, CursorPos\y + #Taille)
      
      CombineRgn_(Region1, Region1, Region2, #RGN_DIFF)
      
      SetWindowRgn_(WindowID(), Region1, #True)
      
      DeleteObject_(Region1)
      DeleteObject_(Region2)
    EndIf
    
    If Event = #WM_HOTKEY
      If EventwParam() = #HotKeyID
        Win = 0  
      EndIf
    EndIf
    
  Until Win <> WindowID()
  
  UnregisterHotKey_(WindowID(), #HotKeyID)
  KillTimer_(WindowID(), Timer)
  
  ; On remet les fenêtres
  ResetList(hWndList())
  While NextElement(hWndList())
    GetWindowRect_(hWndList(), @Fen.RECT)
    MoveWindow_(hWndList(), Fen\Left - Largeur_Ecran - 50, Fen\Top, Fen\Right - Fen\Left, Fen\Bottom - Fen\Top, #True)
  Wend
  
EndIf
mais j'ai un prob car je ferme le programme quand ma fenêtre ou le bureau n'ont plus le focus.
mais je n'arrive pas à obtenir le handle du bureau pour que mon programme ne se ferme pas quand je clique sur le bureau ou sur un icone du bureau

j'ai essayé avec GetDeskTopWindow_() mais ça ne me renvoi pas le handle du bureau :(

Publié : mer. 07/avr./2004 16:14
par Oliv
Il y en as qui n'on vraiment rien à faire......mais c'est marrant :)
sinon, je pense que le handle du bureau est ça

Code : Tout sélectionner

Debug GetDC_(GetDesktopWindow_())

Publié : mer. 07/avr./2004 16:41
par Le Soldat Inconnu
tu m'a donné le handle pour dessiner sur le bureau, c'est pas ça qu'il me faut :roll:

Publié : mer. 07/avr./2004 17:36
par Oliv
:lol: pardon

Publié : mer. 07/avr./2004 21:56
par nico
C'est excellent, va falloir que j'y regarde de plus près! :D

Publié : jeu. 08/avr./2004 7:20
par brossden
Bravo Régis pour ce code, il est trés amusant et me donne des idées d'applications ! :P

Publié : jeu. 08/avr./2004 7:40
par Le Soldat Inconnu
bon, j'ai trouvé un paliatif au handle du bureau que je n'arrivait pas à obtenir.

comme pour lancer un raccourci, il faut cliquer sur le bureau et que je n'ai que ça sous la souris (forcément puisqu'il y a un trou), je dis que lorsque le handle de la fenêtre au premier change la première fois, c'est le handle du bureau. (en prenant soin de vérifier que la souris est bien au dessus du bureau et pas de la barre des taches)

donc mon petit code :

Code : Tout sélectionner

#Taille = 200

NewList hWndList.l()


; taille de la zone de l'écran utilisable (sans la barre des taches)
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @Taille_Ecran.RECT, 0)
Largeur_Ecran = Taille_Ecran\Right - Taille_Ecran\Left
Hauteur_Ecran = Taille_Ecran\Bottom - Taille_Ecran\Top

If OpenWindow(0, Taille_Ecran\Left, Taille_Ecran\Top, Largeur_Ecran, Hauteur_Ecran, #PB_Window_Invisible | #PB_Window_BorderLess, "Affiche bureau")
  
  DC = GetDC_(0)
  CreateImage(0, Largeur_Ecran, Hauteur_Ecran)
  Dessin = StartDrawing(ImageOutput())
    bitblt_(Dessin, 0, 0, Largeur_Ecran, Hauteur_Ecran, DC, 0, 0, #SRCCOPY)
  StopDrawing()
  ReleaseDC_(0, DC)
  
  SetWindowLong_(WindowID(), #GWL_EXSTYLE, GetWindowLong_(WindowID(), #GWL_EXSTYLE) | #WS_EX_TOOLWINDOW) ; choix de la barre d'outil réduite
  ShowWindow_(WindowID(), #SW_SHOW) ; montre la fenêtre
  SetWindowPos_(WindowID(), -1, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)
  
  If CreateGadgetList(WindowID())
    ImageGadget(0, 0, 0, Largeur_Ecran, Hauteur_Ecran, UseImage(0))
  EndIf
  
  UpdateWindow_(WindowID())
  
  ; On pousse les fenêtres
  hWnd.l = FindWindow_(0, 0)
  While hWnd <> 0
    If GetwindowLong_(Hwnd, #GWL_STYLE) & #WS_VISIBLE = #WS_VISIBLE
      If GetwindowLong_(Hwnd, #GWL_EXSTYLE) & #WS_EX_TOOLWINDOW <> #WS_EX_TOOLWINDOW
        GetWindowRect_(Hwnd, @Fen.RECT)
        MoveWindow_(Hwnd, Fen\Left + Largeur_Ecran + 50, Fen\Top, Fen\Right - Fen\Left, Fen\Bottom - Fen\Top, #True)
        AddElement(hWndList())
        hWndList() = Hwnd
      EndIf
    EndIf
    hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
  Wend
  
  Timer = SetTimer_(WindowID(), 0, 15, 0)
  
  #HotKeyID = 45
  RegisterHotKey_(WindowID(0), #HotKeyID, 0, #PB_Shortcut_Escape)
  
  Bureau = 0
  
  Repeat
    Event = WaitWindowEvent()
    Win = GetForeGroundWindow_()
    
    If Event = #WM_Timer
      ; position de la souris
      GetCursorPos_(CursorPos.POINT)
      
      Region1 = CreateRectRgn_(Taille_Ecran\Left, Taille_Ecran\Top, Taille_Ecran\Right, Taille_Ecran\Bottom)
      Region2 = CreateEllipticRgn_(CursorPos\x - #Taille, CursorPos\y - #Taille, CursorPos\x + #Taille, CursorPos\y + #Taille)
      
      CombineRgn_(Region1, Region1, Region2, #RGN_DIFF)
      
      SetWindowRgn_(WindowID(), Region1, #True)
      UpdateWindow_(WindowID())
      
      DeleteObject_(Region1)
      DeleteObject_(Region2)
    EndIf
    
    If Event = #WM_HOTKEY ; si on appui sur Echap
      If EventwParam() = #HotKeyID
        Win = -1
      EndIf
    EndIf
    
    If Bureau = 0 And Win <> WindowID()
      GetCursorPos_(CursorPos.POINT)
      If CursorPos\x >= Taille_Ecran\Left And CursorPos\x <= Taille_Ecran\Right And CursorPos\y >= Taille_Ecran\Top And CursorPos\y <= Taille_Ecran\Bottom
        Bureau = Win
      EndIf
    EndIf
    
  Until (Win <> WindowID() And Win <> Bureau) Or Win = -1
  
  UnregisterHotKey_(WindowID(), #HotKeyID)
  KillTimer_(WindowID(), Timer)
  
  ; On remet les fenêtres
  ResetList(hWndList())
  While NextElement(hWndList())
    GetWindowRect_(hWndList(), @Fen.RECT)
    MoveWindow_(hWndList(), Fen\Left - Largeur_Ecran - 50, Fen\Top, Fen\Right - Fen\Left, Fen\Bottom - Fen\Top, #True)
  Wend

EndIf
le programme sera sur mon site d'ici peu (demain, rubrique petits utilitaires)

si vous voulez une explication qlconque, demandez moi parce que coté commentaire, faut bien chercher pour les trouver.

Publié : jeu. 08/avr./2004 11:31
par nico
Moi je dis qu'il y a du génie dans ce code, mais d'où peut t'il venir ? :wink:

Publié : jeu. 08/avr./2004 14:08
par Le Soldat Inconnu
cherche pas, je suis génial :mrgreen: et je vais le prouver dans mon prochain message, regarde bien :wink:

Publié : jeu. 08/avr./2004 14:25
par Chris
cherche pas, je suis génial
Ta modestie te perdra ! 8O

Chris :)

Publié : jeu. 08/avr./2004 14:27
par Le Soldat Inconnu
ma "modestie", ça fait longtemps qu'elle est morte et enterrée :mrgreen:
et puis j'ai quand même le droit de me lance des fleurs, si ça me fait plaisir :lol:

Publié : jeu. 08/avr./2004 14:32
par Chris
j'ai quand même le droit de me lance des fleurs, si ça me fait plaisir
Bien sur!!! , on n'est jamais si bien servi que par soi-même!

Chris :)

Publié : jeu. 08/avr./2004 15:31
par Fred
A mon avis, le handle que tu recherches est celui du gadget ListView() qui gere les icones, qui doit etre 'fils' de la fenetre GetDesktopWindow_(). Un bon truc est d'utiliser 'Spy++' un outil livré avec le VisualC++ tres pratique pour explorer les fenetres ouvertes etc..

Publié : jeu. 08/avr./2004 17:17
par Chris
Ah, ben si c'est ça que tu veux, en voilà:

Code : Tout sélectionner

hTmp = GetShellWindow_()
hInstance = GetWindowLong_(hTmp, #GWL_HINSTANCE)
Buffer$ = Space(256)

Repeat
  hTmp = GetTopWindow_(hTmp)
  GetClassName_(hTmp,Buffer$,256)
Until Buffer$ = "SysListView32"

Debug hTmp
Chris :)

Publié : ven. 09/avr./2004 13:38
par Le Soldat Inconnu
c'est quoi, cette horreur, tu peux expliquer comment tu as fait pour pondre ce truc, que je comprenne comment tu as fait, parce que la .... :roll: merci