Page 1 of 1

Modify or create frame around explorer window

Posted: Mon Apr 15, 2024 11:18 am
by Kwai chang caine
Hello at all

I open several explorer windows "C:\" and "D:\" and "C:\Program files\"
And i want spot one of this explorer window, for example :
- Change window background color
- Change titlebar background color
- Change icon in TileBar
- Create a square around it
etc ...

For the moment, I just know how to change the title :oops:
But it's not realy visible :| i prefer something with color for good see the window selected :D

Code: Select all

Hwnd = FindWindow_("CabinetWClass", "C:\")
Debug Hwnd

; Change title
Title$ = Space(256)
GetWindowText_(Hwnd, Title$, 256)
Title$ = Title$ + " ==> MASTER"
SetWindowText_(Hwnd, Title$)

; Change background color (NOT WORKS => Nothing happening) 
hBrush = CreateSolidBrush_(RGB(0, 255, 255)) 
SetClassLong_(Hwnd, #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(Hwnd, #Null, #True) 
;DeleteObject_(hBrush)

; Change icone window (NOT WORKS => Icon disapear, new icon not show) 
If LoadImage(0, #PB_Compiler_Home + "..\Examples\#Commun\ico2.ico") 
 SendMessage_(hWnd,#WM_SETICON,0, ImageID(0)) 
EndIf 
Have you a simple code, to spot one of my windows ?

I wish to you all a good day

Re: Modify explorer window

Posted: Mon Apr 15, 2024 5:23 pm
by Kwai chang caine
Thanks to a Netmaestro code (Transparency window) 8)
https://www.purebasic.fr/english/viewto ... 41#p551441
I nearly have what i want to do, but the problem is with StickyWindow() other windows can pass between my cible window "C:\" and my FRAM :|

Image

Have you a way for linking my window cible and my frame, or perhaps for replace the stickywindow() send to the frame a style of ZORDER only one level less or more :oops:

Code: Select all

Procedure WindowFrame(Hwnd)
  
 GetClientRect_(Hwnd, Cible.rect)
 PosX = Cible\left + 5
 PosY = Cible\top
 Largeur = Cible\right - Cible\left + 5
 Hauteur = Cible\bottom - Cible\top
 CreateImage(0, Largeur + 10, Hauteur + 10, 32, #PB_Image_Transparent)

 StartVectorDrawing(ImageVectorOutput(0))
  VectorSourceColor(RGBA(255,0,0,255))
  AddPathBox(PosX, PosY, Largeur, Hauteur)
  StrokePath(4)
 StopVectorDrawing()
  
 HwndFenetre = OpenWindow(0, PosX, PosY, Largeur + 10, Hauteur + 10, "Gdiplus Drawing", #PB_Window_ScreenCentered|#PB_Window_BorderLess)
 SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED)
 StickyWindow(0, #True)
 
 hDC = StartDrawing(ImageOutput(0))
  sz.SIZE\cx = ImageWidth(0)
  sz.SIZE\cy = ImageHeight(0)
  BlendMode.BLENDFUNCTION\SourceConstantAlpha = 255
  BlendMode.BLENDFUNCTION\AlphaFormat = 1
  UpdateLayeredWindow_(WindowID(0),0,0,@sz,hDC,@ContextOffset.POINT,0,@BlendMode,2)
 StopDrawing()
 
 ProcedureReturn HwndFenetre
 
EndProcedure

Hwnd = FindWindow_("CabinetWClass", "C:\")
HwndFrame = WindowFrame(Hwnd)

Repeat : 

 WindowEvent()
 Delay(1)
 GetWindowRect_(Hwnd, Cible.rect)
 ResizeWindow(0, Cible\left, Cible\top, Cible\right - Cible\left, Cible\bottom - Cible\top)
 
Until GetAsyncKeyState_(#VK_ESCAPE)

Re: Modify explorer window

Posted: Tue Apr 16, 2024 7:44 am
by firace
Not sure if this responds to your needs, but here's a different, very simple solution, using the standard FlashWindow() API:

Code: Select all

OpenWindow(0, 100, 100, 140, 80, "Test")

ExplorerWindowTitle$ = "OS (C:)"    ;  <<<--- change this to the title of your explorer window

hWnd=FindWindow_(0, @ExplorerWindowTitle$)

FlashWindow_(hWnd, 3)  


Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 

Re: Modify explorer window

Posted: Tue Apr 16, 2024 9:24 am
by Kwai chang caine
Hello FIRACE

Thanks for your precious help, very happy to talk to you 8) since all this long time :|

Yeeess !!!
it's not really that i search to do, but you have a really good idea :wink:
I have forgoten this API, who not use really often, i must to say :lol:

I have test your code and have a strange behaviour, my window flash only one time :shock:
After search, i found the second parameter is not the number of flash, but just a boolean for flash or not :wink:

Thanks to you now and your servant (The dream team :lol: )...my window can be flashed

Code: Select all

OpenWindow(0, 100, 100, 140, 80, "Test")

ExplorerWindowTitle$ = "OS (C:)"    ;  <<<--- change this to the title of your explorer window

hWnd=FindWindow_(0, @ExplorerWindowTitle$)

For i = 1 To 20
 FlashWindow_(hWnd, #True)
 Delay(100)
 Debug i
Next 

FlashWindow_(hWnd, #False)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
Again thanks for your interest, if you have another good idea for linked my two windows, or draw a frame around my target window, i'm always here :D (Unfortunately for you all :mrgreen: )
Have a very good day MASTER Firace 8)

Re: Modify explorer window

Posted: Tue Apr 16, 2024 9:44 am
by Caronte3D
I think is Better if you get rid of the Delay() with something like that: :wink:

Code: Select all

EnableExplicit

OpenWindow(0, 100, 100, 140, 80, "Test")

Define ExplorerWindowTitle$ = "OS (C:)"    ; <<<--- change this to the title of your explorer window



Define hWnd = FindWindow_(0, @ExplorerWindowTitle$)



Define Elapsed.q         = ElapsedMilliseconds()
Define flashCurrentCount = 1
Define maxFlashCount     = 20
Define flashDelay        = 100

Repeat
  
  If ElapsedMilliseconds() - flashDelay > Elapsed And flashCurrentCount <= 20
    Elapsed = ElapsedMilliseconds()
    FlashWindow_(hWnd, #True)
    Debug flashCurrentCount
    flashCurrentCount + 1
  ElseIf flashCurrentCount = 20
      ;flashCurrentCount=1
    FlashWindow_(hWnd, #False)
  EndIf
  
Until WaitWindowEvent(10) = #PB_Event_CloseWindow

Re: Modify explorer window

Posted: Tue Apr 16, 2024 9:52 am
by Kwai chang caine
Hello Caronte3D
Yes your flash is more regular :wink:
Thanks for your interest 8)

Re: Modify explorer window

Posted: Tue Apr 16, 2024 9:57 am
by breeze4me
Try this.

Code: Select all

Procedure Event_ResizeWnd()
  Protected Wnd = EventWindow()
  Protected w = WindowWidth(Wnd)
  Protected h = WindowHeight(Wnd)
  Static img
  
  If IsImage(img) : FreeImage(img): EndIf
  If w > 0 And h > 0
    img = CreateImage(#PB_Any, w, h, 24, #Red)
    If img
      If StartDrawing(ImageOutput(img))
        Box(10, 10, w - 20, h - 20, #White)
        StopDrawing()
        SetGadgetState(0, ImageID(img))
      EndIf
    EndIf
  EndIf
EndProcedure

hWnd = OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Invisible)
SetWindowLongPtr_(hWnd, #GWL_EXSTYLE, GetWindowLongPtr_(hWnd, #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(hWnd, #White, 0, #LWA_COLORKEY)
ImageGadget(0, 0, 0, 0, 0, 0)

BindEvent(#PB_Event_SizeWindow, @Event_ResizeWnd(), 0)

Hwnd = FindWindow_("CabinetWClass", "C:\")

HideWindow(0, 0)

Repeat

 WindowEvent()
 Delay(1)
 GetWindowRect_(Hwnd, Cible.rect)
 SetWindowPos_(WindowID(0), hwnd, Cible\left, Cible\top - 6, Cible\right - Cible\left, Cible\bottom - Cible\top + 6, #SWP_NOACTIVATE)
 
Until GetAsyncKeyState_(#VK_ESCAPE)

Re: Modify explorer window

Posted: Tue Apr 16, 2024 9:59 am
by firace
Hi KCC, happy to talk to you too!

Sorry I don't have enough time to look at your frame code, but here's another crazy idea, "shaking" the window so you can notice it: :)

Code: Select all

ExplorerWindowTitle$ = "OS (C:)"    ;  <<<--- change this to the title of your explorer window

hWnd=FindWindow_(0, @ExplorerWindowTitle$)

GetWindowRect_(hWnd,re.RECT)

L = re\left
R = re\right
T = re\top
B = re\bottom
W = R - L
H = B - T

for a = 1 to 5
  moveWindow_(hwnd, L, T, W, H, 0)
  delay(80)
  moveWindow_(hwnd, L+10, T+10, W, H, 0)
  delay(80)
next 

Re: Modify explorer window

Posted: Tue Apr 16, 2024 10:43 am
by Kwai chang caine
Ouaaaaarfff !!! Ouaaaaarfff !!!
Image

DYING of laughter

Really FIRACE ....your humor equal to your knowledge and it's very difficult to achieve it :lol:
I not have thinking to this two
Another great idea to keep :wink:

The only one problem, it's if I have to leave the distinctive sign in place for hours to recognize my window,

Image

I'm not sure I'll escape unscathed :mrgreen:

Image

Thanks a lot for your nice present MASTER

Re: Modify explorer window

Posted: Tue Apr 16, 2024 4:44 pm
by firace
I'm glad to see that you still have your gigantic collection of crazy GIFs :D

Re: Modify explorer window

Posted: Tue Apr 16, 2024 5:07 pm
by Kwai chang caine
:lol: :lol: :lol:
Thanks a lot for your compliment, it touches me deeply especially coming to one of my MASTER heroes 8)

All my collection and mainly my little software, only created for manage all my numerous childrens :mrgreen:

Image