Mercurial > dwindows
comparison win/dw.c @ 2852:5018df4f952e
Win/Android/Template: Add return values to dw_window_set_bitmap(_from_data).
Also update the readme regarding this change.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 15 Nov 2022 00:34:20 +0000 |
parents | ee1cfa7d645e |
children | 761b7a12b079 |
comparison
equal
deleted
inserted
replaced
2851:fdd21139c07f | 2852:5018df4f952e |
---|---|
7691 (WPARAM) IMAGE_ICON, | 7691 (WPARAM) IMAGE_ICON, |
7692 (LPARAM) hicon); | 7692 (LPARAM) hicon); |
7693 } | 7693 } |
7694 | 7694 |
7695 /* Internal function to set bitmap for the next two functions */ | 7695 /* Internal function to set bitmap for the next two functions */ |
7696 void _dw_window_set_bitmap(HWND handle, HICON icon, HBITMAP hbitmap) | 7696 int _dw_window_set_bitmap(HWND handle, HICON icon, HBITMAP hbitmap) |
7697 { | 7697 { |
7698 HBITMAP oldbitmap = 0; | 7698 HBITMAP oldbitmap = 0; |
7699 HANDLE oldicon = 0; | 7699 HANDLE oldicon = 0; |
7700 TCHAR tmpbuf[100] = {0}; | 7700 TCHAR tmpbuf[100] = {0}; |
7701 | 7701 |
7702 if (!icon && !hbitmap) | 7702 if (!icon && !hbitmap) |
7703 return; | 7703 return DW_ERROR_GENERAL; |
7704 | 7704 |
7705 GetClassName(handle, tmpbuf, 99); | 7705 GetClassName(handle, tmpbuf, 99); |
7706 | 7706 |
7707 if(_tcsnicmp(tmpbuf, BUTTONCLASSNAME, _tcslen(BUTTONCLASSNAME)+1)==0) | 7707 if(_tcsnicmp(tmpbuf, BUTTONCLASSNAME, _tcslen(BUTTONCLASSNAME)+1)==0) |
7708 { | 7708 { |
7768 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); | 7768 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); |
7769 /* Queue a redraw on the top-level window */ | 7769 /* Queue a redraw on the top-level window */ |
7770 _dw_redraw(_dw_toplevel_window(handle), TRUE); | 7770 _dw_redraw(_dw_toplevel_window(handle), TRUE); |
7771 } | 7771 } |
7772 } | 7772 } |
7773 return DW_ERROR_NONE; | |
7773 } | 7774 } |
7774 | 7775 |
7775 /* | 7776 /* |
7776 * Sets the bitmap used for a given static window. | 7777 * Sets the bitmap used for a given static window. |
7777 * Parameters: | 7778 * Parameters: |
7779 * id: An ID to be used to specify the icon, | 7780 * id: An ID to be used to specify the icon, |
7780 * (pass 0 if you use the filename param) | 7781 * (pass 0 if you use the filename param) |
7781 * filename: a path to a file (Bitmap on OS/2 or | 7782 * filename: a path to a file (Bitmap on OS/2 or |
7782 * Windows and a pixmap on Unix, pass | 7783 * Windows and a pixmap on Unix, pass |
7783 * NULL if you use the id param) | 7784 * NULL if you use the id param) |
7784 */ | 7785 * Returns: |
7785 void API dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename) | 7786 * DW_ERROR_NONE on success. |
7787 * DW_ERROR_UNKNOWN if the parameters were invalid. | |
7788 * DW_ERROR_GENERAL if the bitmap was unable to be loaded. | |
7789 */ | |
7790 int API dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename) | |
7786 { | 7791 { |
7787 HBITMAP hbitmap = 0; | 7792 HBITMAP hbitmap = 0; |
7788 HANDLE icon = 0; | 7793 HANDLE icon = 0; |
7789 | 7794 |
7790 if(id) | 7795 if(id) |
7798 hbitmap = _dw_load_bitmap(filename, NULL); | 7803 hbitmap = _dw_load_bitmap(filename, NULL); |
7799 #else | 7804 #else |
7800 _dw_get_image_handle(filename, &icon, &hbitmap); | 7805 _dw_get_image_handle(filename, &icon, &hbitmap); |
7801 #endif | 7806 #endif |
7802 } | 7807 } |
7803 | 7808 else |
7804 _dw_window_set_bitmap(handle, icon, hbitmap); | 7809 return DW_ERROR_UNKNOWN; |
7810 | |
7811 return _dw_window_set_bitmap(handle, icon, hbitmap); | |
7805 } | 7812 } |
7806 | 7813 |
7807 /* | 7814 /* |
7808 * Sets the bitmap used for a given static window from data. | 7815 * Sets the bitmap used for a given static window from data. |
7809 * Parameters: | 7816 * Parameters: |
7812 * (pass 0 if you use the data param) | 7819 * (pass 0 if you use the data param) |
7813 * data: the image from meory | 7820 * data: the image from meory |
7814 * Bitmap on Windows and a pixmap on Unix, pass | 7821 * Bitmap on Windows and a pixmap on Unix, pass |
7815 * NULL if you use the id param) | 7822 * NULL if you use the id param) |
7816 * len: length of data | 7823 * len: length of data |
7817 */ | 7824 * Returns: |
7818 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len) | 7825 * DW_ERROR_NONE on success. |
7826 * DW_ERROR_UNKNOWN if the parameters were invalid. | |
7827 * DW_ERROR_GENERAL if the bitmap was unable to be loaded. | |
7828 */ | |
7829 int API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len) | |
7819 { | 7830 { |
7820 HBITMAP hbitmap=0; | 7831 HBITMAP hbitmap=0; |
7821 HICON icon=0; | 7832 HICON icon=0; |
7822 char *file; | 7833 char *file; |
7823 FILE *fp; | 7834 FILE *fp; |
7843 } | 7854 } |
7844 else | 7855 else |
7845 { | 7856 { |
7846 _unlink( file ); | 7857 _unlink( file ); |
7847 free( file ); | 7858 free( file ); |
7848 return; | 7859 return DW_ERROR_GENERAL; |
7849 } | 7860 } |
7850 _unlink( file ); | 7861 _unlink( file ); |
7851 free( file ); | 7862 free( file ); |
7852 } | 7863 } |
7853 if (icon == 0 && hbitmap == 0) | 7864 if (icon == 0 && hbitmap == 0) |
7854 return; | 7865 return DW_ERROR_GENERAL; |
7855 } | 7866 } |
7856 else if ( id ) | 7867 else if ( id ) |
7857 { | 7868 { |
7858 hbitmap = LoadBitmap(_DWInstance, MAKEINTRESOURCE(id)); | 7869 hbitmap = LoadBitmap(_DWInstance, MAKEINTRESOURCE(id)); |
7859 icon = LoadImage(_DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED); | 7870 icon = LoadImage(_DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED); |
7860 } | 7871 } |
7861 | 7872 else |
7862 _dw_window_set_bitmap(handle, icon, hbitmap); | 7873 return DW_ERROR_UNKNOWN; |
7874 | |
7875 return _dw_window_set_bitmap(handle, icon, hbitmap); | |
7863 } | 7876 } |
7864 | 7877 |
7865 | 7878 |
7866 /* | 7879 /* |
7867 * Sets the text used for a given window. | 7880 * Sets the text used for a given window. |