Mercurial > dwindows
comparison win/dw.c @ 242:36013ddd3f5b
Fixes for Windows code.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 19 Feb 2003 06:23:59 +0000 |
parents | 00d2b1bcf036 |
children | 3c1e39905f2f |
comparison
equal
deleted
inserted
replaced
241:00d2b1bcf036 | 242:36013ddd3f5b |
---|---|
6696 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) | 6696 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) |
6697 { | 6697 { |
6698 HPIXMAP pixmap; | 6698 HPIXMAP pixmap; |
6699 BITMAP bm; | 6699 BITMAP bm; |
6700 HDC hdc; | 6700 HDC hdc; |
6701 char *file = alloca(strlen(filename) + 5); | 6701 SIZE sz; |
6702 char *file = malloc(strlen(filename) + 5); | |
6702 | 6703 |
6703 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 6704 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
6705 { | |
6706 if(file) | |
6707 free(file); | |
6704 return NULL; | 6708 return NULL; |
6709 } | |
6705 | 6710 |
6706 strcpy(file, filename); | 6711 strcpy(file, filename); |
6707 | 6712 |
6708 /* check if we can read from this file (it exists and read permission) */ | 6713 /* check if we can read from this file (it exists and read permission) */ |
6709 if(access(file, 04) != 0) | 6714 if(access(file, 04) != 0) |
6711 /* Try with .bmp extention */ | 6716 /* Try with .bmp extention */ |
6712 strcat(file, ".bmp"); | 6717 strcat(file, ".bmp"); |
6713 if(access(file, 04) != 0) | 6718 if(access(file, 04) != 0) |
6714 { | 6719 { |
6715 free(pixmap); | 6720 free(pixmap); |
6721 free(file); | |
6716 return NULL; | 6722 return NULL; |
6717 } | 6723 } |
6718 } | 6724 } |
6719 | 6725 |
6720 dc = GetDC(handle); | 6726 hdc = GetDC(handle); |
6721 | |
6722 pixmap->width = width; pixmap->height = height; | |
6723 | 6727 |
6724 pixmap->handle = handle; | 6728 pixmap->handle = handle; |
6725 pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); | 6729 pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); |
6730 | |
6731 if(!pixmap->hbm) | |
6732 { | |
6733 free(file); | |
6734 free(pixmap); | |
6735 ReleaseDC(handle, hdc); | |
6736 return NULL; | |
6737 } | |
6738 | |
6726 pixmap->hdc = CreateCompatibleDC(hdc); | 6739 pixmap->hdc = CreateCompatibleDC(hdc); |
6727 | 6740 |
6741 GetBitmapDimensionEx(pixmap->hbm, &sz); | |
6742 | |
6743 pixmap->width = sz.cx; pixmap->height = sz.cy; | |
6744 | |
6728 SelectObject(pixmap->hdc, pixmap->hbm); | 6745 SelectObject(pixmap->hdc, pixmap->hbm); |
6729 | 6746 |
6730 ReleaseDC(handle, hdc); | 6747 ReleaseDC(handle, hdc); |
6748 | |
6749 free(file); | |
6731 | 6750 |
6732 return pixmap; | 6751 return pixmap; |
6733 } | 6752 } |
6734 | 6753 |
6735 /* | 6754 /* |