diff win/dw.c @ 257:9ea4ac9a097f

Added dw_icon_load_from_file() on OS/2 and Windows. Added a stub on Unix to be filled in shortly.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 20 Feb 2003 20:19:09 +0000
parents 0f9a185deeb6
children bf8b907f8a29
line wrap: on
line diff
--- a/win/dw.c	Thu Feb 20 17:55:56 2003 +0000
+++ b/win/dw.c	Thu Feb 20 20:19:09 2003 +0000
@@ -5855,6 +5855,39 @@
 }
 
 /*
+ * Obtains an icon from a file.
+ * Parameters:
+ *       filename: Name of the file, omit extention to have
+ *                 DW pick the appropriate file extension.
+ *                 (ICO on OS/2 or Windows, XPM on Unix)
+ */
+unsigned long API dw_icon_load_from_file(char *filename)
+{
+	char *file = malloc(strlen(filename) + 5);
+	HANDLE icon;
+
+	if(!file)
+		return 0;
+
+	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, ".ico");
+		if(access(file, 04) != 0)
+		{
+			free(file);
+			return 0;
+		}
+	}
+	icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
+	free(file);
+	return (unsigned long)icon;
+}
+
+/*
  * Frees a loaded resource in OS/2 and Windows.
  * Parameters:
  *          handle: Handle to icon returned by dw_icon_load().