Announcement

Collapse
No announcement yet.

Transparent Text Overlay

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

  • Transparent Text Overlay

    I'm using bitmaps as buttons in my latest project. The bitmaps are applied to the dialog using GRAPHIC RENDER. I would like to map a text legend on to the bitmaps in such a way that it looks like the text is part of the bitmap. Is this possible? :confused2: If so, a piece of sample code would be greatly appreciated.

  • #2
    I'm assuming you want something like
    Color Text that color stands for
    color2 text that color2 stands for

    after rendering the bmp, just print a graphic box (and/or xprint) with color with the text It should work just fine.
    Client Writeup for the CPA

    buffs.proboards2.com

    Links Page

    Comment


    • #3
      Maybe this is the kind of thing you were after?
      I've added code for an 'image button' for comparison. Maybe you have code to alter the graphic control so it reacts to being clicked - to give the user visual feedback like a 'normal' button does?
      Probably you would have to subclass the control and redraw on Button Down / Button Up events..
      Code:
      #Dim All
      #Register None
      #Compile Exe
      #Include "WIN32API.INC"
       
      %GFX_Button1  = 102
      %IMG_Button2  = 103
      '------------------/
       
      CallBack Function DlgProc() As Long
       
        Select Case CbMsg
          Case %WM_InitDialog
            Static hBmp1, hBmp2, hBmp3, hFont1 As Dword 
            Font New "Arial", 18, 1, 0, 0, 0 To hFont1
       
            ' Using 'Render'
            Graphic Bitmap New 128, 128 To hBmp1                            ' Create memory bitmap
            Graphic Attach hBmp1, 0
            Graphic Set Font hFont1
            Graphic Render "C:\Windows\Gone Fishing.bmp", (0,0)-(128,128)   ' render image into bitmap
            Graphic Set Pos (12, 45)
            Graphic Color %BLACK, -2
            Graphic Print "Button 1"                                        ' print onto it
       
            Graphic Attach CbHndl, %GFX_Button1
            Graphic Copy hBmp1, 0                                           ' copy to the graphic control
       
            ' Using 'Load'
            Graphic Bitmap Load "C:\Windows\Gone Fishing.bmp", 128, 128 TO hBmp2 ' Load memory bitmap
            Graphic Attach hBmp2, 0
            Graphic Set Font hFont1
            Graphic Set Pos (12, 45)
            Graphic Color %BLACK, -2
            Graphic Print "Button 2"                                        ' print onto it
       
            Graphic Save  "Temp2.bmp"         ' Save modified image to temp file
       
            hBmp3 = LoadImage(0, "Temp2.bmp", %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
            Control Send CbHndl, %IMG_Button2, %BM_SETIMAGE, %IMAGE_BITMAP, hBmp3   ' copy to button
       
          Case %WM_Command
            Select Case CbCtl
              Case %GFX_Button1
                If CbCtlMsg = %BN_Clicked Or CbCtlMsg = 1 Then
                  MsgBox "Button1 clicked!"
                End If
              Case %IMG_Button2
                If CbCtlMsg = %BN_Clicked Or CbCtlMsg = 1 Then
                  MsgBox "Button2 clicked!"
                End If
              Case %IDCANCEL
                If CbCtlMsg = %BN_Clicked Or CbCtlMsg = 1 Then
                  Dialog End CbHndl, 0
                End If
            End Select
       
          Case %WM_Destroy
            Graphic Attach hBmp1, 0
            Graphic Bitmap End
            Graphic Attach hBmp2, 0
            Graphic Bitmap End
            Kill "Temp2.bmp"
        End Select
      End Function
      '------------------/DlgProc
       
      Function PBMain() As Long
       Local hDlg As Dword
       
        Dialog New Pixels, 0, "GFX Button Test", , , 360, 250, %WS_OVERLAPPEDWINDOW, To hDlg
          Control Add Button,  hDlg, %IDCANCEL, "Exit", 280, 215, 75, 25
          Control Add Graphic, hDlg, %GFX_Button1, "", 40, 15, 128, 128, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _
            %SS_NOTIFY, %WS_EX_STATICEDGE 'OR %WS_EX_CLIENTEDGE 
          Control Add Button,  hDlg, %IMG_Button2, "", 190, 15, 128, 128, %BS_BITMAP    ' BitMap style
        Dialog Show Modal hDlg, Call DlgProc
       
      End Function
      '------------------/PBMain
      Rgds, Dave

      Comment


      • #4
        Many Thanks Dave! That was exactly what I was looking for.

        Comment

        Working...
        X