NO

Author Topic: Image on tab control  (Read 428 times)

Offline HellOfMice

  • Member
  • *
  • Posts: 221
  • Never be pleased, always improve
Image on tab control
« on: December 05, 2024, 05:03:22 PM »
Hi tout le monde,

I need your help because I am becoming crazy.

I create an image list
I create a tab control
I assign the imagelist to the tab control
I do the following:
Quote
//  ---> Insert items in tab bar

    _Tci.dwState        = 0 ;
    _Tci.dwStateMask    = 0 ;
    _Tci.cchTextMax     = 0 ;

    _Tci.mask           = TCIF_PARAM|TCIF_TEXT|TCIF_IMAGE ;

    _Tci.pszText        = "Welcome" ;
    _Tci.lParam         = 0 ;
    _Tci.iImage         = 0 ;

    TabCtrl_InsertItem(hTabControl,0,&_Tci) ;

And the result is: nothing on the tabs


I set all I did for the tabs in the lines below:
Code: [Select]
1/ In WinMain

//  *******************************
//  *** Windows initializations ***
//  *******************************

//  ---> Common controls

    _IccEx.dwSize   = sizeof(INITCOMMONCONTROLSEX) ;
    _IccEx.dwICC    = ICC_BAR_CLASSES|ICC_COOL_CLASSES|ICC_LISTVIEW_CLASSES|ICC_PROGRESS_CLASS|ICC_STANDARD_CLASSES|ICC_TAB_CLASSES|ICC_TREEVIEW_CLASSES|ICC_USEREX_CLASSES|ICC_WIN95_CLASSES ;

    InitCommonControlsEx(&_IccEx) ;

//  ---> Image List Buttons

//  *****************************
//  *** Create the image list ***
//  *****************************

    hTabButtonsList = ImageList_Create(80,24,ILC_COLOR24,6,6) ;
    ImageList_SetBkColor(hTabButtonsList,0x00000000) ;

//  *************************************
//  *** Add bitmaps to the image list ***
//  *************************************

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_0_0)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_0_1)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_0_2)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_0_3)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_0_4)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_0_5)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_1_0)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_1_1)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_1_2)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_1_3)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_1_4)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_LINE_1_5)) ;
    ImageList_Add(hTabButtonsList,_hBitmap,NULL) ;
    DeleteObject(_hBitmap) ;

//  *************************************************
//  *** Finished adding bitmaps to the image list ***
//  *************************************************

2 / in WmSIZE

//  _____________________________________________________________________________________________
//  ________________________________Main_OnWmSize________________________________________________
//  _____________________________________________________________________________________________

LRESULT Main_OnWmSize(DWORD __dwNewWidth,DWORD __dwNewHeight)
{
    register            int         _iXChildren ;
    register            int         _iStatusBarHeight ;
    alignas(HBITMAP)    HBITMAP     _hBitmap ;
    alignas(HBITMAP)    BITMAP      _Bitmap ;
    alignas(HANDLE)     RECT        _RcStatus, _RcTab ;
    alignas(int)        int         _iWidthReservedSpace, _iHeightReservedSpace ;
    alignas(int)        int         _iChildrenWidth, _iChildrenHeight ;
    alignas(int)        int         _iHeightHalfBitmap ;
    alignas(int)        int         _iXBouton, _iYBouton ;

    MoveWindow(hStatus,0,0,0,0,TRUE) ;
    GetClientRect(hStatus,&_RcStatus) ;

    MoveWindow(hTabControl,0,0,__dwNewWidth,DIK_HEIGHT_OF_ONE_TAB,TRUE) ;
    GetClientRect(hTabControl,&_RcTab) ;

    _iStatusBarHeight       = _RcStatus.bottom - _RcStatus.top ;

    _iWidthReservedSpace    = 32 ;
    _iHeightReservedSpace   = 72 ;

    _iXChildren             = _iWidthReservedSpace / 2 ;
    _iChildrenWidth         = __dwNewWidth - _iWidthReservedSpace ;
    _iChildrenHeight        = __dwNewHeight - DIK_HEIGHT_OF_ONE_TAB - _iStatusBarHeight - _iHeightReservedSpace ;

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_BUTTONS_01)) ;
    GetObject(_hBitmap,sizeof(BITMAP),&_Bitmap) ;
    DeleteObject(_hBitmap) ;

    _iHeightHalfBitmap      = _Bitmap.bmHeight / 2 ;

    _iXBouton               = (__dwNewWidth - _Bitmap.bmWidth) / 2 ;
    _iYBouton               = ((_iHeightReservedSpace - _iStatusBarHeight) - _iHeightHalfBitmap) / 2 ;
    _iYBouton               = _iYBouton + DIK_HEIGHT_OF_ONE_TAB + _iChildrenHeight ;

    MoveWindow(hChildrenWindows[0],_iXChildren,DIK_HEIGHT_OF_ONE_TAB,_iChildrenWidth,_iChildrenHeight,TRUE) ;
    MoveWindow(hChildrenWindows[1],_iXChildren,DIK_HEIGHT_OF_ONE_TAB,_iChildrenWidth,_iChildrenHeight,TRUE) ;
    MoveWindow(hChildrenWindows[2],_iXChildren,DIK_HEIGHT_OF_ONE_TAB,_iChildrenWidth,_iChildrenHeight,TRUE) ;
    MoveWindow(hChildrenWindows[3],_iXChildren,DIK_HEIGHT_OF_ONE_TAB,_iChildrenWidth,_iChildrenHeight,TRUE) ;
    MoveWindow(hChildrenWindows[4],_iXChildren,DIK_HEIGHT_OF_ONE_TAB,_iChildrenWidth,_iChildrenHeight,TRUE) ;
    MoveWindow(hChildrenWindows[5],_iXChildren,DIK_HEIGHT_OF_ONE_TAB,_iChildrenWidth,_iChildrenHeight,TRUE) ;

    MoveWindow(hButtonQuit,_iXBouton,_iYBouton,_Bitmap.bmWidth,_iHeightHalfBitmap,SWP_SHOWWINDOW|TRUE) ;

    return (0) ;
}

2/ in WM_CREATE

//  _____________________________________________________________________________________________
//  ________________________________Main_OnWmCreate______________________________________________
//  _____________________________________________________________________________________________

LRESULT Main_OnWmCreate(HWND __hWnd)
{
    alignas(HBITMAP)    HBITMAP     _hBitmap ;
    alignas(HBITMAP)    BITMAP      _Bitmap ;
    alignas(HANDLE)     TCITEM      _Tci ;
    alignas(RECT)       RECT        _RcClient ;

    hMainWindow = __hWnd ;

//  ---> Statusbar

    hStatus = CreateStatusWindow(WS_CHILD|WS_VISIBLE,"Welcome",__hWnd,DIK_STATUSBAR) ;
    SendMessage(hStatus,WM_SETFONT,(WPARAM) hThemeFont,TRUE) ;
    SendMessage(hStatus,SB_SETPARTS,(WPARAM) 1,(LPARAM) StatWidths) ;
    Theme_WriteStatusBarText(hStatus,"Welcome / Bienvenue") ;
    ShowWindow(hStatus,SW_SHOW) ;

//  ---> client areas

    GetClientRect(__hWnd,&_RcClient) ;

//  ---> Tab bar

    hTabControl = CreateWindow(WC_TABCONTROL,NULL,WS_CHILD|WS_VISIBLE,0,0,_RcClient.right,DIK_HEIGHT_OF_ONE_TAB,__hWnd,(HMENU) DIK_TAB,hInstance,NULL) ;

    SendMessage(hTabControl,TCM_SETIMAGELIST,0,(LPARAM) hTabButtonsList) ;

    TabCtrl_SetExtendedStyle(hTabControl,TCS_EX_FLATSEPARATORS) ;
    SendMessage(hTabControl,TCM_SETMINTABWIDTH,0,80) ;
    SendMessage(hTabControl,TCM_SETITEMSIZE,0,0x00500018) ;

//  ---> Quit button

    _hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(BMP_BUTTONS_01)) ;
    GetObject(_hBitmap,sizeof(BITMAP),&_Bitmap) ;
    DeleteObject(_hBitmap) ;

    hButtonQuit = CreateWindowEx(0,"BUTTON",NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW|BS_CENTER|BS_VCENTER|BS_FLAT|BS_NOTIFY,100,100,_Bitmap.bmWidth,_Bitmap.bmHeight / 2,__hWnd,(HMENU) DIK_BUTTON_QUIT,hInstance,NULL) ;

//  ---> Insert items in tab bar

    _Tci.dwState        = 0 ;
    _Tci.dwStateMask    = 0 ;
    _Tci.cchTextMax     = 0 ;

    _Tci.mask           = TCIF_PARAM|TCIF_TEXT|TCIF_IMAGE ;

    _Tci.pszText        = "Welcome" ;
    _Tci.lParam         = 0 ;
    _Tci.iImage         = 0 ;

    TabCtrl_InsertItem(hTabControl,0,&_Tci) ;

    _Tci.pszText        = "Criteria" ;
    _Tci.lParam         = 1 ;
    _Tci.iImage         = 1 ;

    TabCtrl_InsertItem(hTabControl,1,&_Tci) ;

    _Tci.pszText        = "Database" ;
    _Tci.lParam         = 2 ;
    _Tci.iImage         = 2 ;


    TabCtrl_InsertItem(hTabControl,2,&_Tci) ;

    _Tci.pszText        = "Folders && Run" ;
    _Tci.lParam         = 3 ;
    _Tci.iImage         = 3 ;

    TabCtrl_InsertItem(hTabControl,3,&_Tci) ;

    _Tci.pszText        = "Protect" ;
    _Tci.lParam         = 4 ;
    _Tci.iImage         = 4 ;

    TabCtrl_InsertItem(hTabControl,4,&_Tci) ;

    _Tci.pszText        = "Results" ;
    _Tci.lParam         = 5 ;
    _Tci.iImage         = 5 ;

    TabCtrl_InsertItem(hTabControl,5,&_Tci) ;

    UpdateWindow(hTabControl) ;
    ShowWindow(hTabControl,SW_SHOW) ;

//  ---> Create children windows

    hChildrenWindows[0] = CreateWindowEx(0,szChild_0_WindowClass,NULL,WS_CHILD|WS_VISIBLE,0,0,100,100,__hWnd,(HMENU) W00_DLG_SEARCH,hInstance,NULL) ;
    hChildrenWindows[1] = CreateWindowEx(0,szChild_1_WindowClass,NULL,WS_CHILD|WS_VISIBLE,0,0,100,100,__hWnd,(HMENU) W01_DLG_SEARCH,hInstance,NULL) ;
    hChildrenWindows[2] = CreateWindowEx(0,szChild_2_WindowClass,NULL,WS_CHILD|WS_VISIBLE,0,0,100,100,__hWnd,(HMENU) W02_DLG_SEARCH,hInstance,NULL) ;
    hChildrenWindows[3] = CreateWindowEx(0,szChild_3_WindowClass,NULL,WS_CHILD|WS_VISIBLE,0,0,100,100,__hWnd,(HMENU) W03_DLG_SEARCH,hInstance,NULL) ;
    hChildrenWindows[4] = CreateWindowEx(0,szChild_4_WindowClass,NULL,WS_CHILD|WS_VISIBLE,0,0,100,100,__hWnd,(HMENU) W04_DLG_SEARCH,hInstance,NULL) ;
    hChildrenWindows[5] = CreateWindowEx(0,szChild_5_WindowClass,NULL,WS_CHILD|WS_VISIBLE,0,0,100,100,__hWnd,(HMENU) W05_DLG_SEARCH,hInstance,NULL) ;

    ShowWindow(hChildrenWindows[1],SW_HIDE) ;
    ShowWindow(hChildrenWindows[2],SW_HIDE) ;
    ShowWindow(hChildrenWindows[3],SW_HIDE) ;
    ShowWindow(hChildrenWindows[4],SW_HIDE) ;
    ShowWindow(hChildrenWindows[5],SW_HIDE) ;
    ShowWindow(hChildrenWindows[0],SW_SHOW) ;

//  ---> Set the focus on the first tab

    TabCtrl_SetCurSel(hTabControl,0) ;
    TabCtrl_SetCurFocus(hTabControl,0) ;

    return (0) ;
}
« Last Edit: December 05, 2024, 05:08:21 PM by HellOfMice »
--------------------------------
Kenavo