473,883 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Win32 API Graphical Controls - How to Redraw

3 New Member
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 3426
988 Recognized Expert Contributor

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,
May 26 '13 #2
3 New Member
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
988 Recognized Expert Contributor

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,
May 28 '13 #4
3 New Member
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
988 Recognized Expert Contributor

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?

May 29 '13 #6

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

Similar topics

by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4. forkme.pl calls the process creation script (createme.pl) 5. createme.pl creates my notepad.exe process, but no window shows up on my PC. The result on my web browser is:
by: Charles Law | last post by:
I have a user control created on the main thread. Let's say, for arguments sake, that it has a single property that maintains a private variable. If I want to set that property from a worker thread, do I need to use UserControl1.Invoke to set it, or can I just set it? After all, it is only changing a private variable. TIA Charles
by: Jose Michael Meo R. Barrido | last post by:
I made a custom runded rectangle usercontrol. I used a function i found on the internet. the function works fine(see "GetRoundRect" below). I use the fullowing code to make my usercontrol rounded.... ***************************************************** Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) Dim x1 As Integer = 0 Dim x2 As Integer = Me.ClientSize.Width Dim iHeight As Int32 = Me.Height Dim...
by: conset23 | last post by:
Hello. I'm working with WinForm. It has 30 same user control, each with 4 buttons, 3 labels, 3 textboxes, 2 picture boxes and uses override onPaint to draw gradient rectangle. Main form also has 2 panels with same gradient. I'm trying to reduce drawing speed on form activation. But at the moment it is too noticeable for each user control to be drawn. Tried to use double buffering on main form and on each user control, looks almost the...
by: Mau | last post by:
I ' m looking for some articles concerning the way to create graphical controls in ASP.NET or WinForms an example: I would like to create a round progress bar and so on..... I think that I have to use GDI+ but I need some resources to get started.
by: John Smith | last post by:
Hello Coould please any one to help me to find good graphical controls to create GDI in ASP.NET. Some related websites also really appreciated Thanks in Advance John
by: diogoko | last post by:
I have some code like: try { someButton.disabled = true; cpuIntensiveCode(); } finally { someButton.disabled = false; } The problem is that someButton is never disabled, because the browser
by: George | last post by:
Hello everyone, I am using C# on a Pocket PC 2003 project based on .Net Compact Framework of Visual Studio 2005. I want to re-draw some controls of a Form (Window) at a regular interval (for example, change the title of some Label or something similar). The issues I met with are, 1. My application has several Forms/Windows. How to check whether the specific Form/Window (which I want to re-draw) is active? If the Form/Window
by: Joergen Bech | last post by:
Just out of curiosity: What is your favorite method of making sure that anything that happens on a form, only happens in response to a single, external event? Take the example below. I have made it as simple as I could: Put two textboxes on a form, paste the code and run it. The idea is that whatever is typed in one box is displayed in the other box, only reversed. This is a simple example of two repre- sentations of the same data on...
by: GaryTexmo | last post by:
In my last insight, http://bytes.com/topic/c-sharp/insights/909141-object-scaling-varying-resolutions, I talked about scaling objects to a form's size so that it would always draw with the correct scale. In that, the method I used to create and store objects that could be drawn on my form was a manual approach; that is, I created and stored a list of objects, then manually drew them. While that certainly works, it means there's a lot of code...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.