matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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.
|
|