Announcement

Collapse
No announcement yet.

DDT toolbar help desperately needed...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Semen Matusovski
    replied
    According MSDN, LR_LOADMAP3DCOLORS searches the color table for the image and replaces the following shades of gray with the corresponding 3-D color:
    RGB(128,128,128) -> COLOR_3DSHADOW
    RGB(192,192,192) -> COLOR_3DFACE
    RGB(223,223,223) -> COLOR_3DLIGHT
    There are two problems:
    1) it's not allowed to use this option for bitmaps with a color depth greater than 8bpp.
    2) Windows makes "transparent" any point with Gray (Ltgray/DkGray) color. Actually similar points could be a part of picture.

    I use for background unique color (different, depends of picture).
    After ordinary LoadBitmap I call something like below to replace colors.
    PixelX & PixelY defines position of one transparent pixel (typically, 0, 0)
    Code:
       Function AdaptBmp (hBmp As Dword, PixelX As Long, PixelY As Long) As Long
    
          Dim bm As BITMAP, hDC As Long, hMem1DC As Long, hMem2DC As Long, hMemBmp As Long, _
              bmi As BITMAPINFO, i As Long, j As Long,  m As Long, t As Long, tt As Long
    
          hDC = GetDC(0)
          hMem1DC = CreateCompatibleDC (hDC)
          hMem2DC = CreateCompatibleDC (hDC)
          ReleaseDC 0, hDC
    
          GetObject hBmp, SizeOf(bm), bm
          bmi.bmiHeader.biSize = SizeOf(bmi.bmiHeader)
          bmi.bmiHeader.biWidth = bm.bmWidth
          bmi.bmiHeader.biHeight = bm.bmHeight
          bmi.bmiHeader.biPlanes = 1
          bmi.bmiHeader.biBitCount = 32
          bmi.bmiHeader.biCompression = %BI_RGB
          hMemBmp = CreateDIBSection(hMem2DC, bmi, %DIB_RGB_COLORS, 0, 0, 0)
          GetObject hMemBmp, SizeOf(bm), bm
    
          SelectObject hMem1DC, hBmp
          SelectObject hMem2DC, hMemBmp
    
          BitBlt hMem2DC, 0, 0, bm.bmWidth, bm.bmHeight, hMem1Dc, 0, 0, %SRCCOPY
    
          t =  GetSysColor(%COLOR_BTNFACE)
          ReDim b(3) As Byte At VarPtr(t)
          m = Rgb(b(2), b(1), b(0))
    
          ReDim Ar(0) As Long At bm.bmBits
          t = (Ar((bm.bmHeight - 1 - PixelY) * bm.bmWidth + PixelX) And &HFFFFFF)
    
          For j = 0 To bm.bmHeight - 1
             For i = 0 To bm.bmWidth - 1
                If (Ar(tt) And &HFFFFFF) = t Then Ar(tt) = m
                Incr tt
             Next
          Next
    
          DeleteDC hMem1DC: DeleteDC hMem2DC: DeleteObject hBmp
          hBmp = hMemBmp: Function = hBmp
    
       End Function

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Simon Morgan
    replied
    Regarding the issue of the background color of the buttons, SKELETON.BAS doesn't follow
    the selected Windows color scheme properly. I fixed it by changing:
    Code:
          hBmp = LoadBitmap(hInst, "TOOLBAR")
    to
    Code:
          hBmp = LoadImage(hInst, "TOOLBAR",%IMAGE_BITMAP,0,0,%LR_LOADMAP3DCOLORS)
    Just in case that helps anyone.
    Simon

    ------------------

    Leave a comment:


  • Bern Ertl
    replied
    Thanks Lance.

    Someone turned the lights on in here!

    I think *my* problem was only having the Skeleton.RC example
    to draw from. It uses a label for the bitmap instead of a
    numerical identifier and I could not for the life of me
    figure out how to find a numerical identifier for it.



    ------------------
    Bernard Ertl

    Leave a comment:


  • Semen Matusovski
    replied
    Borje --
    do you about TB_ADDBITMAP ?!
    I can beleive, if initial background color = %COLOR_BTNFACE.
    Under Win2000 LTGRAY color <> GetSysColor(%COLOR_BTNFACE) even for standart scheme.

    [This message has been edited by Semen Matusovski (edited July 21, 2001).]

    Leave a comment:


  • Borje Hagsten
    replied
    Hm, don't understand. I use standard bmp, 16 colors with light gray
    background and it changes background perfect, according to colorscheme.
    Must be that the toolbar remaps the background when it is %COLOR_BTNFACE.


    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Toolbar requires "transparent" bitmap. That's why I call a special sub to "adapt" hbmp to %COLOR_BTNFACE.

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Lance Edmonds
    replied
    I used the same resource ID for the control ID, just to simplify matters somewhat.
    Code:
    ' in the .BAS code:
    %ID_TOOLBAR1  = 998&
     
    ' snippet from .RC file:
    998  BITMAP  DISCARDABLE  "toobar.bmp"

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Bern Ertl
    replied
    Lance,

    Looking at your last post, you used %ID_TOOLBAR1 for the
    Toolbar control id AND the bitmap resource identifier (Tabm.nID).

    How was the bitmap set up in your resource file?

    Perhaps this is where my confusion lay....



    ------------------
    Bernard Ertl

    Leave a comment:


  • Borje Hagsten
    replied
    Not sorry - glad to hear this.

    Still prefer CreateToolbarEx though, since result is same (%TB_AUTOSIZE) and
    one gets the handle back directly, instead of having to use CONTROL HANDLE..


    ------------------

    Leave a comment:


  • Lance Edmonds
    replied
    Sorry Borje, but CONTROL ADD works perfectly fine with a toolbar control. For example:
    Code:
    CONTROL ADD "TOOLBARWINDOW32", hDlg, %ID_TOOLBAR1, "", 0, 0, 1, 32, _
            %WS_CHILD OR %WS_BORDER OR %WS_VISIBLE OR %CCS_TOP OR _
            %TBSTYLE_TOOLTIPS OR %TB_AUTOSIZE _
            OR %WS_CLIPSIBLINGS
    Further, here is the technique I use in one of my apps (which works well):
    Code:
    LOCAL Tabm AS TBADDBITMAP
    ...
    CONTROL SEND hDlg, %ID_TOOLBAR1, %TB_SETBITMAPSIZE, 0, MAKLNG(32,32)
    Tabm.hInst = ghInst
    Tabm.nID = %ID_TOOLBAR1
    CONTROL SEND hDlg, %ID_TOOLBAR1, %TB_ADDBITMAP, %ToolButtons, VARPTR(Tabm)
    (The above code was directly copied from one of my working app's)

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Borje Hagsten
    replied
    Not sure, but don't think CONTROL ADD works with toolbar. May be
    same reason as to why one cannot use it to create container controls
    either, since a toolbar actually is a container for a bunch of buttons.

    Doesn't really matter, because CreateToolbarEx works fine and then one
    can use CONTROL SEND, or Sendmessage, to communicate with it..


    ------------------


    [This message has been edited by Borje Hagsten (edited July 20, 2001).]

    Leave a comment:


  • Bern Ertl
    replied
    Thanks all.

    Lance, I tried several variations with hInst = %NULL. I was
    not successful.

    I have managed to get CreateWindowEx to work though, so I'm back
    in business. When I have more time, I'll re-examine my code and
    see if I can post a working DDT solution.



    ------------------
    Bernard Ertl

    Leave a comment:


  • Lance Edmonds
    replied
    Bern, try this (I use this technique all the time):
    Code:
    Tabm.hInst = GetModuleHandle(BYVAL %NULL)
    Tabm.nID = %ID_TOOLBAR1
    Note: You'll need to change your resource file to use a numeric identifier, rather than the text identifier.


    Alternatively, try this way (pseudocode, off the top of my head):
    Code:
    Tabm.hInst = %NULL
    Tabm.nID = LoadImage(hInstance, "bitmapID", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTCOLOR)
    LoadBitmap() may work in it's place - the key is that the .hInst member must be zero.

    See TBADDBITMAP in WIN32.HLP for more info.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Simon Morgan
    replied
    I've realised my earlier response wasn't helpful & deleted it.
    One thought though: are filenames longer than 8 characters a problem?

    Simon

    [This message has been edited by Simon Morgan (edited July 20, 2001).]

    Leave a comment:


  • Bern Ertl
    replied
    Borje, thanks for the tip.

    I tried modifying my .RC file like so:

    Code:
    1 BITMAP LARGEIMAGE.BMP
    2 BITMAP SMALLIMAGE.BMP
    LargeImage.Bmp is (36) 32x32 images in a strip.
    SmallImage.Bmp is (36) 16x16 images in a strip.

    and modifying the DDT code like so:

    Code:
       Tabm.hInst = GetModuleHandle(BYVAL %NULL)
    
    
       IF BIT( LogInUser.Info.Part.One, %IconSize) THEN
          CONTROL SEND hDlg&, %ID_TOOLBAR, %TB_SETBITMAPSIZE, 0, MAKLNG(16,16)
    
    
    'Original assignment
    '      Tabm.nID = %IDB_STD_SMALL_COLOR ' Use the ID of the bitmap image, ie, %ID_TOOLBAR
    'Previous attempt at using resource .BMP
    '      Tabm.nID = LoadBitmap( Tabm.hInst, "STBAR")
    
    
    'Current attempt
          hBmp& = LoadBitmap( Tabm.hInst, BYVAL 2)
          Tabm.nID = 2
       ELSE
          CONTROL SEND hDlg&, %ID_TOOLBAR, %TB_SETBITMAPSIZE, 0, MAKLNG(32,32)
    
    
    'Original assignment
    '      Tabm.nID = %IDB_STD_LARGE_COLOR ' Use the ID of the bitmap image, ie, %ID_TOOLBAR
    'Previous attempt at using resource .BMP
    '      Tabm.nID = LoadBitmap( Tabm.hInst, "LTBAR")
    
    
    'Current attempt
          hBmp& = LoadBitmap( Tabm.hInst, BYVAL 1)
          Tabm.nID = 1
       END IF
    
    
       CONTROL SEND hDlg&, %ID_TOOLBAR, %TB_BUTTONSTRUCTSIZE, SIZEOF(Tbb(0)), 0
       CONTROL SEND hDlg&, %ID_TOOLBAR, %TB_ADDBITMAP, 36, VARPTR(Tabm)
    'Note: bitmap is 36 images (id 0-35)
    
    
       ' Set the buttons
       CONTROL SEND hDlg&, %ID_TOOLBAR, %TB_ADDBUTTONS, %ToolButtons, VARPTR(Tbb(0))
    This code thrashes my HD before GPF. I was truly hoping for easy
    DDT solution so that I don't have to make major changes to a ton
    of existing code.

    Has anyone successfully used their own bitmap resource with a DDT
    toolbar? What am I doing wrong?



    ------------------
    Bernard Ertl

    Leave a comment:


  • Borje Hagsten
    replied
    Here's how I've done it - TOOLBAR.BMP is a bitmap with 26 16x16 bitmaps
    placed side by side in a long low - this making it a 416x16 bmp. In
    resource file, RC:
    Code:
    #include "c:\pb\pbdll60\winapi\resource.h"
    1  BITMAP  TOOLBAR.BMP
    I sometimes like using numbers, so I've set id to 1 there. Then in code
    (here I only use 21 of those 26 available):
    Code:
    CASE %WM_CREATE
     
      'Fill the TBBUTTON array with button information
      DIM tbb(20) AS STATIC TBBUTTON
     
      tbb(0).iBitmap = 0                : tbb(0).idCommand = %IDM_NEW
      tbb(0).fsState = %TBSTATE_ENABLED : tbb(0).fsStyle   = %TBSTYLE_BUTTON
      tbb(1).iBitmap = 1                : tbb(1).idCommand = %IDM_OPEN
      tbb(1).fsState = %TBSTATE_ENABLED : tbb(1).fsStyle   = %TBSTYLE_DROPDOWN
      tbb(2).iBitmap = 3                : tbb(2).idCommand = %IDM_SAVE
      tbb(2).fsState = %TBSTATE_ENABLED : tbb(2).fsStyle   = %TBSTYLE_BUTTON
      tbb(3).fsStyle = %TBSTYLE_SEP     : tbb(3).idCommand = 700
      tbb(4).iBitmap = 5                : tbb(4).idCommand = %IDM_CUT
      tbb(4).fsState = %TBSTATE_ENABLED : tbb(4).fsStyle   = %TBSTYLE_BUTTON
      tbb(5).iBitmap = 6                : tbb(5).idCommand = %IDM_COPY
      tbb(5).fsState = %TBSTATE_ENABLED : tbb(5).fsStyle   = %TBSTYLE_BUTTON
      tbb(6).iBitmap = 7                : tbb(6).idCommand = %IDM_PASTE
      tbb(6).fsState = %TBSTATE_ENABLED : tbb(6).fsStyle   = %TBSTYLE_BUTTON
      tbb(7).fsStyle = %TBSTYLE_SEP     : tbb(7).idCommand = 701
     
      '.. etc. up to tbb(20)
     
      'Create the toolbar window
      hToolbar = CreateToolbarEx(hWnd, %WS_CHILD OR %WS_CLIPCHILDREN OR %WS_VISIBLE OR %TBSTYLE_TOOLTIPS, _
                                 %ID_TOOLBAR, 26, hInst, 1, _
                                 tbb(0), UBOUND(tbb) + 1, 0, 0, 16, 16, LEN(TBBUTTON))
    The number after %ID_TOOLBAR tells the function to consider 26 bitmaps.
    The number after hInst tells it what resource id to use, here 1.
    iBitmap in the structure above tells it what bitmap part to use for
    that particular button. 16, 16 is the size of each bitmap-part.


    ------------------

    Leave a comment:


  • Bern Ertl
    replied
    How does one find the "identifier" of a bitmap resource?

    I'm gathering that this is not the same as the bitmap
    handle returned from LoadBitmap?



    ------------------
    Bernard Ertl

    Leave a comment:


  • Bern Ertl
    started a topic DDT toolbar help desperately needed...

    DDT toolbar help desperately needed...

    hi folks.

    i'm trying to make use of lance's ddt toolbar code posted here:
    http://www.powerbasic.com/support/pb...ad.php?t=23151


    with my own toolbar bitmaps. see my last post here:
    http://www.powerbasic.com/support/pb...ead.php?t=4060

    i'm sure the solution(s?) are very simple, but i'm working in a
    dark room without a light! help!



    ------------------
    bernard ertl
Working...
X