News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Problems when showing icon in Tab control

Started by Ar0n, July 31, 2016, 04:41:02 PM

Previous topic - Next topic

Ar0n

I'm experiment some issues when setting up a icon in tab control, test code:


.586
.model flat,stdcall
option casemap:none

   include windows.inc
   include user32.inc
   include kernel32.inc
   include comctl32.inc
   
   includelib user32.lib
   includelib kernel32.lib
   includelib Comctl32.lib


WinMain proto :DWORD,:DWORD,:DWORD,:DWORD


.data
    ClassName db "MainWinClass",0
    AppName  db "Main Window",0
    tabclass db "SysTabControl32",0
    hTab    HWND 0
    tabname1    db "test 1",0

.data?
   hInstance HINSTANCE ?
   CommandLine LPSTR ?

.code


; ---------------------------------------------------------------------------


start:
invoke GetModuleHandle, NULL
mov    hInstance,eax

invoke GetCommandLine
mov    CommandLine,eax

invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov   wc.cbSize,SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra,NULL
mov   wc.cbWndExtra,NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground,COLOR_BTNFACE+1
mov   wc.lpszMenuName,NULL
mov   wc.lpszClassName,OFFSET ClassName

invoke LoadIcon,NULL,IDI_APPLICATION
mov   wc.hIcon,eax
mov   wc.hIconSm,eax

invoke LoadCursor,NULL,IDC_ARROW
mov   wc.hCursor,eax

invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,420,180,NULL,NULL,\
           hInst,NULL
mov   hwnd,eax

invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd

.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW

mov     eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL Item:TC_ITEM

.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx, NULL, ADDR tabclass, NULL,  WS_CHILD or WS_VISIBLE, \
2, 2, 404, 150, hWnd, NULL, hInstance, NULL
mov hTab, eax

; ===========================================================================================

invoke ImageList_Create,16, 16, ILC_COLOR32 or ILC_MASK, 1, 1
mov edi, eax
invoke LoadImage,hInstance, 100, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR
mov esi, eax
invoke ImageList_ReplaceIcon, edi, -1, esi
invoke DestroyIcon, esi

; ===========================================================================================

        invoke SendMessage, hTab, TCM_SETIMAGELIST, 0, edi
       
mov Item.imask, TCIF_TEXT or TCIF_IMAGE
mov Item.pszText, offset tabname1
        mov Item.iImage, 0
        invoke SendMessage, hTab, TCM_INSERTITEM, 0, addr Item
       
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF

xor eax,eax
ret
WndProc endp
end start


screen:

it seems that cannot display the icon properly, it's an icon 16x16 at 32-bit,  how can I solve this problem? files in attachment.

jj2007

What exactly is the problem? The icon looks OK...

Ar0n

@jj2007, did you try with the icon in attachments, it's at 32-bit.

fearless

Might be the the ILC_MASK flag in ImageList_Create causing it to paint the background of your icon slightly darker on one side?

Ive some code on creating a toolbar, loading icons, one for an imagelist for an enabled state and one for another imagelist when it is disabled (greyed)


    Invoke ImageList_Create, 16,16, ILC_COLOR32, 1, 16
    mov hToolBarIL_Enabled, eax
    Invoke ImageList_Create, 16,16, ILC_COLOR32, 1, 16
    mov hToolBarIL_Disabled, eax

    ; Imagelists for adding icons - enabled then disabled to each imagelist
    Invoke SendMessage, hToolBar, CCM_SETVERSION, 5, 0
    Invoke SendMessage, hToolBar, TB_SETIMAGELIST, 0, hToolBarIL_Enabled
    Invoke SendMessage, hToolBar, TB_SETDISABLEDIMAGELIST, 0, hToolBarIL_Disabled

    ; Load enabled icons
    Invoke LoadIcon, hInstance, ICO_TB_NEW
    Invoke ImageList_AddIcon, hToolBarIL_Enabled, eax
    Invoke LoadIcon, hInstance, ICO_TB_OPEN
    Invoke ImageList_AddIcon, hToolBarIL_Enabled, eax
    Invoke LoadIcon, hInstance, ICO_TB_SAVEAS
    Invoke ImageList_AddIcon, hToolBarIL_Enabled, eax
    Invoke LoadIcon, hInstance, ICO_TB_EXIT
    Invoke ImageList_AddIcon, hToolBarIL_Enabled, eax   

   
    ; Load disabled icons
    Invoke LoadIcon, hInstance, ICO_TB_NEW_GREY   
    Invoke ImageList_AddIcon, hToolBarIL_Disabled, eax
    Invoke LoadIcon, hInstance, ICO_TB_OPEN_GREY       
    Invoke ImageList_AddIcon, hToolBarIL_Disabled, eax
    Invoke LoadIcon, hInstance, ICO_TB_SAVEAS_GREY
    Invoke ImageList_AddIcon, hToolBarIL_Disabled, eax
    Invoke LoadIcon, hInstance, ICO_TB_EXIT_GREY     
    Invoke ImageList_AddIcon, hToolBarIL_Disabled, eax


of course that means creating specific greyed out icons for the disabled state. There are other options of course, using ILC_MASK only for the original loading icons but for the imagelist that is to be disabled might work. Cant remember why i done it this way exactly but might have been related to the mask drawing over the original icon sometimes doesnt look right? so i probably just edited my set of icons and changes the saturation and brightness of them to 'grey' them.

jj2007

Quote from: Ar0n on July 31, 2016, 07:45:16 PM
@jj2007, did you try with the icon in attachments, it's at 32-bit.

OK, I had not understood that you meant the little shadow. As fearless already wrote, the mask is the problem. Edit the icon and remove the ILC_MASK.

Ar0n

The problem is that I don't want to edit the icon, perhaps with some icons there is not any difference between an icon 24-bit and 32-bit one, but the one I'm using it does have a significant difference:

Is there a way to use an icon at 32-bit or bitmap at 32-bit with alpha channel in a tab control?

fearless

I think the answer is yes but with a few issue attached.

Yes you can use a 32bit icon that has the alpha channel in it for loading up as an icon via LoadImage, or LoadIcon, then passing the handle to an imagelist that is assigned to the toolbar control. However as you have seen in your example, the mask effect using the same image will give you an ugly looking icon when it combines the normal icon image with the mask. The same will apply for bitmaps.

I think Hutch has/had some code in one of the original examples with masm32 that replaces a pink color (to denote transparancy) in a bitmap strip - a bitmap with all 'icon' images stored side by side in a long row of images. The toolbar control understands which image to use based on the uniform width of each individual image in the bitmap strip and an index to denote its placement or order in the strip. The toolbar control will also use this bitmap strip for the mask effect when a toolbar image is disabled or greyed out.

So that is one possible way of achieving the result you are looking for.

The other is the use of a second set of icons in a 2nd imagelist used for when they are disabled.

Here is an example (using a rebar control that hosts the toolbar control) that has some icons disabled and enabled, all are 32bit icons