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:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [REQ/HELP] Display Picture as Window Icon
That is an interesting idea. Only thought is that at 16x16 pixels you wont be able to see the image that well considering the original is 96x96...

Anyways it will look something like this...

Untested as I am at work!
js code:
var objChatWnds = {};

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 );
            Interop.Call ( 'gdiplus' , 'GdipCreateHICONFromBitmap' , hImage , hIcon );
            objChatWnds [ oChatWnd ] = hIcon;
            Interop.Call( 'user32' , 'SendMessageW' , oChatWd.Handle , 0x80 /* WM_SETICON */ , 0 /* ICON_SMALL */ , hIcon );
            Interop.Call( 'user32' , 'SendMessageW' , oChatWd.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' , oChatWd.Handle , 0x80 /* WM_SETICON */ , 0 /* ICON_SMALL */ , 0 );
            Interop.Call( 'user32' , 'SendMessageW' , oChatWd.Handle , 0x80 /* WM_SETICON */ , 1 /* ICON_SMALL */ , 0 );
            Interop.Call ( 'user32' , 'DestroyIcon' , objChatWnds [ oChatWnd.Handle ] );
            delete objChatWnds [ oChatWnd.Handle ];
        }
    }
}

If the image needs to be resized that isn't a problem. Just need to use the GdipGetImageThumbnail call.

This is from Screenshot Sender 5:

js code:
"CreateThumbnail" : function (hPicture) {
        var ImageThumb = Interop.Allocate(4);
        var lBitmap = Interop.Allocate(4);
        var hbmBitmap = Interop.Allocate(4);
        Interop.Call('gdiplus', 'GdipCreateBitmapFromHBITMAP', hPicture, 0, lBitmap)
        Interop.Call('gdiplus', 'GdipGetImageThumbnail', lBitmap.ReadDWORD(0), 100, this.ImageHeight/(this.ImageWidth/100), ImageThumb.DataPtr, 0, 0);
        Interop.Call('gdiplus', 'GdipCreateHBITMAPFromBitmap', ImageThumb.ReadDWORD(0), hbmBitmap, 0x00000000);
        return  hbmBitmap.ReadDWORD(0);
    }

This post was edited on 10-05-2009 at 02:55 PM by matty.
10-05-2009 02:05 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