AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bringing window to foreground after removing from taskbar

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
HugoTheGuest
Guest





PostPosted: Tue Feb 02, 2010 4:35 am    Post subject: Bringing window to foreground after removing from taskbar Reply with quote

Hi guys,

I'm currently writing a bit of code to modify a third-party application (an instant messenger) that's stored in the system tray. When you click it, a buddy list window opens. Unfortunately, this window appears in the taskbar, but shouldn't, so I read through this thread to remove it from there. There are actually two ways to remove the window from the taskbar:
- Make it a toolwindow or
- Make it the child of an invisible process

First I tried the first approach, but failed because each time I click the tray icon of that application again, the window appears in usual window style and, of course, also in the taskbar. So I set up a timer to look for the window continuously and set the toolwindow style, but that had two bad effects:
- it took some time to update the style, so the window always popped up in the taskbar for a short moment
- I couldn't manage to get it right so it doesn't show the window when it's hidden... that made the window start flashing without content...

For interested people, that's the relevant code for this:
Code:

#Persistent
SetTimer, DeleteTaskBarEntry, 100
return

DeleteTaskBarEntry:
   WinWait, Buddy-Liste
   
   if ErrorLevel
   {
   
   }
   else
   {
      WinGet, ExStyle, ExStyle, Buddy-Liste

      if (ExStyle & +0x80)
      {

      }
      else
      {
         DetectHiddenWindows On
         WinHide
         WinSet, ExStyle, +0x80 ; 0x80 is WS_EX_TOOLWINDOW
         WinShow
      }
   }
return


So after some time I tried the second approach that looked much more satisfying after a short time. The window gets deleted from the taskbar just as I wanted to, and additionally, it doesn't show up in the taskbar for a short time. But unfortunately, I'm lost again because there is some strange behavior in that approach that was discussed in the thread I linked as well. That's the relevant code (just for testing purpose, it's in a timer loop like the other approach in the real version):

Code:
F12::
   WinGet, hw_notepad, ID, Unbenannt - Editor

   if hw_notepad=
   {
         
   }
   else
   {
      hw_parent := DllCall("GetParent", "uint", hw_notepad)
      WinGet, hw_progman, ID, Program Manager ahk_class Progman
      DllCall("SetParent", "uint", hw_notepad, "uint", hw_progman)
   }
return


No matter what programm you use to test this, the window is always in the background and - sadly - stays there. My actual question now is: How do I bring that window from the background to the foreground? I tried a lot of things now (maybe I just used them wrong?), but none worked: WinActivate, SetWindowPos, SetForegroundWindow, WinHide + WinShow... Sad

Is someone able and willing to help me? I'm not really sticking to that solution, so if my problem (removing the buddy list from the taskbar) can be solved in another way without these disturbing issues, please feel free to tell me.

Thanks =)
Back to top
HugoTheGuest
Guest





PostPosted: Fri Feb 05, 2010 10:22 am    Post subject: :( Reply with quote

Guys, does really noone have an idea? I know it's annoying to selfbumb unanswered threads to the top again, but... well I don't know how to finish this sentence... yeah, it's lame, but, please!, help me Smile
Back to top
gark
Guest





PostPosted: Mon Mar 15, 2010 1:14 pm    Post subject: Reply with quote

i have the same problem, so far i have not figured it out...
Back to top
Guest






PostPosted: Mon Mar 15, 2010 3:03 pm    Post subject: Reply with quote

If you pin your window to the desktop (by setting the parent program manager )you can't have it on top! You can not have it both ways!!
Back to top
closed



Joined: 07 Feb 2008
Posts: 509

PostPosted: Tue Mar 16, 2010 3:36 pm    Post subject: Reply with quote

You can use Sean's program to remove the taskbutton and then use WinActivate if you need.But i only tried it in winXP

Maybe the title is misleading but the downloaded zipfile also contains taskbutton.ahk and trayicon.ahk so it works on both trayicons and taskbuttons.

http://www.autohotkey.com/forum/topic17314.html




I used this once to play with notepad program,it will hide then show the button (if notepad is running!)



Code:
DetectHiddenWindows, On

; see source of this program here http://www.autohotkey.com/forum/topic17314.html 

program=notepad.exe  ;procesname program to remove taskbar button (can be pid also)


data:= TaskButtons(program)
pos:=regexmatch(data,"\| idn:( \d+ )\|",idn)
idxTB:=   GetTaskSwBar()
SendMessage, 0x404, idn1, true, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd
sleep 5000
SendMessage, 0x404, idn1, false, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd

Return







TaskButtons(sExeName = "")
{
   WinGet,   pidTaskbar, PID, ahk_class Shell_TrayWnd
   hProc:=   DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
   pProc:=   DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
   idxTB:=   GetTaskSwBar()
      SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
   Loop,   %ErrorLevel%
   {
      SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_GETBUTTON
      VarSetCapacity(btn,32,0)
      DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
         iBitmap   := NumGet(btn, 0)
         idn   := NumGet(btn, 4)
         Statyle := NumGet(btn, 8)
      If   dwData   := NumGet(btn,12)
         iString   := NumGet(btn,16)
      Else   dwData   := NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
      DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "int64P", hWnd:=0, "Uint", NumGet(btn,12) ? 4:8, "Uint", 0)
      If Not   hWnd
         Continue
      WinGet, pid, PID,              ahk_id %hWnd%
      WinGet, sProcess, ProcessName, ahk_id %hWnd%
      WinGetClass, sClass,           ahk_id %hWnd%
      If !sExeName || (sExeName = sProcess) || (sExeName = pid)
         VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
      ,   DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
      ,   DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
      ,   sTaskButtons .= "idx: " . A_Index-1 . " | idn: " . idn . " | pid: " . pid . " | hWnd: " . hWnd . " | Class: " . sClass . " | Process: " . sProcess . "`n" . "   | Tooltip: " . sTooltip . "`n"
   }
   DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
   DllCall("CloseHandle", "Uint", hProc)
   Return   sTaskButtons
}


GetTaskSwBar()
{
   ControlGet, hParent, hWnd,, MSTaskSwWClass1 , ahk_class Shell_TrayWnd
   ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
   Loop
   {
      ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
      If  Not   hWnd
         Break
      Else If   hWnd = %hChild%
      {
         idxTB := A_Index
         Break
      }
   }
   Return   idxTB
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group