Mercurial > dwindows
comparison win/dw.c @ 544:536b32eb0cb0
Committed Icon code from Mark.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 04 Apr 2004 01:58:48 +0000 |
parents | a95f39e81fe2 |
children | d940dc1ff462 |
comparison
equal
deleted
inserted
replaced
543:8217ee5c254e | 544:536b32eb0cb0 |
---|---|
4538 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) | 4538 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) |
4539 { | 4539 { |
4540 HWND tmp; | 4540 HWND tmp; |
4541 BubbleButton *bubble; | 4541 BubbleButton *bubble; |
4542 HBITMAP hbitmap = 0; | 4542 HBITMAP hbitmap = 0; |
4543 HANDLE icon = 0; | |
4544 int windowtype = 0, len; | |
4543 char *file = malloc(strlen(filename) + 5); | 4545 char *file = malloc(strlen(filename) + 5); |
4544 | 4546 |
4545 if(!file || !(bubble = calloc(1, sizeof(BubbleButton)))) | 4547 if(!file || !(bubble = calloc(1, sizeof(BubbleButton)))) |
4546 { | 4548 { |
4547 if(file) | 4549 if(file) |
4548 free(file); | 4550 free(file); |
4549 return 0; | 4551 return 0; |
4550 } | 4552 } |
4551 | 4553 |
4554 strcpy(file, filename); | |
4555 | |
4556 /* check if we can read from this file (it exists and read permission) */ | |
4557 if(access(file, 04) == 0) | |
4558 { | |
4559 len = strlen( file ); | |
4560 if ( len < 4 ) | |
4561 { | |
4562 free(file); | |
4563 return 0; | |
4564 } | |
4565 if ( stricmp( file + len - 4, ".ico" ) == 0 ) | |
4566 { | |
4567 icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); | |
4568 windowtype = BS_ICON; | |
4569 } | |
4570 else if ( stricmp( file + len - 4, ".bmp" ) == 0 ) | |
4571 { | |
4572 hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); | |
4573 windowtype = BS_BITMAP; | |
4574 } | |
4575 } | |
4576 else | |
4577 { | |
4578 /* Try with .ico extension first...*/ | |
4579 strcat(file, ".ico"); | |
4580 if(access(file, 04) == 0) | |
4581 { | |
4582 icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); | |
4583 windowtype = BS_ICON; | |
4584 } | |
4585 else | |
4586 { | |
4587 strcpy(file, filename); | |
4588 strcat(file, ".bmp"); | |
4589 if(access(file, 04) == 0) | |
4590 { | |
4591 hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); | |
4592 windowtype = BS_BITMAP; | |
4593 } | |
4594 } | |
4595 } | |
4596 | |
4552 tmp = CreateWindow(BUTTONCLASSNAME, | 4597 tmp = CreateWindow(BUTTONCLASSNAME, |
4553 "", | 4598 "", |
4554 WS_CHILD | BS_PUSHBUTTON | | 4599 WS_CHILD | BS_PUSHBUTTON | |
4555 BS_BITMAP | WS_CLIPCHILDREN | | 4600 windowtype | WS_CLIPCHILDREN | |
4556 WS_VISIBLE, | 4601 WS_VISIBLE, |
4557 0,0,2000,1000, | 4602 0,0,2000,1000, |
4558 DW_HWND_OBJECT, | 4603 DW_HWND_OBJECT, |
4559 (HMENU)id, | 4604 (HMENU)id, |
4560 DWInstance, | 4605 DWInstance, |
4565 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; | 4610 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; |
4566 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | 4611 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); |
4567 | 4612 |
4568 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); | 4613 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); |
4569 | 4614 |
4570 strcpy(file, filename); | 4615 if(icon) |
4571 | 4616 { |
4572 /* check if we can read from this file (it exists and read permission) */ | 4617 SendMessage(tmp, BM_SETIMAGE, |
4573 if(access(file, 04) == 0) | 4618 (WPARAM) IMAGE_ICON, |
4574 hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); | 4619 (LPARAM) icon); |
4575 else | 4620 } |
4576 { | 4621 else if(hbitmap) |
4577 /* Try with .bmp extention */ | 4622 { |
4578 strcat(file, ".bmp"); | |
4579 if(access(file, 04) == 0) | |
4580 hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); | |
4581 } | |
4582 | |
4583 | |
4584 if(hbitmap) | |
4585 SendMessage(tmp, BM_SETIMAGE, | 4623 SendMessage(tmp, BM_SETIMAGE, |
4586 (WPARAM) IMAGE_BITMAP, | 4624 (WPARAM) IMAGE_BITMAP, |
4587 (LPARAM) hbitmap); | 4625 (LPARAM) hbitmap); |
4626 } | |
4588 free(file); | 4627 free(file); |
4589 return tmp; | 4628 return tmp; |
4590 } | 4629 } |
4591 | 4630 |
4592 /* | 4631 /* |