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 ];
}
}
}
|
|