How to set ComboBox to Flat Style

kidmsoft
kidmsoft used Ask the Experts™
on
Hello, Experts

I spent a lot of time to solve this problem but it seem to worst.First time I have been tried to crated an ActiveX control and then laid down a ComboBox to the UserControl area.When ActiveX control have set to Flat style my program will set the inner combo's size more larger than UserControl's size that will make it seem to not have border. It's seem to OK, but the problem of use ActiveX control that is VB does not support to create a lot of Dynamic ActiveX Controls.When I try to do like:


         Dim i As Integer
         On Error GoTo trap
         For i = 1 To 1000
            Me.Controls.Add "MyActiveXControl.XCombo",
                             _"control" & i
         Next
         Debug.Print "Finished"
         Exit Sub
         trap:
         If Err.Number = 743 Then
            Debug.Print "Error 743 loading control #" & i
         End If
 
program will come to error.I found something about Error 743 at

http://support.microsoft.com/default.aspx?scid=KB;en-us;q191864 

It tell me that VB cannot do like that.However I must do somethings like laying down a lot of controls,because my work is creating an ActiveX Control that is like a SpreadSheet which can insert a control(Combo, CheckBox, CommandButton) in to each cell.

If I use an ActiveX control and let it's appearance to  Flat Style I will cannot put a lot of Controls in to my SpreadSheet, so I try to use MSWLess.ocx as Microsoft's instruction but I don't know how to set WLCombo in to Flat Style. Have any API function that can do that.

I don't know why Microsoft had been protect Appearance Property of ComboBox,that is not not enough,there are a lot of things in VB ,for example trap an event,also confuse and have no encapsulation.If we solve those problems we must use API Functions and Messaging that will can make the program have a lot of mistake.

However,Would you like to tell me about Setting ComboBox to Flat style(especially WLCombo)?

Best regard.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can use SetWindowLong like this:

   Private Sub MDIForm_Load()
        Dim L as Long
        L = GetWindowLong(Me.hWnd, GWL_STYLE)
        L = L And Not (WS_BORDER)
        L = SetWindowLong(Me.hWnd, GWL_STYLE, L)
     End Sub

 #If Win32 Then
      Private Declare Function SetWindowLong Lib "user32" Alias _
         "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
         ByVal dwNewLong As Long) As Long
      Private Declare Function GetWindowLong Lib "user32" Alias _
         "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) _
         As Long
   #Else
      Declare Function SetWindowLong Lib "User" (ByVal hwnd As Integer, _
         ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
       Declare Function GetWindowLong Lib "User" (ByVal hwnd As Integer, _
         ByVal nIndex As Integer) As Long
   #End If

   Const WS_BORDER = &H800000
   Const GWL_STYLE = (-16)

Author

Commented:
I have tried to do like that but WS_BORDER will only set the Form come to be no have Minimize-Maximize-Close button.

If you have another solution tell me please
This is the proper solution to removing the border from any control, you need to replace Me.hWnd with XCombo.hwnd (or whatever your control name is and if you're using control arrays, it would be XCombo(Index).hwnd).  Also you don't want to put this in MDIForm_Load of course.  It is setting the form's border because you are passing in the form's hwnd. pass in the proper control's hwnd and all should be well.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I have tried to do like this:


#If Win32 Then
     Private Declare Function SetWindowLong Lib "user32" Alias _
        "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
        ByVal dwNewLong As Long) As Long
     Private Declare Function GetWindowLong Lib "user32" Alias _
        "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) _
        As Long
#Else
     Declare Function SetWindowLong Lib "User" (ByVal hwnd As Integer, _
        ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
      Declare Function GetWindowLong Lib "User" (ByVal hwnd As Integer, _
        ByVal nIndex As Integer) As Long
#End If

Const WS_BORDER = &H800000
Const GWL_STYLE = (-16)
 
 



Private Sub Form_Load()
       Dim L As Long
       L = GetWindowLong(Combo1.hwnd, GWL_STYLE)
       L = L And Not (WS_BORDER)
       L = SetWindowLong(Combo1.hwnd, GWL_STYLE, L)

End Sub


But Combo1 still 3D style.Would you tell me what's a mistake that I have done?

You're right, it doesn't seem to work.  It should, but doesn't seem to.  I also tried several other border values separately and in tandem with each other to no avail, but they only seem to lock up the control or not perform as I expect.  If I find something else, I'll post.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- refund and close
Please leave any comments here within the
next seven days.
Per recommendation, points refunded and question closed.

Netminder
EE Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial