Results 1 to 13 of 13

Thread: Api To Make Double Columns

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Santo Domingo,D.N., Dom. Rep.
    Posts
    707

    Talking Api To Make Double Columns

    I heard there is an API that u could call to make double columns in a combobox. Can anyone tell where is that API?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can on a listbox, I'm not sure about a combo. You can use SendMessage and set a tab length which makes it appear to have columns. Then when you add something that you want to go to the next column just use tab where the column should be.

    Here is a sampel project.

  3. #3
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    I agree with Edneeis and Stanich. You can't do it even with the most complex of APIs. I spend about three hours ownerdrawing and subclassing comboboxes and the farthest i've gotten is something that LOOKS like it has 2 cols but really behaves like half of one row is for the Col1 item and half of Row2 is for the 2nd ite, (at this point, James Stanich probably already figured what I am trying to do ).

    You could add a listbox below the combobox and hide it and use IT as the selection structure.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  4. #4
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    BTW, just in case if you're wondering, here's my currently unfinished code. Maybe someone else could use this to finish what I failed to do?

    VB Code:
    1. Public Type RECT
    2.     Left As Long
    3.     Top As Long
    4.     Right As Long
    5.     Bottom As Long
    6. End Type
    7. Public Type DRAWITEMSTRUCT
    8.     CtlType As Long
    9.     CtlID As Long
    10.     itemID As Long
    11.     itemAction As Long
    12.     itemState As Long
    13.     hwndItem As Long
    14.     hdc As Long
    15.     rcItem As RECT
    16.     itemData As Long
    17. End Type
    18. Public Type MEASUREITEMSTRUCT
    19.     CtlType As Long
    20.     CtlID As Long
    21.     itemID As Long
    22.     itemWidth As Long
    23.     itemHeight As Long
    24.     itemData As Long
    25. End Type
    26. Public Type LOGFONT
    27.     lfHeight As Long
    28.     lfWidth As Long
    29.     lfEscapement As Long
    30.     lfOrientation As Long
    31.     lfWeight As Long
    32.     lfItalic As Byte
    33.     lfUnderline As Byte
    34.     lfStrikeOut As Byte
    35.     lfCharSet As Byte
    36.     lfOutPrecision As Byte
    37.     lfClipPrecision As Byte
    38.     lfQuality As Byte
    39.     lfPitchAndFamily As Byte
    40.     lfFaceName(1 To 32) As Byte
    41. End Type
    42. Public Type TEXTMETRIC
    43.     tmHeight As Long
    44.     tmAscent As Long
    45.     tmDescent As Long
    46.     tmInternalLeading As Long
    47.     tmExternalLeading As Long
    48.     tmAveCharWidth As Long
    49.     tmMaxCharWidth As Long
    50.     tmWeight As Long
    51.     tmOverhang As Long
    52.     tmDigitizedAspectX As Long
    53.     tmDigitizedAspectY As Long
    54.     tmFirstChar As Byte
    55.     tmLastChar As Byte
    56.     tmDefaultChar As Byte
    57.     tmBreakChar As Byte
    58.     tmItalic As Byte
    59.     tmUnderlined As Byte
    60.     tmStruckOut As Byte
    61.     tmPitchAndFamily As Byte
    62.     tmCharSet As Byte
    63. End Type
    64.  
    65. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    66. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    67. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    68. Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    69. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    70. Public Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    71. Public Declare Function SendMessageLng Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    72. Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    73. Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    74. Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    75. Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    76. Public Declare Function GetCurrentObject Lib "gdi32" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
    77. Public Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
    78. Public Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
    79. Public Declare Function GetTextMetrics Lib "gdi32" Alias "GetTextMetricsA" (ByVal hdc As Long, lpMetrics As TEXTMETRIC) As Long
    80. Public Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    81. Public Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
    82. Public Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
    83. Public Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
    84. Public Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    85. Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    86.  
    87. '-----------------------------------------------
    88. 'TextParam
    89. Public Const DT_SINGLELINE = &H20
    90.  
    91. '-----------------------------------------------
    92. 'Combobox Styles
    93. Public Const CBS_OWNERDRAWVARIABLE = &H20&
    94. Public Const CBS_HASSTRINGS = &H200&
    95. Public Const CBS_AUTOHSCROLL = &H40&
    96. Public Const CBS_DROPDOWNLIST = &H3&
    97.  
    98. '------------------------------------------
    99. 'Window Styles
    100. Public Const WS_CHILD = &H40000000
    101. Public Const WS_CLIPCHILDREN = &H2000000
    102. Public Const WS_CLIPSIBLINGS = &H4000000
    103. Public Const WS_OVERLAPPED = &H0&
    104. Public Const WS_VISIBLE = &H10000000
    105. Public Const WS_VSCROLL = &H200000
    106.  
    107. '--------------------------------------------
    108. 'MISC.
    109. Public Const GCL_HBRBACKGROUND = (-10)
    110.  
    111. Public Const WM_CTLCOLORLISTBOX = &H134
    112. Public Const WM_DESTROY = &H2
    113. Public Const WM_DRAWITEM = &H2B
    114. Public Const WM_MEASUREITEM = &H2C
    115. Public Const WM_PAINT = &HF
    116.  
    117. Public Const GWL_STYLE = (-16)
    118.  
    119. Public Const ODS_FOCUS = &H10
    120. Public Const ODT_COMBOBOX = 3
    121. Public Const OBJ_FONT = 6
    122.  
    123. Public Const CB_ADDSTRING = &H143
    124. Public Const CB_GETITEMDATA = &H150
    125. Public Const CB_GETITEMHEIGHT = &H154
    126. Public Const CB_GETLBTEXT = &H148
    127. Public Const CB_GETLBTEXTLEN = &H149
    128. Public Const CB_SETITEMDATA = &H151
    129.  
    130. Public hwndList As Long
    131. Public hdcList As Long
    132. Public wtbrush As Long
    133. Public procOld As Long
    134.  
    135. Public ListHeight As Long
    136. Public ListWidth As Long
    137. Dim hfont As Long
    138. Public bolPlace As Boolean
    139.  
    140. Public Function WndProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    141.     Dim tItem As DRAWITEMSTRUCT
    142.     Dim mItem As MEASUREITEMSTRUCT
    143.     Dim tmetric As TEXTMETRIC
    144.     Dim sBuff As String * 255
    145.     Dim sItem As String
    146.     Dim lBack As Long
    147.     Dim icback As Long
    148.     Dim rsct As RECT
    149.     Dim temp As Long, pictop As Long
    150.    
    151.     Select Case iMsg
    152.     Case WM_MEASUREITEM
    153.         Call CopyMemory(mItem, ByVal lParam, Len(mItem))
    154.         'If mItem.CtlType = ODT_COMBOBOX Then
    155.             Call SendMessage(hwndList, CB_GETLBTEXT, mItem.itemID, ByVal sBuff)
    156.             sItem = Left(sBuff, InStr(sBuff, Chr(0)) - 1)
    157.             'mItem.itemHeight = 56
    158.             mItem.itemWidth = mItem.itemWidth
    159.            
    160.             GetTextMetrics GetDC(hwndList), tmetric
    161.             temp = tmetric.tmHeight
    162.             If mItem.itemID = -1 Then mItem.itemHeight = temp Else mItem.itemHeight = temp / 2
    163.            
    164.             Call CopyMemory(ByVal lParam, mItem, Len(mItem))
    165.            
    166.             WndProc = True
    167.             Exit Function
    168.         'End If
    169.     Case WM_DRAWITEM
    170.         Call CopyMemory(tItem, ByVal lParam, Len(tItem))
    171.         'If tItem.CtlType = ODT_COMBOBOX Then
    172.             Call SendMessage(tItem.hwndItem, CB_GETLBTEXT, tItem.itemID, ByVal sBuff)
    173.             sItem = Left(sBuff, InStr(sBuff, Chr(0)) - 1)
    174.            
    175.             GetTextMetrics GetDC(hwndList), tmetric
    176.             temp = tmetric.tmHeight
    177.            
    178.             'If tItem.itemID = -1 Then
    179.             If tItem.itemState = 4096 Or tItem.itemState = 4113 Then
    180.             ElseIf tItem.itemData = 1 Then
    181.                 tItem.rcItem.Left = (tItem.rcItem.Left + tItem.rcItem.Right) / 2
    182.                 tItem.rcItem.Top = tItem.rcItem.Top * 2 - tItem.rcItem.Bottom
    183.                 tItem.rcItem.Bottom = tItem.rcItem.Top + temp
    184.                 'tItem.rcItem.Top = 0
    185.             Else
    186.                 tItem.rcItem.Right = (tItem.rcItem.Left + tItem.rcItem.Right) / 2
    187.                 tItem.rcItem.Bottom = tItem.rcItem.Bottom * 2 - tItem.rcItem.Top
    188.             End If
    189.             If (tItem.itemState And ODS_FOCUS) Then
    190.                 icback = GetSysColor(&HD)
    191.                 lBack = CreateSolidBrush(icback)
    192.                 Call FillRect(tItem.hdc, tItem.rcItem, lBack)
    193.                 Call SetBkColor(tItem.hdc, icback)
    194.                 icback = GetSysColor(&HE)
    195.                 Call SetTextColor(tItem.hdc, icback)
    196.                 DrawText tItem.hdc, ByVal sItem, Len(sItem), tItem.rcItem, &H20
    197.                 DrawFocusRect tItem.hdc, tItem.rcItem
    198.             Else
    199.                 icback = GetSysColor(&H5)
    200.                 lBack = CreateSolidBrush(icback)
    201.                 Call FillRect(tItem.hdc, tItem.rcItem, lBack)
    202.                 Call SetBkColor(tItem.hdc, icback)
    203.                 icback = GetSysColor(8)
    204.                 Call SetTextColor(tItem.hdc, icback)
    205.                 DrawText tItem.hdc, ByVal sItem, Len(sItem), tItem.rcItem, &H20
    206.             End If
    207.             Call DeleteObject(lBack)
    208.            
    209.             WndProc = True
    210.             Exit Function
    211.         'End If
    212.     End Select
    213.     WndProc = CallWindowProc(procOld, hwnd, iMsg, wParam, lParam)
    214. End Function
    215.  
    216. Public Sub StrCpy(ByteArr() As Byte, ByVal Text As String)
    217.     Dim i As Long
    218.     For i = 1 To Len(Text)
    219.         If (i + LBound(ByteArr) - 1) < UBound(ByteArr) Then ByteArr(i + LBound(ByteArr) - 1) = Asc(Mid$(Text, i, 1))
    220.     Next
    221. End Sub
    222.  
    223. Public Function StrToByte(ByVal Text As String) As Variant
    224.     Dim ByteArr() As Byte
    225.     ReDim ByteArr(Len(Text))
    226.     Dim i As Long
    227.     For i = 1 To Len(Text)
    228.         If (i + LBound(ByteArr) - 1) < UBound(ByteArr) Then ByteArr(i + LBound(ByteArr) - 1) = Asc(Mid$(Text, i, 1))
    229.     Next
    230.     StrToByte = ByteArr
    231. End Function
    232.  
    233. Public Function Syscolor(Color As OLE_COLOR) As Long
    234.     Dim icback As Long
    235.     If (Color And &HFF000000) = &H80000000 Then icback = GetSysColor(Color - &H80000000) Else icback = BGColor
    236.     Syscolor = icback
    237. End Function


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  5. #5
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    That was the module code. here's the form code:

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim Lgfnt As LOGFONT
    3.     Dim tmetric As TEXTMETRIC
    4.    
    5.     procOld = SetWindowLong(Me.hwnd, -4, AddressOf WndProc)
    6.    
    7.     GetTextMetrics Me.hdc, tmetric
    8.     temp = tmetric.tmHeight
    9.     hwndList = CreateWindowEx(&H0, "combobox", "", WS_VISIBLE Or WS_CHILD Or CBS_AUTOHSCROLL Or CBS_HASSTRINGS Or CBS_OWNERDRAWVARIABLE Or CBS_DROPDOWNLIST, 2, 2, 250, 250, Me.hwnd, 1, App.hInstance, &H0)
    10.     Lgfnt.lfHeight = temp '-1 * m_ListItems.Item(mItem.itemData).Font.Size Or WS_MAXIMIZEBOX Or WS_OVERLAPPED Or WS_CLIPSIBLINGS Or WS_CLIPCHILDREN
    11.     Lgfnt.lfWidth = 0
    12.     Lgfnt.lfEscapement = 0
    13.     Lgfnt.lfOrientation = 0
    14.     Lgfnt.lfWeight = IIf(Me.FontBold, 700, 0)
    15.     Lgfnt.lfItalic = Abs(Me.FontItalic)
    16.     Lgfnt.lfUnderline = Abs(Me.FontUnderline)
    17.     Lgfnt.lfStrikeOut = Abs(Me.FontStrikethru)
    18.     Lgfnt.lfCharSet = Me.Font.Charset
    19.     Lgfnt.lfOutPrecision = 0
    20.     Lgfnt.lfClipPrecision = 0
    21.     Lgfnt.lfQuality = 0
    22.     Lgfnt.lfPitchAndFamily = 0
    23.     StrCpy Lgfnt.lfFaceName(), Me.FontName
    24.     hfont = CreateFontIndirect(Lgfnt)
    25.     hfont = SelectObject(GetDC(hwndList), hfont)
    26.    
    27.     AddItem "Hello"
    28.     AddItem "BYBY"
    29.     AddItem "CRASH?"
    30.     AddItem "CRASH?2"
    31. End Sub
    32.  
    33. Private Sub Form_Unload(Cancel As Integer)
    34.     Call SetWindowLong(Me.hwnd, -4, procOld)
    35. End Sub
    36.  
    37. Public Function AddItem(Text As String)
    38.     Dim place As Long
    39.    
    40.     place = SendMessageStr(hwndList, CB_ADDSTRING, 0, Text)
    41.     Call SendMessageLng(hwndList, CB_SETITEMDATA, place, Abs(bolPlace))
    42.     bolPlace = Not bolPlace
    43. End Function


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Micro : I too screwed around with tring to make a control behave in the same manner. But, after days of screwing around with it, I eventually abandoned (besides how may times do you see a combobox with multiple columns anyway?)
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    This is the best thing I've found for making a multicolumn combo, and it's kind of cheating.

    http://www.mvps.org/vbnet/index.html...bolistview.htm

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    This is what I meant about using the flexgrid (no subclassing required)
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Santo Domingo,D.N., Dom. Rep.
    Posts
    707

    Re: Well

    Originally posted by James Stanich
    Micro : I too screwed around with tring to make a control behave in the same manner. But, after days of screwing around with it, I eventually abandoned (besides how may times do you see a combobox with multiple columns anyway?)
    Morning everyone!

    Well, first i will try to check the code, second: Here, in the best place of the third rock from the sun (Dominican Republic) u have to use a combobox almost everyday, the problem is that you cannot do it, but people always ask for it.

    Third: How can i use a MsFlexGrid like a combobox to have 2 columns?

  10. #10
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Horse Tranqualizer please...!

    Couldn't you just write your own in a usercontrol?
    Subclass the combo box, when the drop down is called, cancel it and display a listview or something instead?
    To make the combo look like the selected item has columns use:
    VB Code:
    1. strEntry = Left("London" & Space(15),15)
    2. strEntry = strEntry & Left("England" & Space(15),15)
    3. 'Etc
    4. Combo1.AddItem strEntry
    Then just add the same into the listview, which has columns...???

    Understand what I'm getting at???

    Woka

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Santo Domingo,D.N., Dom. Rep.
    Posts
    707
    Thanks wokawidget!
    I will do it. It is a great idea.

  12. #12
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Copy, Copy, Copy....THUNDER CATS!

    Originally posted by Edneeis
    This is the best thing I've found for making a multicolumn combo, and it's kind of cheating.

    http://www.mvps.org/vbnet/index.html...bolistview.htm
    Errr...just realised that Edneeis posted the same thing a suggested, apart from the example it the link above doesn't use the Left comamnd to make the combo appear to have columns...

    Sorry Ed, wasn't stealing your idea, just didn't read it properly...

    Woka

  13. #13
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well technically its the VB.Net guy's idea so steal away. :>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width