diff 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
line wrap: on
line diff
--- a/win/dw.c	Tue Feb 18 21:45:32 2003 +0000
+++ b/win/dw.c	Wed Feb 19 06:00:54 2003 +0000
@@ -6684,6 +6684,55 @@
 }
 
 /*
+ * Creates a pixmap from a file.
+ * Parameters:
+ *       handle: Window handle the pixmap is associated with.
+ *       filename: Name of the file, omit extention to have
+ *                 DW pick the appropriate file extension.
+ *                 (BMP on OS/2 or Windows, XPM on Unix)
+ * Returns:
+ *       A handle to a pixmap or NULL on failure.
+ */
+HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename)
+{
+	HPIXMAP pixmap;
+	BITMAP bm;
+	HDC hdc;
+	char *file = alloca(strlen(filename) + 5);
+
+	if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap))))
+		return NULL;
+
+	strcpy(file, filename);
+
+	/* check if we can read from this file (it exists and read permission) */
+	if(access(file, 04) != 0)
+	{
+		/* Try with .bmp extention */
+		strcat(file, ".bmp");
+		if(access(file, 04) != 0)
+		{
+			free(pixmap);
+			return NULL;
+		}
+	}
+
+	dc = GetDC(handle);
+
+	pixmap->width = width; pixmap->height = height;
+
+	pixmap->handle = handle;
+	pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
+	pixmap->hdc = CreateCompatibleDC(hdc);
+
+	SelectObject(pixmap->hdc, pixmap->hbm);
+
+	ReleaseDC(handle, hdc);
+
+	return pixmap;
+}
+
+/*
  * Creates a pixmap from internal resource graphic specified by id.
  * Parameters:
  *       handle: Window handle the pixmap is associated with.