What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [REQ/HELP] Display Picture as Window Icon

[REQ/HELP] Display Picture as Window Icon
Author: Message:
NoWhereMan
Junior Member
**


Posts: 25
Joined: Oct 2009
O.P. RE: [REQ/HELP] Display Picture as Window Icon
Here's an updated version with an (optional) fixed size 16x16 thumb; unfortunately, neither calling it or not calling it seems to be able to make it work :/ (the icon is only cleared)

thank you a lot for your help, though :)

note: with the 32x32 or 48x48 icon available the avatar would be displayed on alt-tab too (and eventually on docks if you have one)

Javascript code:
var objChatWnds = {};
 
function getThumbnailFromPic(hPicture) {
        var ImageThumb = Interop.Allocate(4);
        var lBitmap = Interop.Allocate(4);
        var hbmBitmap = Interop.Allocate(4);
        Interop.Call('gdiplus', 'GdipCreateBitmapFromHBITMAP', hPicture, 0, lBitmap); /* 100, this.ImageHeight/(this.ImageWidth/100), */
        Interop.Call('gdiplus', 'GdipGetImageThumbnail', lBitmap.ReadDWORD(0), 16, 16, ImageThumb.DataPtr, 0, 0);
        Interop.Call('gdiplus', 'GdipCreateHBITMAPFromBitmap', ImageThumb.ReadDWORD(0), hbmBitmap, 0x00000000);
        return  hbmBitmap.ReadDWORD(0);
}
 
function setDpAsIcon ( sDpLocation , oChatWnd ) {
    var GdipToken = Interop.Allocate ( 4 );
    var GdipStartupInput = Interop.Allocate ( 16 );
        GdipStartupInput.WriteDWORD( 0 , 1 );
       
    var bInitialized = Interop.Call( 'gdiplus' , 'GdiplusStartup' , GdipToken , GdipStartupInput , 0 ) === 0;
   
    if ( bInitialized === true ) {
        var nImgPtr = Interop.Allocate ( 4 );
        Interop.Call( 'gdiplus' , 'GdipLoadImageFromFile' , sDpLocation , nImgPtr );
        var hImage = nImgPtr.ReadDWORD ( 0 ) !== 0 ? nImgPtr.ReadDWORD ( 0 ) : false;
       
        if ( hImage !== false ) {
            var hIcon = Interop.Allocate ( 4 );
 
            // uncomment for thumb:
            // hImage = getThumbnailFromPic(hImage);
           
            Interop.Call ( 'gdiplus' , 'GdipCreateHICONFromBitmap' , hImage , hIcon );
            objChatWnds [ oChatWnd.Handle ] = hIcon;
            Interop.Call( 'user32' , 'SendMessageW' , oChatWnd.Handle , 0x80 /* WM_SETICON */ , 0 /* ICON_SMALL */ , hIcon );
            Interop.Call( 'user32' , 'SendMessageW' , oChatWnd.Handle , 0x80 /* WM_SETICON */ , 1 /* ICON_BIG */ , hIcon );
        }
    }
    Interop.Call( 'gdiplus' , 'GdiplusShutdown' , GdipToken.ReadDWORD ( 0 ) );
}
 
function OnEvent_ChatWndCreated ( oChatWnd ) {
    if ( oChatWnd.Contacts.Count === 1 ) {
        for ( var oContact = new Enumerator ( oChatWnd.Contacts ); !oContact.atEnd ( ); oContact.moveNext ( ) ) {
            setDpAsIcon ( oContact.item( ).DisplayPicture , oChatWnd );
        }
    }
}
 
function OnEvent_ChatWndDestroyed ( oChatWnd ) {
    if ( typeof objChatWnds [ oChatWnd.Handle ] === 'object ' ) {
        if ( oChatWnd.Contacts.Count === 1 ) {
            Interop.Call( 'user32' , 'SendMessageW' , oChatWnd.Handle , 0x80 /* WM_SETICON */ , 0 /* ICON_SMALL */ , 0 );
            Interop.Call( 'user32' , 'SendMessageW' , oChatWnd.Handle , 0x80 /* WM_SETICON */ , 1 /* ICON_SMALL */ , 0 );
            Interop.Call ( 'user32' , 'DestroyIcon' , objChatWnds [ oChatWnd.Handle ] );
            delete objChatWnds [ oChatWnd.Handle ];
        }
    }
}

10-05-2009 03:48 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[REQ/HELP] Display Picture as Window Icon - by NoWhereMan on 10-04-2009 at 02:57 PM
RE: [REQ/HELP] Display Picture as Window Icon - by matty on 10-05-2009 at 02:05 PM
RE: [REQ/HELP] Display Picture as Window Icon - by NoWhereMan on 10-05-2009 at 03:48 PM
RE: [REQ/HELP] Display Picture as Window Icon - by NoWhereMan on 10-05-2009 at 04:46 PM
RE: [REQ/HELP] Display Picture as Window Icon - by Matti on 10-05-2009 at 05:26 PM
RE: [REQ/HELP] Display Picture as Window Icon - by matty on 10-05-2009 at 05:31 PM
RE: [REQ/HELP] Display Picture as Window Icon - by NoWhereMan on 10-05-2009 at 05:47 PM
RE: [REQ/HELP] Display Picture as Window Icon - by ryxdp on 10-06-2009 at 01:35 AM
RE: [REQ/HELP] Display Picture as Window Icon - by NoWhereMan on 10-06-2009 at 06:26 AM
RE: RE: [REQ/HELP] Display Picture as Window Icon - by ryxdp on 10-06-2009 at 07:19 AM
RE: [REQ/HELP] Display Picture as Window Icon - by Matti on 10-06-2009 at 02:55 PM
RE: [REQ/HELP] Display Picture as Window Icon - by NoWhereMan on 10-06-2009 at 03:26 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On