472,127 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Win32 API Graphical Controls - How to Redraw

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.
May 24 '13 #1
5 3146
Oralloy
983 Expert 512MB
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
May 26 '13 #2
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.
May 28 '13 #3
Oralloy
983 Expert 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  2.   If CloseMode = vbFormControlMenu Then
  3.     Cancel = True
  4.     MsgBox "Please use the Close Form button!"
  5.   End If
  6. End Sub
Issue #2 is a pain - I know that you don't have a lot of control over most aspects of the "controls", although you can get a list of the available messages that they can process by using VBA's editor's drop-down. Looking around, I found this old example for graphic controls, which might help for pure graphical manipulation. It kind of stinks that we have to break out into the Windows API, rather than having some degree of native competence in VBA.

The example above is for VBA 6, however I think that it might help you with your issue #3.

Kind Regards,
Oralloy
May 28 '13 #4
Again, thanks very much for your detailed reply. The example you linked to looks promising, along the lines that I suspected would be required. I'll dig in and see what happens. Thanks again! --Tim
May 28 '13 #5
Oralloy
983 Expert 512MB
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?

--Oralloy
May 29 '13 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Mau | last post: by
5 posts views Thread by John Smith | last post: by
2 posts views Thread by diogoko | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.