@@ -93,6 +93,9 @@ static bool capture_mouse = false;
9393static bool relative_mouse = false;
9494
9595typedef HCURSOR dx_cursor ;
96+ typedef HICON dx_icon ;
97+
98+ #define TICON _ABSTRACT(dx_icon)
9699
97100static dx_cursor cur_cursor = NULL ;
98101static bool show_cursor = true;
@@ -957,6 +960,11 @@ HL_PRIM int HL_NAME(win_change_display_setting)(wchar_t* device, vdynamic* ds) {
957960 return ChangeDisplaySettingsExW (device , found ? & devMode : NULL , NULL , found ? CDS_FULLSCREEN : 0 , NULL );
958961}
959962
963+ HL_PRIM void HL_NAME (win_set_icon )(HWND wnd , dx_icon icon ) {
964+ SendMessage (wnd , WM_SETICON , ICON_SMALL , (LPARAM )icon );
965+ SendMessage (wnd , WM_SETICON , ICON_BIG , (LPARAM )icon );
966+ }
967+
960968#define TWIN _ABSTRACT(dx_window)
961969DEFINE_PRIM (TWIN , win_create_ex , _I32 _I32 _I32 _I32 _I32 );
962970DEFINE_PRIM (TWIN , win_create , _I32 _I32 );
@@ -990,6 +998,7 @@ DEFINE_PRIM(_DYN, win_get_current_display_setting, _BYTES _BOOL);
990998DEFINE_PRIM (_I32 , win_change_display_setting , _BYTES _DYN );
991999DEFINE_PRIM (_ARR , win_get_monitors , _NO_ARG );
9921000DEFINE_PRIM (_BYTES , win_get_monitor_from_window , TWIN );
1001+ DEFINE_PRIM (_VOID , win_set_icon , TWIN TICON );
9931002DEFINE_PRIM (_VOID , win_set_dark_mode , TWIN _BOOL );
9941003
9951004DEFINE_PRIM (_I32 , get_screen_width , _NO_ARG );
@@ -999,38 +1008,40 @@ HL_PRIM dx_cursor HL_NAME(load_cursor)( int res ) {
9991008 return LoadCursor (NULL ,MAKEINTRESOURCE (res ));
10001009}
10011010
1002- HL_PRIM dx_cursor HL_NAME ( create_cursor )( int width , int height , vbyte * data , int hotX , int hotY ) {
1011+ static HICON create_icon_internal ( int width , int height , vbyte * data , bool icon , int hotX , int hotY ) {
10031012 int pad = sizeof (void * ) << 3 ;
10041013 HICON hicon ;
10051014 HDC hdc = GetDC (NULL );
10061015 BITMAPV4HEADER bmh ;
1007- void * pixels ;
1008- void * maskbits ;
1016+ void * pixels ;
1017+ void * maskbits ;
10091018 int maskbitslen ;
10101019 ICONINFO ii ;
10111020
1012- ZeroMemory (& bmh ,sizeof (bmh ));
1021+ ZeroMemory (& bmh , sizeof (bmh ));
10131022 bmh .bV4Size = sizeof (bmh );
10141023 bmh .bV4Width = width ;
10151024 bmh .bV4Height = - height ;
10161025 bmh .bV4Planes = 1 ;
10171026 bmh .bV4BitCount = 32 ;
10181027 bmh .bV4V4Compression = BI_BITFIELDS ;
10191028 bmh .bV4AlphaMask = 0xFF000000 ;
1020- bmh .bV4RedMask = 0x00FF0000 ;
1029+ bmh .bV4RedMask = 0x00FF0000 ;
10211030 bmh .bV4GreenMask = 0x0000FF00 ;
1022- bmh .bV4BlueMask = 0x000000FF ;
1031+ bmh .bV4BlueMask = 0x000000FF ;
10231032
1024- maskbitslen = ((width + (- width )% pad ) >> 3 ) * height ;
1033+ maskbitslen = ((width + (- width ) % pad ) >> 3 ) * height ;
10251034 maskbits = malloc (maskbitslen );
1026- if ( maskbits == NULL )
1035+ if ( maskbits == NULL )
10271036 return NULL ;
1028- memset (maskbits ,0xFF ,maskbitslen );
1037+ memset (maskbits , 0xFF , maskbitslen );
10291038
1030- memset (& ii ,0 ,sizeof (ii ));
1031- ii .fIcon = FALSE;
1032- ii .xHotspot = (DWORD )hotX ;
1033- ii .yHotspot = (DWORD )hotY ;
1039+ memset (& ii , 0 , sizeof (ii ));
1040+ ii .fIcon = icon ;
1041+ if (icon ) {
1042+ ii .xHotspot = (DWORD )hotX ;
1043+ ii .yHotspot = (DWORD )hotY ;
1044+ }
10341045 ii .hbmColor = CreateDIBSection (hdc , (BITMAPINFO * )& bmh , DIB_RGB_COLORS , & pixels , NULL , 0 );
10351046 ii .hbmMask = CreateBitmap (width , height , 1 , 1 , maskbits );
10361047 ReleaseDC (NULL , hdc );
@@ -1044,10 +1055,23 @@ HL_PRIM dx_cursor HL_NAME(create_cursor)( int width, int height, vbyte *data, in
10441055 return hicon ;
10451056}
10461057
1058+
1059+ HL_PRIM dx_cursor HL_NAME (create_cursor )( int width , int height , vbyte * data , int hotX , int hotY ) {
1060+ return create_icon_internal (width , height , data , false, hotX , hotY );
1061+ }
1062+
1063+ HL_PRIM dx_icon HL_NAME (create_icon )(int width , int height , vbyte * data ) {
1064+ return create_icon_internal (width , height , data , true, 0 , 0 );
1065+ }
1066+
10471067HL_PRIM void HL_NAME (destroy_cursor )( dx_cursor c ) {
10481068 DestroyIcon (c );
10491069}
10501070
1071+ HL_PRIM void HL_NAME (destroy_icon )(dx_icon i ) {
1072+ DestroyIcon (i );
1073+ }
1074+
10511075HL_PRIM void HL_NAME (set_cursor )( dx_cursor c ) {
10521076 cur_cursor = c ;
10531077 if ( CURSOR_VISIBLE )
@@ -1066,7 +1090,9 @@ HL_PRIM bool HL_NAME(is_cursor_visible)() {
10661090#define TCURSOR _ABSTRACT(dx_cursor)
10671091DEFINE_PRIM (TCURSOR , load_cursor , _I32 );
10681092DEFINE_PRIM (TCURSOR , create_cursor , _I32 _I32 _BYTES _I32 _I32 );
1093+ DEFINE_PRIM (TICON , create_icon , _I32 _I32 _BYTES );
10691094DEFINE_PRIM (_VOID , destroy_cursor , TCURSOR );
1095+ DEFINE_PRIM (_VOID , destroy_icon , TICON );
10701096DEFINE_PRIM (_VOID , set_cursor , TCURSOR );
10711097DEFINE_PRIM (_VOID , show_cursor , _BOOL );
10721098DEFINE_PRIM (_BOOL , is_cursor_visible , _NO_ARG );
0 commit comments