window event if window is invisible...

Just starting out? Need help? Post your questions and find answers here.
GregBUG
User
User
Posts: 16
Joined: Tue Apr 13, 2004 10:02 pm
Location: Italy

window event if window is invisible...

Post by GregBUG »

Hello PB Coders!!

is there a way to detect windows event if a windows is invisible?

if yes how?

ex.

if i open a window...

Code: Select all

Procedure.b OpenWindow_MainForm()
	If OpenWindow(#MainForm, 326, 264, 566, 295, "PenDrive Immunizer", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered);
		QueryCancelAutoPlay = RegisterWindowMessage_("QueryCancelAutoPlay")
   	SetWindowCallback(@WindowCallback())
   	AddSysTrayIcon(1, WindowID(#MainForm), LoadImage(0, "Gfx\pendrive.ico"))
		ProcedureReturn  #True
	Else
		ProcedureReturn #False
	EndIf
EndProcedure
main loop

Code: Select all

If OpenWindow_MainForm()
	Repeat
   	; >>> ATTENDI EVENTO DA UTENTE <<<
  
  		Event = WaitWindowEvent(100)
  		; >>>>>>>>>>>>>>>>>>>>>>>
  
  		; L'Evento generato dal SysTray ?
  		If Event = #PB_Event_SysTray
    		Select EventType()
      		Case #PB_EventType_RightClick ; Click destro sull'icona nella taskbar ?
        		DisplayPopupMenu(0, WindowID(#MainForm)) ;Visualizza il menu...
    		EndSelect
  		EndIf
  
		; Controllo del menu sull'icona....  
  		If Event = #PB_Event_Menu
  			Select EventMenu()
    			Case 1; Quit
      			Quit = 1
    		EndSelect
  		EndIf
  
	Until Event = #PB_Event_CloseWindow Or Quit = 1 
EndIf
if the window is visible the code detect the pen drive if it is inserted in the pc... and the code call the callback procedure...

but if the windows is invisible it not detect the usb pen drive...

how can i solve this problem?

thanks.

please help!.

thanks again.
Ciao Ciao!
GregBUG [Gianluca D'Angelo]
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Maybe more info will shed some light. Can we see your WindowCallback() proc? Which event (message) are you trying to catch? Your code is incomplete and does not run as is.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
GregBUG
User
User
Posts: 16
Joined: Tue Apr 13, 2004 10:02 pm
Location: Italy

Post by GregBUG »

sorry...
this is the source...

i'm trying to catch the usb key....

Code: Select all

EnableExplicit

#MainForm	= 0
#True				= 1
#False				= 0

Global Event.l                = 0
Global Quit.b                  = 0
Global QueryCancelAutoPlay.l

CreatePopupMenu(0)
  MenuItem(1, "Quit")

  Procedure OpenFolderWindow (Folder.s)
  Define OpInfo.s="OPEN"
  ShellExecute_(0, @OpInfo, @Folder, 0, 0, #SW_SHOWDEFAULT)
EndProcedure


Procedure.l WindowCallback(hwnd, message, wParam, lParam)
   Define.l result = #PB_ProcessPureBasicEvents
  	Define n.b
         
   Select message
      Case QueryCancelAutoPlay
         ; è Stato avviato l'autoplay... e noi l'abbiamo fermato....
         ; ora controlliamo le lettere e vediamo se ne sono state aggiunte periferiche rimovibili...
         For n = 2 To 26
    			If RealDriveType_(n, 0) =  #DRIVE_REMOVABLE
      			OpenFolderWindow(Chr(n+65)+":")
         		Break;
         	EndIf
         Next
         result = 1
   EndSelect
  
  ProcedureReturn result
EndProcedure

Procedure.b OpenWindow_MainForm()
	If OpenWindow(#MainForm, 326, 264, 566, 295, "PenDrive Immunizer", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered);|#PB_Window_Invisible)
		QueryCancelAutoPlay = RegisterWindowMessage_("QueryCancelAutoPlay")
   	SetWindowCallback(@WindowCallback())
   	;AddSysTrayIcon(1, WindowID(#MainForm), LoadImage(0, "Gfx\pendrive_disabled.ico"))
		ProcedureReturn  #True
	Else
		ProcedureReturn #False
	EndIf
EndProcedure
	
If OpenWindow_MainForm()
	Repeat
   	; >>> ATTENDI EVENTO DA UTENTE <<<
  
  		Event = WaitWindowEvent(1000)
  		; >>>>>>>>>>>>>>>>>>>>>>>
  
  		; L'Evento generato dal SysTray ?
  		If Event = #PB_Event_SysTray
    		Select EventType()
      		Case #PB_EventType_RightClick ; Click destro sull'icona nella taskbar ?
        		DisplayPopupMenu(0, WindowID(#MainForm)) ;Visualizza il menu...
    		EndSelect
  		EndIf
  
		; Controllo del menu sull'icona....  
  		If Event = #PB_Event_Menu
  			Select EventMenu()
    			Case 1; Quit
      			Quit = 1
    		EndSelect
  		EndIf
  
	Until Event = #PB_Event_CloseWindow Or Quit = 1 
EndIf

SetWindowCallback(0)

End
Ciao Ciao!
GregBUG [Gianluca D'Angelo]
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Apparently that message is only sent to a top-level foreground window, i.e. your window must be visible and active otherwise it will not receive it. I can't check that right now though.

Yes, see here for more info - seems like you need to use COM instead of that window message: http://msdn.microsoft.com/en-us/magazine/cc301341.aspx
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
GregBUG
User
User
Posts: 16
Joined: Tue Apr 13, 2004 10:02 pm
Location: Italy

Post by GregBUG »

tinman wrote:Apparently that message is only sent to a top-level foreground window, i.e. your window must be visible and active otherwise it will not receive it. I can't check that right now though.

Yes, see here for more info - seems like you need to use COM instead of that window message: http://msdn.microsoft.com/en-us/magazine/cc301341.aspx
yes.
RegisterWindowMessage_("QueryCancelAutoPlay")
is only sent top-level foreground window
but i don't know how use COM.

any help? (Docs, src,?)

thanks.
Ciao Ciao!
GregBUG [Gianluca D'Angelo]
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

I don't have any and I don't know how to use COM but I found some C++ code here: http://blog.csdn.net/kuanghong/archive/ ... 13508.aspx
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
GregBUG
User
User
Posts: 16
Joined: Tue Apr 13, 2004 10:02 pm
Location: Italy

Post by GregBUG »

tinman wrote:I don't have any and I don't know how to use COM but I found some C++ code here: http://blog.csdn.net/kuanghong/archive/ ... 13508.aspx
wow thanks!

i'll try to implement in PB.

if i succed i'll post here the source...

thanks again...
Ciao Ciao!
GregBUG [Gianluca D'Angelo]
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re:

Post by Thunder93 »

Have you ever succeeded?
GregBUG wrote:
tinman wrote:I don't have any and I don't know how to use COM but I found some C++ code here: http://blog.csdn.net/kuanghong/archive/ ... 13508.aspx
wow thanks!

i'll try to implement in PB.

if i succed i'll post here the source...

thanks again...
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Post Reply