comparison win/dw.c @ 303:464b5e46b313

Create the bitmap button even if the bitmap file does not exist.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 28 Mar 2003 21:19:07 +0000
parents 887675ee5b67
children 324587c06cea
comparison
equal deleted inserted replaced
302:7c1770e3fe08 303:464b5e46b313
4220 */ 4220 */
4221 HWND dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) 4221 HWND dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename)
4222 { 4222 {
4223 HWND tmp; 4223 HWND tmp;
4224 BubbleButton *bubble; 4224 BubbleButton *bubble;
4225 HBITMAP hbitmap; 4225 HBITMAP hbitmap = 0;
4226 char *file = malloc(strlen(filename) + 5); 4226 char *file = malloc(strlen(filename) + 5);
4227 4227
4228 if(!file || !(bubble = calloc(1, sizeof(BubbleButton)))) 4228 if(!file || !(bubble = calloc(1, sizeof(BubbleButton))))
4229 { 4229 {
4230 if(file) 4230 if(file)
4231 free(file); 4231 free(file);
4232 return 0; 4232 return 0;
4233 } 4233 }
4234
4235 strcpy(file, filename);
4236
4237 /* check if we can read from this file (it exists and read permission) */
4238 if(access(file, 04) != 0)
4239 {
4240 /* Try with .bmp extention */
4241 strcat(file, ".bmp");
4242 if(access(file, 04) != 0)
4243 {
4244 free(bubble);
4245 free(file);
4246 return 0;
4247 }
4248 }
4249
4250 hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
4251 4234
4252 tmp = CreateWindow(BUTTONCLASSNAME, 4235 tmp = CreateWindow(BUTTONCLASSNAME,
4253 "", 4236 "",
4254 WS_CHILD | BS_PUSHBUTTON | 4237 WS_CHILD | BS_PUSHBUTTON |
4255 BS_BITMAP | WS_CLIPCHILDREN | 4238 BS_BITMAP | WS_CLIPCHILDREN |
4265 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; 4248 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
4266 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); 4249 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc);
4267 4250
4268 SetWindowLong(tmp, GWL_USERDATA, (ULONG)bubble); 4251 SetWindowLong(tmp, GWL_USERDATA, (ULONG)bubble);
4269 4252
4270 SendMessage(tmp, BM_SETIMAGE, 4253 strcpy(file, filename);
4271 (WPARAM) IMAGE_BITMAP, 4254
4272 (LPARAM) hbitmap); 4255 /* check if we can read from this file (it exists and read permission) */
4256 if(access(file, 04) == 0)
4257 hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
4258 else
4259 {
4260 /* Try with .bmp extention */
4261 strcat(file, ".bmp");
4262 if(access(file, 04) == 0)
4263 hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
4264 }
4265
4266
4267 if(hbitmap)
4268 SendMessage(tmp, BM_SETIMAGE,
4269 (WPARAM) IMAGE_BITMAP,
4270 (LPARAM) hbitmap);
4273 free(file); 4271 free(file);
4274 return tmp; 4272 return tmp;
4275 } 4273 }
4276 4274
4277 /* 4275 /*