Lines on a button

Just starting out? Need help? Post your questions and find answers here.
User avatar
Stefan Schnell
User
User
Posts: 85
Joined: Wed May 07, 2003 2:53 pm
Location: Germany - Oberirsen
Contact:

Lines on a button

Post 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
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Can we have a working sample ?
User avatar
Stefan Schnell
User
User
Posts: 85
Joined: Wed May 07, 2003 2:53 pm
Location: Germany - Oberirsen
Contact:

Post 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
Mr Skunk
User
User
Posts: 12
Joined: Wed May 07, 2003 3:40 pm

Post 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???
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post 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
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post 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
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
User avatar
Stefan Schnell
User
User
Posts: 85
Joined: Wed May 07, 2003 2:53 pm
Location: Germany - Oberirsen
Contact:

Post by Stefan Schnell »

Hello Mr Skunk and Danilo,
thanks for your tips.
Bye
Stefan
Post Reply