comparison win/dw.c @ 278:df0665ba147f

Initial code for dw_bitmapbutton_new_from_file and added filename parameter to dw_window_set_bitmap().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 14 Mar 2003 18:03:35 +0000
parents d706e0dbb0cb
children 2f038ef90a36
comparison
equal deleted inserted replaced
277:d706e0dbb0cb 278:df0665ba147f
3941 3941
3942 /* 3942 /*
3943 * Create a new static text window (widget) to be packed. 3943 * Create a new static text window (widget) to be packed.
3944 * Parameters: 3944 * Parameters:
3945 * text: The text to be display by the static text widget. 3945 * text: The text to be display by the static text widget.
3946 * id: An ID to be used with WinWindowFromID() or 0L. 3946 * id: An ID to be used with dw_window_from_id() or 0L.
3947 */ 3947 */
3948 HWND API dw_text_new(char *text, ULONG id) 3948 HWND API dw_text_new(char *text, ULONG id)
3949 { 3949 {
3950 HWND tmp = CreateWindow(STATICCLASSNAME, 3950 HWND tmp = CreateWindow(STATICCLASSNAME,
3951 text, 3951 text,
3962 3962
3963 /* 3963 /*
3964 * Create a new status text window (widget) to be packed. 3964 * Create a new status text window (widget) to be packed.
3965 * Parameters: 3965 * Parameters:
3966 * text: The text to be display by the static text widget. 3966 * text: The text to be display by the static text widget.
3967 * id: An ID to be used with WinWindowFromID() or 0L. 3967 * id: An ID to be used with dw_window_from_id() or 0L.
3968 */ 3968 */
3969 HWND API dw_status_text_new(char *text, ULONG id) 3969 HWND API dw_status_text_new(char *text, ULONG id)
3970 { 3970 {
3971 HWND tmp = CreateWindow(STATICCLASSNAME, 3971 HWND tmp = CreateWindow(STATICCLASSNAME,
3972 text, 3972 text,
3983 } 3983 }
3984 3984
3985 /* 3985 /*
3986 * Create a new Multiline Editbox window (widget) to be packed. 3986 * Create a new Multiline Editbox window (widget) to be packed.
3987 * Parameters: 3987 * Parameters:
3988 * id: An ID to be used with WinWindowFromID() or 0L. 3988 * id: An ID to be used with dw_window_from_id() or 0L.
3989 */ 3989 */
3990 HWND API dw_mle_new(ULONG id) 3990 HWND API dw_mle_new(ULONG id)
3991 { 3991 {
3992 3992
3993 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, 3993 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE,
4020 4020
4021 /* 4021 /*
4022 * Create a new Entryfield window (widget) to be packed. 4022 * Create a new Entryfield window (widget) to be packed.
4023 * Parameters: 4023 * Parameters:
4024 * text: The default text to be in the entryfield widget. 4024 * text: The default text to be in the entryfield widget.
4025 * id: An ID to be used with WinWindowFromID() or 0L. 4025 * id: An ID to be used with dw_window_from_id() or 0L.
4026 */ 4026 */
4027 HWND API dw_entryfield_new(char *text, ULONG id) 4027 HWND API dw_entryfield_new(char *text, ULONG id)
4028 { 4028 {
4029 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, 4029 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE,
4030 EDITCLASSNAME, 4030 EDITCLASSNAME,
4049 4049
4050 /* 4050 /*
4051 * Create a new Entryfield passwird window (widget) to be packed. 4051 * Create a new Entryfield passwird window (widget) to be packed.
4052 * Parameters: 4052 * Parameters:
4053 * text: The default text to be in the entryfield widget. 4053 * text: The default text to be in the entryfield widget.
4054 * id: An ID to be used with WinWindowFromID() or 0L. 4054 * id: An ID to be used with dw_window_from_id() or 0L.
4055 */ 4055 */
4056 HWND API dw_entryfield_password_new(char *text, ULONG id) 4056 HWND API dw_entryfield_password_new(char *text, ULONG id)
4057 { 4057 {
4058 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, 4058 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE,
4059 EDITCLASSNAME, 4059 EDITCLASSNAME,
4091 4091
4092 /* 4092 /*
4093 * Create a new Combobox window (widget) to be packed. 4093 * Create a new Combobox window (widget) to be packed.
4094 * Parameters: 4094 * Parameters:
4095 * text: The default text to be in the combpbox widget. 4095 * text: The default text to be in the combpbox widget.
4096 * id: An ID to be used with WinWindowFromID() or 0L. 4096 * id: An ID to be used with dw_window_from_id() or 0L.
4097 */ 4097 */
4098 HWND API dw_combobox_new(char *text, ULONG id) 4098 HWND API dw_combobox_new(char *text, ULONG id)
4099 { 4099 {
4100 HWND tmp = CreateWindow(COMBOBOXCLASSNAME, 4100 HWND tmp = CreateWindow(COMBOBOXCLASSNAME,
4101 text, 4101 text,
4131 4131
4132 /* 4132 /*
4133 * Create a new button window (widget) to be packed. 4133 * Create a new button window (widget) to be packed.
4134 * Parameters: 4134 * Parameters:
4135 * text: The text to be display by the static text widget. 4135 * text: The text to be display by the static text widget.
4136 * id: An ID to be used with WinWindowFromID() or 0L. 4136 * id: An ID to be used with dw_window_from_id() or 0L.
4137 */ 4137 */
4138 HWND API dw_button_new(char *text, ULONG id) 4138 HWND API dw_button_new(char *text, ULONG id)
4139 { 4139 {
4140 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); 4140 BubbleButton *bubble = calloc(1, sizeof(BubbleButton));
4141 4141
4196 4196
4197 /* 4197 /*
4198 * Create a new spinbutton window (widget) to be packed. 4198 * Create a new spinbutton window (widget) to be packed.
4199 * Parameters: 4199 * Parameters:
4200 * text: The text to be display by the static text widget. 4200 * text: The text to be display by the static text widget.
4201 * id: An ID to be used with WinWindowFromID() or 0L. 4201 * id: An ID to be used with dw_window_from_id() or 0L.
4202 */ 4202 */
4203 HWND API dw_spinbutton_new(char *text, ULONG id) 4203 HWND API dw_spinbutton_new(char *text, ULONG id)
4204 { 4204 {
4205 ULONG *data = malloc(sizeof(ULONG)); 4205 ULONG *data = malloc(sizeof(ULONG));
4206 HWND buddy = CreateWindowEx(WS_EX_CLIENTEDGE, 4206 HWND buddy = CreateWindowEx(WS_EX_CLIENTEDGE,
4244 4244
4245 /* 4245 /*
4246 * Create a new radiobutton window (widget) to be packed. 4246 * Create a new radiobutton window (widget) to be packed.
4247 * Parameters: 4247 * Parameters:
4248 * text: The text to be display by the static text widget. 4248 * text: The text to be display by the static text widget.
4249 * id: An ID to be used with WinWindowFromID() or 0L. 4249 * id: An ID to be used with dw_window_from_id() or 0L.
4250 */ 4250 */
4251 HWND API dw_radiobutton_new(char *text, ULONG id) 4251 HWND API dw_radiobutton_new(char *text, ULONG id)
4252 { 4252 {
4253 HWND tmp = CreateWindow(BUTTONCLASSNAME, 4253 HWND tmp = CreateWindow(BUTTONCLASSNAME,
4254 text, 4254 text,
4273 /* 4273 /*
4274 * Create a new slider window (widget) to be packed. 4274 * Create a new slider window (widget) to be packed.
4275 * Parameters: 4275 * Parameters:
4276 * vertical: TRUE or FALSE if slider is vertical. 4276 * vertical: TRUE or FALSE if slider is vertical.
4277 * increments: Number of increments available. 4277 * increments: Number of increments available.
4278 * id: An ID to be used with WinWindowFromID() or 0L. 4278 * id: An ID to be used with dw_window_from_id() or 0L.
4279 */ 4279 */
4280 HWND API dw_slider_new(int vertical, int increments, ULONG id) 4280 HWND API dw_slider_new(int vertical, int increments, ULONG id)
4281 { 4281 {
4282 HWND tmp = CreateWindow(TRACKBAR_CLASS, 4282 HWND tmp = CreateWindow(TRACKBAR_CLASS,
4283 "", 4283 "",
4301 /* 4301 /*
4302 * Create a new scrollbar window (widget) to be packed. 4302 * Create a new scrollbar window (widget) to be packed.
4303 * Parameters: 4303 * Parameters:
4304 * vertical: TRUE or FALSE if scrollbar is vertical. 4304 * vertical: TRUE or FALSE if scrollbar is vertical.
4305 * increments: Number of increments available. 4305 * increments: Number of increments available.
4306 * id: An ID to be used with WinWindowFromID() or 0L. 4306 * id: An ID to be used with dw_window_from_id() or 0L.
4307 */ 4307 */
4308 HWND API dw_scrollbar_new(int vertical, int increments, ULONG id) 4308 HWND API dw_scrollbar_new(int vertical, int increments, ULONG id)
4309 { 4309 {
4310 HWND tmp = CreateWindow(SCROLLBARCLASSNAME, 4310 HWND tmp = CreateWindow(SCROLLBARCLASSNAME,
4311 "", 4311 "",
4327 } 4327 }
4328 4328
4329 /* 4329 /*
4330 * Create a new percent bar window (widget) to be packed. 4330 * Create a new percent bar window (widget) to be packed.
4331 * Parameters: 4331 * Parameters:
4332 * id: An ID to be used with WinWindowFromID() or 0L. 4332 * id: An ID to be used with dw_window_from_id() or 0L.
4333 */ 4333 */
4334 HWND API dw_percent_new(ULONG id) 4334 HWND API dw_percent_new(ULONG id)
4335 { 4335 {
4336 return CreateWindow(PROGRESS_CLASS, 4336 return CreateWindow(PROGRESS_CLASS,
4337 "", 4337 "",
4345 4345
4346 /* 4346 /*
4347 * Create a new checkbox window (widget) to be packed. 4347 * Create a new checkbox window (widget) to be packed.
4348 * Parameters: 4348 * Parameters:
4349 * text: The text to be display by the static text widget. 4349 * text: The text to be display by the static text widget.
4350 * id: An ID to be used with WinWindowFromID() or 0L. 4350 * id: An ID to be used with dw_window_from_id() or 0L.
4351 */ 4351 */
4352 HWND API dw_checkbox_new(char *text, ULONG id) 4352 HWND API dw_checkbox_new(char *text, ULONG id)
4353 { 4353 {
4354 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); 4354 BubbleButton *bubble = calloc(1, sizeof(BubbleButton));
4355 HWND tmp = CreateWindow(BUTTONCLASSNAME, 4355 HWND tmp = CreateWindow(BUTTONCLASSNAME,
4372 } 4372 }
4373 4373
4374 /* 4374 /*
4375 * Create a new listbox window (widget) to be packed. 4375 * Create a new listbox window (widget) to be packed.
4376 * Parameters: 4376 * Parameters:
4377 * id: An ID to be used with WinWindowFromID() or 0L. 4377 * id: An ID to be used with dw_window_from_id() or 0L.
4378 * multi: Multiple select TRUE or FALSE. 4378 * multi: Multiple select TRUE or FALSE.
4379 */ 4379 */
4380 HWND API dw_listbox_new(ULONG id, int multi) 4380 HWND API dw_listbox_new(ULONG id, int multi)
4381 { 4381 {
4382 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, 4382 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE,
4425 4425
4426 /* 4426 /*
4427 * Sets the bitmap used for a given static window. 4427 * Sets the bitmap used for a given static window.
4428 * Parameters: 4428 * Parameters:
4429 * handle: Handle to the window. 4429 * handle: Handle to the window.
4430 * id: An ID to be used to specify the icon. 4430 * id: An ID to be used to specify the icon,
4431 */ 4431 * (pass 0 if you use the filename param)
4432 void API dw_window_set_bitmap(HWND handle, ULONG id) 4432 * filename: a path to a file (Bitmap on OS/2 or
4433 { 4433 * Windows and a pixmap on Unix, pass
4434 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); 4434 * NULL if you use the id param)
4435 */
4436 void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename)
4437 {
4438 HBITMAP hbitmap;
4435 HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, STM_GETIMAGE, IMAGE_BITMAP, 0); 4439 HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, STM_GETIMAGE, IMAGE_BITMAP, 0);
4440
4441 if(id)
4442 hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id));
4443 else if(filename)
4444 {
4445 char *file = malloc(strlen(filename) + 5);
4446
4447 if (!file)
4448 return;
4449
4450 strcpy(file, filename);
4451
4452 /* check if we can read from this file (it exists and read permission) */
4453 if(access(file, 04) != 0)
4454 {
4455 /* Try with .bmp extention */
4456 strcat(file, ".bmp");
4457 if(access(file, 04) != 0)
4458 {
4459 free(file);
4460 return;
4461 }
4462 }
4463
4464 hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
4465 free(file);
4466 }
4467 else
4468 return;
4436 4469
4437 SendMessage(handle, STM_SETIMAGE, 4470 SendMessage(handle, STM_SETIMAGE,
4438 (WPARAM) IMAGE_BITMAP, 4471 (WPARAM) IMAGE_BITMAP,
4439 (LPARAM) hbitmap); 4472 (LPARAM) hbitmap);
4440 4473