Mercurial > dwindows
changeset 544:536b32eb0cb0
Committed Icon code from Mark.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 04 Apr 2004 01:58:48 +0000 |
parents | 8217ee5c254e |
children | 11e3d5e3543c |
files | win/dw.c |
diffstat | 1 files changed, 55 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/win/dw.c Sat Apr 03 06:52:12 2004 +0000 +++ b/win/dw.c Sun Apr 04 01:58:48 2004 +0000 @@ -4540,6 +4540,8 @@ HWND tmp; BubbleButton *bubble; HBITMAP hbitmap = 0; + HANDLE icon = 0; + int windowtype = 0, len; char *file = malloc(strlen(filename) + 5); if(!file || !(bubble = calloc(1, sizeof(BubbleButton)))) @@ -4549,10 +4551,53 @@ return 0; } + strcpy(file, filename); + + /* check if we can read from this file (it exists and read permission) */ + if(access(file, 04) == 0) + { + len = strlen( file ); + if ( len < 4 ) + { + free(file); + return 0; + } + if ( stricmp( file + len - 4, ".ico" ) == 0 ) + { + icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); + windowtype = BS_ICON; + } + else if ( stricmp( file + len - 4, ".bmp" ) == 0 ) + { + hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); + windowtype = BS_BITMAP; + } + } + else + { + /* Try with .ico extension first...*/ + strcat(file, ".ico"); + if(access(file, 04) == 0) + { + icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); + windowtype = BS_ICON; + } + else + { + strcpy(file, filename); + strcat(file, ".bmp"); + if(access(file, 04) == 0) + { + hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); + windowtype = BS_BITMAP; + } + } + } + tmp = CreateWindow(BUTTONCLASSNAME, "", WS_CHILD | BS_PUSHBUTTON | - BS_BITMAP | WS_CLIPCHILDREN | + windowtype | WS_CLIPCHILDREN | WS_VISIBLE, 0,0,2000,1000, DW_HWND_OBJECT, @@ -4567,24 +4612,18 @@ SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); - strcpy(file, filename); - - /* check if we can read from this file (it exists and read permission) */ - if(access(file, 04) == 0) - hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); - else - { - /* Try with .bmp extention */ - strcat(file, ".bmp"); - if(access(file, 04) == 0) - hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); - } - - - if(hbitmap) + if(icon) + { + SendMessage(tmp, BM_SETIMAGE, + (WPARAM) IMAGE_ICON, + (LPARAM) icon); + } + else if(hbitmap) + { SendMessage(tmp, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap); + } free(file); return tmp; }