Mercurial > dwindows
comparison win/dw.c @ 241:00d2b1bcf036
Added dw_pixmap_new_from_file().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 19 Feb 2003 06:00:54 +0000 |
parents | 13d3de3f1e83 |
children | 36013ddd3f5b |
comparison
equal
deleted
inserted
replaced
240:afc0d5f5d74f | 241:00d2b1bcf036 |
---|---|
6682 | 6682 |
6683 return pixmap; | 6683 return pixmap; |
6684 } | 6684 } |
6685 | 6685 |
6686 /* | 6686 /* |
6687 * Creates a pixmap from a file. | |
6688 * Parameters: | |
6689 * handle: Window handle the pixmap is associated with. | |
6690 * filename: Name of the file, omit extention to have | |
6691 * DW pick the appropriate file extension. | |
6692 * (BMP on OS/2 or Windows, XPM on Unix) | |
6693 * Returns: | |
6694 * A handle to a pixmap or NULL on failure. | |
6695 */ | |
6696 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) | |
6697 { | |
6698 HPIXMAP pixmap; | |
6699 BITMAP bm; | |
6700 HDC hdc; | |
6701 char *file = alloca(strlen(filename) + 5); | |
6702 | |
6703 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) | |
6704 return NULL; | |
6705 | |
6706 strcpy(file, filename); | |
6707 | |
6708 /* check if we can read from this file (it exists and read permission) */ | |
6709 if(access(file, 04) != 0) | |
6710 { | |
6711 /* Try with .bmp extention */ | |
6712 strcat(file, ".bmp"); | |
6713 if(access(file, 04) != 0) | |
6714 { | |
6715 free(pixmap); | |
6716 return NULL; | |
6717 } | |
6718 } | |
6719 | |
6720 dc = GetDC(handle); | |
6721 | |
6722 pixmap->width = width; pixmap->height = height; | |
6723 | |
6724 pixmap->handle = handle; | |
6725 pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); | |
6726 pixmap->hdc = CreateCompatibleDC(hdc); | |
6727 | |
6728 SelectObject(pixmap->hdc, pixmap->hbm); | |
6729 | |
6730 ReleaseDC(handle, hdc); | |
6731 | |
6732 return pixmap; | |
6733 } | |
6734 | |
6735 /* | |
6687 * Creates a pixmap from internal resource graphic specified by id. | 6736 * Creates a pixmap from internal resource graphic specified by id. |
6688 * Parameters: | 6737 * Parameters: |
6689 * handle: Window handle the pixmap is associated with. | 6738 * handle: Window handle the pixmap is associated with. |
6690 * id: Resource ID associated with requested pixmap. | 6739 * id: Resource ID associated with requested pixmap. |
6691 * Returns: | 6740 * Returns: |