Announcement

Collapse
No announcement yet.

Line does more than advertised

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

  • Michael Mattias
    replied
    Code:
    Case %IDC_LineC
                   hBrush = CreateSolidBrush(%RGB_DarkRed)   'has SS_Notify
                   Function = hBrush
    = GDI Leak. A new GDI object is created each time you call CreateSolidBrush.

    Leave a comment:


  • Gary Beene
    replied
    Another version ...

    When I try to set the Line Control color from within WM_CtlColorStatic, I see the same result. Unless I add %SS_Notify to the Line control style, the color of the control does not change.

    2nd Line control does not use %SS_Notify

    Code:
    'Compilable Example:
    #Compile Exe
    #Dim All
    #Include "Win32API.inc"
    %IDC_LineA = 500 : %IDC_LineB = 501 : %IDC_LineC = 502
    Global hDlg,hDC,hBrush as Dword
    Function PBMain() As Long
       Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
       Control Add Line, hDlg, %IDC_LineA,"", 50,10,100,20, %SS_Notify
       Control Add Line, hDlg, %IDC_LineB,"", 50,40,100,20
       Control Add Line, hDlg, %IDC_LineC,"", 50,70,100,20, %SS_Notify
       Dialog Show Modal hDlg Call DlgProc
    End Function
    CallBack Function DlgProc() As Long
       Select Case Cb.Msg
          Case %WM_CtlColorStatic   'wParam is hDC  lParam is hControl
             Select Case GetDlgCtrlID(Cb.lParam)
                Case %IDC_LineA 
                   Function = GetStockObject(%White_Brush)   'has SS_Notify
                Case %IDC_LineB 
                   Function = GetStockObject(%White_Brush)   'does NOT has SS_Notify
                Case %IDC_LineC
                   hBrush = CreateSolidBrush(%RGB_DarkRed)   'has SS_Notify
                   Function = hBrush
             End Select
          Case %WM_Destroy
             DeleteObject hBrush
       End Select
    End Function

    Leave a comment:


  • Gary Beene
    replied
    In the FWIW column, the method still works. As Barry notes, use at your own risk.

    These are all lines. The last 3 use the method described above.



    Code used to create the image:
    Code:
    'Compilable Example:
    #Compile Exe
    #Dim All
    #Include "Win32API.inc"
    %IDC_LineA = 500 : %IDC_LineB = 501 : %IDC_LineC = 502 : %IDC_LineD = 503
    %IDC_LineE = 504 : %IDC_LineF = 505 : %IDC_LineG = 506 : %IDC_LineH = 507 : %IDC_LineI = 508
    Global hDlg As Dword
    Function PBMain() As Long
       Dialog New Pixels, 0, "Test Code",300,300,200,300, %WS_OverlappedWindow To hDlg
       Control Add Line, hDlg, %IDC_LineA,"Push", 50,10,100,20, %SS_BlackFrame
       Control Add Line, hDlg, %IDC_LineB,"Push", 50,40,100,20, %SS_GrayFrame
       Control Add Line, hDlg, %IDC_LineC,"Push", 50,70,100,20, %SS_WhiteFrame
    
       Control Add Line, hDlg, %IDC_LineD,"Push", 50,100,100,20, %SS_BlackRect
       Control Add Line, hDlg, %IDC_LineE,"Push", 50,130,100,20, %SS_GrayRect
       Control Add Line, hDlg, %IDC_LineF,"Push", 50,160,100,20, %SS_WhiteRect
    
       Control Add Line, hDlg, %IDC_LineG,"", 50,190,100,20, %SS_Notify
       Control Set Color hDlg, %IDC_LineG, %Red, %Red
       Control Add Line, hDlg, %IDC_LineH,"", 50,220,100,20, %SS_Notify
       Control Set Color hDlg, %IDC_LineH, %Green, %Green
       Control Add Line, hDlg, %IDC_LineI,"", 50,250,100,20, %SS_Notify
       Control Set Color hDlg, %IDC_LineI, %Blue, %Blue
    
       Dialog Show Modal hDlg
    End Function
    Last edited by Gary Beene; 12 Mar 2012, 12:32 AM.

    Leave a comment:


  • Barry Marks
    replied
    Finding something undocumented like this is real nice until a future version doesn't do it. I'd be careful not to use it in something that will continue to matter.

    Barry

    Leave a comment:


  • Gary Beene
    replied
    Except that a LINE control won't do angles. I can plot an angled line made of small LINEs, but a line on a graphic target should be tons faster.

    Leave a comment:


  • Gary Beene
    replied
    One thing to do with this trick is to put a colored grid on a dialog, rather than using a separate graphic window or a graphic control. I tried it and it works. A thin grid was instantly drawn. A tight grid filled slowly - that's a lot of controls.

    I guess pretty much anything you can do with a line/box on a graphic target is an option - but on a dialog.

    Having just started using PowerBASIC I don't know if that's important or not.

    Leave a comment:


  • Gary Beene
    replied
    The method works with a 1-pixel wide line too.

    I'm still playing with it - looking for how to make a different colored border (without just putting two line controls, one over the other of different colors, one smaller than the other).

    Leave a comment:


  • Gary Beene
    started a topic Line does more than advertised

    Line does more than advertised

    I don't know how useful this is, here's something I found out while playing with some code.

    In the Help file I read that CONTROL SET COLOR won't work with line controls. I also read that the LINE control won't display text.

    So I was playing around with code and tried this:

    Control Add Line, hDlg, 507, "LINE", 200, 80, 40, 40, %ss_notify
    Control Set Color hdlg, 507, %blue, %red

    This gives me a colored line control with the word "LINE" in it.

    I played some more with other style& values and found that %ss_notify enables the color/text display. I also tried some LABEL style& values and they worked too. I could center the text or get it to wordwrap, for example.

    It's as though the line control works like a label control with the %ss_notify style& value added.
Working...
X