AutoHotkey Community

It is currently May 26th, 2012, 10:33 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 40 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: August 26th, 2009, 5:51 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
My mistake. Icons aren't GDI objects at all, but user objects... :)

I found this interesting:
Quote:
There are actually two different ways to access resources under Windows NT—one in which the resource resides in the server process and one in which it resides in the client. To exemplify the first case, let's assume your application calls LoadIcon and passes the returned handle on to application B, which then calls DrawIcon on that handle. Guess what? Works fine. Just like under Windows 3.1. This seems to be strange at first glance because the two applications have disjoint address spaces, so how can the target application see something that the source application loaded?

Note that you cannot do much more with that handle. In particular, you cannot get your hands on the memory that describes the icon because the handle has no meaning whatsoever to either your application or application B. It is a handle local to the server part of the Win32 subsystem. DrawIcon eventually executes in the server part as well, and thus it knows how to interpret the handle. In this case, the icon is a real object in the strict sense of the word: The handle is a true magic cookie without any meaning to anyone except for the operations that are allowed on it (such as DrawIcon).


Source: Give Me a Handle, and I'll Show You an Object

Apparently GDI object handles are (also) essentially global, but each object has a process ID associated with it for validation; i.e. they aren't portable. This excludes stock objects, which are shared.

(Sorry, I realise this is really off-topic.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2009, 8:28 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Thanks for explanations.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2009, 3:11 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I missunderstood something about this function, it sometimes failed because I was calling SendMessage 2 times as I thought big icon is for the taskbar. Instead, its for ALT TAB window. In 1.0b it should work correctly and Flag=2 is gone as on XP using Flag=1 sets icon on all 3 places...

However, I am confused about this sample:

Code:
   #persistent
   Run, Notepad
   Sleep 1000
   hNotepad := WinExist("Untitled")

   Win_SetIcon( hNotepad, "icon.ico")
   sleep 2000
   hOld := Win_SetIcon( hNotepad, "cd.ico")
   Sleep 2000
   Win_SetIcon( hNotepad, hOld )   
   Sleep 2000
   Win_SetIcon( hNotepad )    ;doesn't remove taskbar icon...
return

Win_SetIcon( Hwnd, Icon="", Flag=1){
   static WM_SETICON = 0x80, LR_LOADFROMFILE=0x10, IMAGE_ICON=1

   if Flag not in 0,1
      return A_ThisFunc "> Unsupported Flag: " Flag

   if Icon !=
      hIcon := Icon+0 != "" ? Icon : DllCall("LoadImage", "Uint", 0, "str", Icon, "uint",IMAGE_ICON, "int", 32, "int", 32, "uint", LR_LOADFROMFILE) 

   SendMessage, WM_SETICON, %Flag%, hIcon, , ahk_id %Hwnd%
   return ErrorLevel
}


It correctly sets up all 3 icons but removal restores only titlebar icon while taskbar icon remains. Prolly something about the thing Lexikos quoted.

Also, its strange that on XP everything works like expected (apart from mentioned removal), while on Vista ALT TAB icon disappears.

In 1.0b I added option to pass icon handle.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 5:00 pm 
Offline

Joined: November 3rd, 2008, 5:13 am
Posts: 12
Interesting experiments and info... I can confirm the Taskbar icon cannot be removed in XP SP3... its the only one who actually stays with Lexicos' SendMessage method (the window icons gets blank after more or less 20 seconds)... so they may be something different for the taskbar

But for what I needed works great. It even works with "Minimize to Tray" tools (show the new icon in the system tray)

The app to change icons dinamically may be easier than I thought... something like:

Code:
#Persistent
SetBatchLines, -1

; Taken from http://www.autohotkey.com/forum/viewtopic.php?t=8795&start=285
Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
{
   If ( wParam = 1 ) ;  HSHELL_WINDOWCREATED := 1
   {
   WinGetTitle, Title, ahk_id %lParam%
   If  ( Title = "Wavosaur" )
      Win_SetIcon( lParam, "C:\Wavosaur.ico")
   If  ( Title = "Irfanview" )
      Win_SetIcon( lParam, "C:\IrfanView.ico")     
   }
}

Win_SetIcon( Hwnd, Icon="", Flag=1){
   static WM_SETICON = 0x80, LR_LOADFROMFILE=0x10, IMAGE_ICON=1

   if Flag not in 0,1
      return A_ThisFunc "> Unsupported Flag: " Flag

   if Icon !=
      hIcon := Icon+0 != "" ? Icon : DllCall("LoadImage", "Uint", 0, "str", Icon, "uint",IMAGE_ICON, "int", 32, "int", 32, "uint", LR_LOADFROMFILE) 

   SendMessage, WM_SETICON, %Flag%, hIcon, , ahk_id %Hwnd%
   return ErrorLevel
}


Missing some cleanup and a configuration GUI... :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 5:05 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Very nice example m8. Ill make a note about it on the first page.

Thank you.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 6:32 pm 
Offline

Joined: November 3rd, 2008, 5:13 am
Posts: 12
Quote:
Ill make a note about it on the first page.


Great.. and I forgot to say thanks for the module.. the animate win function will also be really handy to some sliding dock windows script I am working on...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 1:11 am 
Offline

Joined: July 12th, 2009, 9:52 pm
Posts: 71
Hi there.Am a noob so please do not laugh at my stupid question.

normally, to minimise a window, we use winminimise, <title of window>

but how do we use winanimate using your script? thank you


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 9:18 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
spazpunt wrote:
normally, to minimise a window, we use winminimise, <title of window>

You use hide flag. Its not 100% the same as minimize but function doesn't allow that. You have example in the docs.


*** version 1.1 ***
+ Recall function added. Store & recall window position, size and/or state for AHK and 3td party windows.
+ Recall samples added. _Recall.ahk demonstrates how to save and recall AHK Guis, _RecallShellHook.ahk demonstrates how to recall 3td party window placement when its created.
+ Win_Animate docs update.


Check out animated gif to see Recall in action.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2009, 9:48 am 
Offline

Joined: June 17th, 2008, 7:51 am
Posts: 243
majkinetor wrote:


Check out animated gif to see Recall in action.
Hi majkinetor,
thanks for that animated gif. Now also I understand what you mean with your function :)

Instead of making an animated gif I recommend using Wink. It's fatastic for making some demos. And it's free.

_________________
Greetings
Rog


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2009, 11:53 pm 
Offline

Joined: February 2nd, 2009, 2:03 pm
Posts: 112
This is way too complicated for me, maybe someone can help?
I needed help sliding a splashimage from the down right corner of the screen,
And how can I set speed of sliding? and time of disappearing?

I tried this but nothing works except for the image to show and go lol

Code:
#SingleInstance force
#NoEnv
#Persistent
SetTitleMatchMode, 2
DetectHiddenWindows, on
#Include C:\Users\Administrator\Desktop\New Folder\Win.ahk


F3::
SplashImage, D:\Pictures\Stuff\Untitled.jpg
Win_Animate(hWnd, "slide", 500)
Sleep, 2000
SplashImage, off
Return
#X::Exitapp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2009, 12:14 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
With SplashImage you may set WinTitle, then you'll be
able to retrieve SplahImage window's handle (hWnd).

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2009, 8:33 am 
ballyhairs wrote:
Code:
#SingleInstance force
#NoEnv
#Persistent
SetTitleMatchMode, 2
DetectHiddenWindows, on
#Include C:\Users\Administrator\Desktop\New Folder\Win.ahk


F3::
SplashImage, D:\Pictures\Stuff\Untitled.jpg,xyz ;set the windowtitle to xyz
WinGet ,hWnd,ID,xyz ;get the handle of the window and store it in hWnd
Win_Animate(hWnd, "slide", 500)
Sleep, 2000
SplashImage, off
Return
#X::Exitapp


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2009, 10:00 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
*** version 1.2 ***
+ SetCaption
+ ShowSysMenu

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2009, 10:19 pm 
Offline

Joined: February 2nd, 2009, 2:03 pm
Posts: 112
Is there any chance you can provide few working examples for those who are not advanced enough?
Like a real working example


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2009, 11:29 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Code:
Run, Notepad
sleep 1000
Win_SetCaption(WinExist("Untitled"))
Win_ShowSysMenu(WinExist("Untitled"))

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 40 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], Cristi®, jrav and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group