Page 1 of 1

Lines on a button

Posted: Wed May 07, 2003 3:07 pm
by Stefan Schnell
Hello community,
I want to draw lines on a button (e. g. a rectangle), I use the following code:

Code: Select all

      CreateGadgetList(WindowID())
      ButtonGadget(0, 0, 0, 64, 64, "")
      GadgetToolTip(0, "Process")
      *hButton = GadgetID(0)
      *hDC = GetDC_(*hButton)
;      MessageRequester("hDC", Str(*hDC), #PB_MessageRequester_Ok)
        MoveToEx_(*hDC, 5, 14, 0)
        LineTo_(*hDC, 59, 14)
        LineTo_(*hDC, 59, 50)
        LineTo_(*hDC, 5, 50)
        LineTo_(*hDC, 5, 14)
      ReleaseDC_(*hButton, *hDC)
If I deactivate the remark sign of the MessageRequester the code works, but without MessageRequester I see nothing.
Who can give me a tip.
Thanks.
Stefan

Posted: Wed May 07, 2003 3:17 pm
by Fred
Can we have a working sample ?

Posted: Wed May 07, 2003 8:47 pm
by Stefan Schnell
Hello Fred,
here is a complete example:

Code: Select all

    ScreenWidth.w = GetSystemMetrics_(#SM_CXSCREEN)
    ScreenHeight.w = GetSystemMetrics_(#SM_CYSCREEN)

    MausPos.POINT
    GetCursorPos_(MausPos)

    If (MausPos\x + 64) > ScreenWidth
      xPos.w = ScreenWidth - 64
    Else
      xPos.w = MausPos\x
    EndIf
    
    If (MausPos\y + 64) > ScreenHeight  
      yPos.w = ScreenHeight - 64
    Else
      yPos.w = MausPos\y
    EndIf

    OpenWindow(0, xPos, yPos, 64, 64, #PB_Window_BorderLess, "")

      CreateGadgetList(WindowID())
      ButtonGadget(0, 0, 0, 64, 64, "")
      GadgetToolTip(0, "Verarbeitung")
      *hButton = GadgetID(0)
      *hDC = GetDC_(*hButton)
      MessageRequester("hDC", Str(*hDC), #PB_MessageRequester_Ok)
        MoveToEx_(*hDC, 5, 14, 0)
        LineTo_(*hDC, 59, 14)
        LineTo_(*hDC, 59, 50)
        LineTo_(*hDC, 5, 50)
        LineTo_(*hDC, 5, 14)
      ReleaseDC_(*hButton, *hDC)

      Repeat
        EventID = WaitWindowEvent()
        Select EventID
          Case #PB_EventGadget
            Select EventGadgetID()
              Case 0
                Result = 100
                Quit = 1
            EndSelect
          Case #PB_EventCloseWindow
            Quit = 1  
        EndSelect
      Until Quit = 1        

    CloseWindow(0)

End
So it works, it works not if I remark the line with the MessageRequester.
Thanks.
Stefan

Posted: Thu May 08, 2003 3:12 am
by Mr Skunk
I've made some tests, and apparently, your listing seems to use some windows events to draw lines.
If you replace Messagerequester() by

Code: Select all

for i=1 to 4:windowevent():next
it works. (Try more than 4 if it does not work for you).
I don't know why, if it's a bug or not and if there is another better solution... Fred???

Posted: Thu May 08, 2003 6:07 am
by Danilo

Code: Select all

    ScreenWidth.l  = GetSystemMetrics_(#SM_CXSCREEN) 
    ScreenHeight.l = GetSystemMetrics_(#SM_CYSCREEN) 

    MausPos.POINT 
    GetCursorPos_(MausPos) 

    If (MausPos\x + 64) > ScreenWidth 
      xPos.w = ScreenWidth - 64 
    Else 
      xPos.w = MausPos\x 
    EndIf 
    
    If (MausPos\y + 64) > ScreenHeight  
      yPos.w = ScreenHeight - 64 
    Else 
      yPos.w = MausPos\y 
    EndIf 

    OpenWindow(0, xPos, yPos, 64, 64, #PB_Window_BorderLess, "") 

      CreateGadgetList(WindowID()) 
      ButtonGadget(0, 0, 0, 64, 64, "") 
      GadgetToolTip(0, "Verarbeitung")
      
      While WindowEvent():Wend
      
      *hButton = GadgetID(0) 
      *hDC = GetDC_(*hButton) 
      ;MessageRequester("hDC", Str(*hDC), #PB_MessageRequester_Ok) 
        MoveToEx_(*hDC, 5, 14, 0) 
        LineTo_(*hDC, 59, 14) 
        LineTo_(*hDC, 59, 50) 
        LineTo_(*hDC, 5, 50) 
        LineTo_(*hDC, 5, 14) 
      ReleaseDC_(*hButton, *hDC) 

      Repeat 
        Select WaitWindowEvent() 
          Case #PB_EventGadget 
            Select EventGadgetID() 
              Case 0: End
            EndSelect 
          Case #PB_EventCloseWindow : End
        EndSelect 
      ForEver

Posted: Thu May 08, 2003 6:15 am
by Danilo
The above isnt a good way... better use a ButtonImageGadget()
or ImageGadget().

Code: Select all

    ScreenWidth  = GetSystemMetrics_(#SM_CXSCREEN)
    ScreenHeight = GetSystemMetrics_(#SM_CYSCREEN)

    MausPos.POINT 
    GetCursorPos_(MausPos) 

    If (MausPos\x + 64) > ScreenWidth 
      xPos = ScreenWidth - 64 
    Else 
      xPos = MausPos\x 
    EndIf 
    
    If (MausPos\y + 64) > ScreenHeight  
      yPos = ScreenHeight - 64 
    Else 
      yPos = MausPos\y 
    EndIf 

    Image1 = CreateImage(1,64,64)
      StartDrawing(ImageOutput())
        Box(0,0,64,64,GetSysColor_(#COLOR_BTNFACE)) ; clear
        FrontColor(0,0,0)
        LineXY( 5,14,59,14)
        LineXY(59,14,59,50)
        LineXY(59,50, 5,50)
        LineXY( 5,50, 5,14)
      StopDrawing()

    OpenWindow(0, xPos, yPos, 64, 64, #PB_Window_BorderLess, "") 
      CreateGadgetList(WindowID()) 
      ButtonImageGadget(0, 0, 0, 64, 64, Image1) 
      GadgetToolTip(0, "Verarbeitung")

      Repeat 
        Select WaitWindowEvent() 
          Case #PB_EventGadget 
            Select EventGadgetID() 
              Case 0: End
            EndSelect 
          Case #PB_EventCloseWindow : End
        EndSelect 
      ForEver

Posted: Thu May 08, 2003 6:53 am
by Stefan Schnell
Hello Mr Skunk and Danilo,
thanks for your tips.
Bye
Stefan