I'm working with VBA for Excel 2003. I created UserForm1 and added a command button. I can manipulate the properties of UserForm1 using the form's hwnd. For example, I stripped the border, max/min, and caption properties. I'd like to create the same uniform look for child controls such as the button but graphical controls don't have handles. Is there a way to redraw graphical controls using the API? Thank you for your input.
Win32 API Graphical Controls - How to Redraw
Collapse
X
-
tbostwick,
My suggestion is that you use the attributes for UserForm1 to control it's look and feel. Try to stay within the capabilities of VBA, rather than using calls to the Win32 API. The controls that you put down have similar attributes that you can manipulate.
Since most attributes can be manipulated at design time, they will be saved when you save the spreadsheet, there is then no need to override them through the Win32 API.
Hope this helps,
Oralloy -
Hi Oralloy: Thank you for your reply. Issue #1 is that VBA allows very little customization of controls. For example, you can't remove the close 'X' or change the border without calls to the API. Issue #2 is that graphical child controls such as a command button aren't windows and don't have handles so you can't modify them using the same API calls that modify the form. Which leads to Issue #3, How do you control how graphical controls are drawn? This seems to be a pretty major issue with Windows development so there must be an answer.Comment
-
tbostwick,
First, a proviso - my full-up Office-pro system died a virus death a little while ago, and I gave it to my kid as an excuse for my new toy. Thus, I am working from memory today. If I am wasting your time, tell me, please.
Yes, issue #1 is a pain in the tail, especially if you want to change window styles on the fly. That said, my experience in composing relatively small applications is that the available functionality was adequate to my needs. I'm not sure what you are facing, but all of the principle window styles should be available.
Also, you might try setting the BorderStyle property of your form (in the forms editor) to 0 or 1 (borderless or thin, respectively). The 2003 reference I found is here.
Another sleezy trick you might use is this, but it really isn't professional at all:
Code:Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = vbFormControlMenu Then Cancel = True MsgBox "Please use the Close Form button!" End If End Sub
The example above is for VBA 6, however I think that it might help you with your issue #3.
Kind Regards,
OralloyComment
-
Tim,
I'm glad that helps you some. I know the reference is dated, but VB hasn't changed all that much over time.
May I ask what you are trying to achieve in terms of look, feel, and behaviour of the application you're working on?
--OralloyComment
Comment