Quick Search for:  in language:    
CODE,HAS,BEEN,FIXED,READ,PAGE,SEE,WRONG,ONE,A
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,014,970. lines
 Jobs: 119. postings

 How to support the site

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for Visual Basic.
Click here to see a screenshot of this code!Song/Poem Assistant
By Peter Rowan on 7/2

(Screen Shot)

Click here to see a screenshot of this code!GPA Cal
By KBM-00 on 7/2

(Screen Shot)

Click here to see a screenshot of this code!Connection Via the Telephone line.No internet or cable.Just the telephone line
By Nass ClickMan on 7/2

(Screen Shot)

DBTool
By Make Strömberg on 7/2


Click here to see a screenshot of this code!MSChart Simple Example
By Sebastian Pereira on 7/2

(Screen Shot)

CString v1.5
By Ultimatum on 7/2


Tablature Pro
By Michael McMullen on 7/2


Click here to see a screenshot of this code!MSN Password Decryptor
By Muhammad Sufyan Ansari on 7/2

(Screen Shot)

Mp3 Paker
By Michael McMullen on 7/2


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Real C++ Buttons (Fixed)

Print
Email
 

Submitted on: 2/10/2000
By: Randy Mcdowell (Nebuland Technologies)  
Level: Advanced
User Rating: By 107 Users
Compatibility:VB 4.0 (32-bit), VB 5.0, VB 6.0

Users have accessed this code 14068 times.
 
 
     Notice: THIS CODE HAS BEEN FIXED! PLEASE READ THE COMMENTS AT THE BOTTOM OF THE PAGE TO SEE WHAT WAS WRONG BEFORE. Create real C++ style command buttons with ONE line of code!!! You can use this code on any of your commands buttons. You will loose any images and the BackColor of the button, but that really doesn't matter because you can 'paint' images onto the button using the API. Make sure you set the style property to 'Graphical' or this will not work!. OK here is how it works. You see, by default Visual Basic's command buttons are drawn with the 'Default Push Button' style, which makes them flat and ugly when pushed. But when you set the style to 'Graphical' its really just a C++ button with a single pixel outline drawn around it. This code basically just stops the button from drawing that line to create a sunken style button. This code is not compatible with Visual Basic 4.0/32 because its buttons don't have the style property. However, in Visual Basic 4.0 you can apply the code to an option button and it will appear as a C++ push button (they both have the same basic events and properties: Click, MouseMove, etc...) which is a 'rigged' kind of way of getting it in to Visual Basic 4.0...hehe. I wrote this code because I got tired of all the people trying to create C++ style buttons with CreateWindowEx and Message Hooks, and all that other difficult stuff.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: Real C++ Buttons (Fixed)
' Description:Notice: THIS CODE HAS BEEN
'     FIXED! PLEASE READ THE COMMENTS AT THE B
'     OTTOM OF THE PAGE TO SEE WHAT WAS WRONG 
'     BEFORE. 
Create real C++ style command buttons With ONE line of code!!! You can use this code on any of your commands buttons. You will loose any images and the BackColor of the button, but that really doesn't matter because you can 'paint' images onto the button using the API. Make sure you Set the style Property to 'Graphical' or this will Not work!. OK here is how it works. You see, by default Visual Basic's command buttons are drawn with the 'Default Push Button' style, which makes them flat and ugly when pushed. But when you set the style to 'Graphical' its really just a C++ button with a Single pixel outline drawn around it. This code basically just stops the button from drawing that line to create a sunken style button. This code is not compatible with Visual Basic 4.0/32 because its buttons don't have the style property.
However, In Visual Basic 4.0 you can apply the code To an option button and it will appear as a C++ push button (they both have the same basic events and properties: Click, MouseMove, etc...) which is a 'rigged' kind of way of getting it in to Visual Basic 4.0...hehe. I wrote this code because I got tired of all the people trying to create C++ style buttons With CreateWindowEx and Message Hooks, and all that other difficult stuff.
' By: Randy Mcdowell (Nebuland Technolog
'     ies)
'
' Inputs:You will need the hWnd of the c
'     ommand button.
'
' Assumes:Set the buttons style property
'     to 'Graphical' first!!!
'
' Side Effects:You will loose the backco
'     lor and images.
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=5983&lngWId;=1'for details.'**************************************

Sub Form_Load()

' Command1.Style = 1 ' Graphical SendMessage Command1.hWnd, &HF4;&, &H0;&, 0& End Sub


Other 4 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
2/11/2000 4:06:07 AM:Alex
It's not work!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/11/2000 10:44:48 AM:Walker
I don't see that this code does 
anything.  It seems to have the same 
effect just to set a button's 
appearance to Graphical.  At least, 
that's what I see under my copy of VB 5 
Enterprise Edition.  Maybe other 
versions behave differently(?)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/11/2000 8:41:44 PM:Simon
Hey Randy - this does not work. The 
effect is the same as setting a buttons 
property t graphical... I use VB6 
Enterprise.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/12/2000 11:57:57 PM:Randy Mcdowell
Part #1 of 
Message!
-------------------
For 
all you who can't get the code to work, 
let me take you through the 
steps:
First of all, The 
Professional and Control Creation 
editions of Visual Basic 5 have an 
AutoOverRide feature that keeps you 
from modifying the style of a button 
via the API when the control's style 
property is set to 'Standard'. However, 
when it is set to 'Graphical', you can 
modify this attribute via the API. Here 
is how this is done:
(Microsoft 
Platform SDK)
(Put this in the form 
with the button, if you put it in a 
module, change private reserved words 
to public)
Private Declare Function 
SendMessage Lib "User32.dll" Alias 
"SendMessageA" (ByVal hWnd As Long, 
ByVal wMsg As Long, ByVal wParam As 
Long, lParam As Any) As Long
' 
SetStyle Button Message
Private Const 
BM_SETSTYLE = &HF4
' Available 
PushButton Styles
Private Const 
BS_DEFPUSHBUTTON = &H1& ' 
Standard
Private Const BS_PUSHBUTTON = 
&H0;& 'API Style
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/13/2000 12:02:57 AM:Randy Mcdowell

Part #2 of 
Message!
-------------------
Then 
when you send the message to the 
buttons hWnd it sets the style. Note: 
For some editions of Visual Basic you 
might have to use FindWindow to get 
this to work properly:
Dim hCmd as 
long
hCmd = FindWindow("Button", 
Command1.Caption)
SendMessage hCmd, 
BM_SETSTYLE, BS_PUSHBUTTON, 0&
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/13/2000 12:05:32 AM:Randy Mcdowell
Please respond with what kind of code 
you would like me to write in the 
future, I need to know what other 
people need in their applications.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/13/2000 9:05:38 AM:jlewey
The code works if you fix the wMsg part 
of the call.
in your line
SendMessage 
Command1.hWnd, &H4&, &H0&, 0&
should 
read &HF4; instead of &H4;&
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/14/2000 1:51:26 AM:Randy Mcdowell
I am sorry I did not see my mistake but 
I have re-posted the code as *fixed*. 
Thank you very much for pointing that 
out.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/14/2000 11:00:00 AM:vb lucas
the code that be cool is to make is 
graphical menu buttons like the one in 
office 2000.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/14/2000 10:45:53 PM:Randy Mcdowell
I'm not trying to create new buttons or 
controls, I'm trying to enhance what VB 
already has without needing the 
overhead of a third-party OCX, that is 
my mission.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/14/2000 10:48:49 PM:Velure
Wow! This code is SSSSOOOO simple yet 
it is so great to make your apps look 
professional...why didn't anybody think 
of this before... but if they did I 
didn't know about it. Thanks man and 
keep on programmin'!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/14/2000 10:51:53 PM:RandyMcdowell
yes the code is very simple. But I 
don't understand why it is getting so 
many votes...I mean it's not like it 
can animate a sprite on a 3d graphical 
engine at pentium speed. Could you 
people please tell me what you like 
about this code so much that you are 
voteing for it???
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/14/2000 10:56:15 PM:Shannon The Sweetheart Hacker
Duh! Do you know how long people have 
been trying to get C++ buttons into 
their app...I mean for a long time it 
has just been one of those things that 
only VC++ programmer's could do..kinda 
like the DLLs. But now you fixed this 
little problem with ONE line of 
code..thats what makes this simple 
stuff so great...
Deadly Kisses To 
All!!
~~ STSH ~~~
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/19/2000 9:47:04 PM:jahan
Great code...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/22/2000 3:52:39 PM:Jason Alex
This is a perfect example of how you 
can use the API to make VB more 
powerful...I'll give you a Good vote 
for the code, I would give Excellent if 
you had included the routines to paint 
graphics onto the button with the API.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/22/2000 4:00:04 PM:Clamped Balls
I don't have to MsgHook the button to 
see if it is being clicked, pushed, 
etc.. Do I? I mean how do I know when 
the button is being clicked? 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/22/2000 4:03:36 PM:Randy Mcdowell (Author)
Hey Clamped Balls (that sounds very 
painful) this code just modifies an 
existing VB command button, which means 
it will use the same Font object and 
still have all the same  events, etc.. 
The only things you will loose is your 
BackColor and any images. Hope this 
helps!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/24/2000 5:15:00 PM:d00d
could someonw please please explain 
what the hell this code is supposed to 
do????
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/25/2000 2:04:20 PM:Tom Welch
Swell, It took me a few minutes to 
notice what effect the code was 
causing... frankly, it's not worth it 
to me or my users.  Thanks for the 
effort, though.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/1/2000 1:06:02 AM:Randy Mcdowell
At least you responded politely, thank 
you. As for the code, this was just a 
basis for an entire library of button 
functions that I am working on, I just 
submitted this code to see how may hits 
it would actually get, and BOY WAS I 
AMAZED!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/11/2000 3:51:12 AM:Johannes Eder
It's not that cool, but try &H8&!
This 
makes the button REALLY flat (without 
any borders etc) so you can have 
something like a REAL FOCUSABLE 
imagebox! Whoa!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/31/2000 1:39:43 AM:Howard Grover
I thought is was a nice touch 
Randy,
What I had to do in the past 
was to use a check box, set to 
Graphical put a line of code in the 
click event chk1.vbUnchecked which 
simulated a cmd button then I just made 
sure the background image was the same 
as the button colour RGB 192 etc.
This 
allows me to kill 2 birds with one 
stone as they say, a graphic and C++ 
style button.
If only that pesky black 
square could be removed from the inside 
of the button it would be 
perfect!
Good stuff and I use your 
code iterating thru the command button 
collection in one hit using TypeOf 
etc.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/31/2000 8:29:15 AM:HG
I recieved mail from -stai@email.com- 
asking how to iterate thru a control 
collection but could not reply as the 
address was rejected by server so if 
you happen to look back here it 
is.
Private Declare Function 
SendMessage Lib "User32" _
Alias "SendMessageA" (ByVal hWnd As 
Long, _
        ByVal wMsg As Long, 
ByVal wParam As Long, _
        lParam 
As Long) As Long
Public Sub 
SetButtonStyle(frm As Form)
' C++ Stle 
Command buttons
' Set Styles to 1 
(Graphical) ps.
' Will lose picture if 
one assigned to button
' so I am 
checking for absence of picture 
first.
    Dim ctrl As Control
   On Error Resume Next
    For Each 
ctrl In frm.Controls
        If 
TypeOf ctrl Is CommandButton Then
       If ctrl.Picture = 0 Then _
           Call SendMessage(ctrl.hWnd, 
&HF4&, &H0&, 0&)
        End If
   Next ctrl
End Sub 
'SetButtonStyle(frm As Form)
'call 
from form load is:
Call 
SetButtonStyle(Me)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/23/2000 10:49:48 AM:FormatC
It has been quite a while since someone 
last posted something on this.... oh 
well... anyway, here's my 
comment:
First of all, I must say, 
this is quite handy... definently the 
most used single line of code of 
everything I do - there's nothing like 
showing nice Cpp-looking programs 
magically coming out of VB to my 
coworkers, whose programs are all, 
well, flat.
But, now, for my 
contribution to this code: You do not 
necessarily need to use a Graphical 
commandbutton. You see, VB apparently 
does all its keep-the-flat-button stuff 
in its own behind-the-scenes GotFocus 
procedure... but, lucky for us, they 
decided to implement their 
pseudo-GotFocus procedure before the 
one available to us. So, if you simply 
put this SendMessage call into the 
GotFocus event of any command button 
with normal style, VB will never get a 
chance to show that button as flat and 
ugly...
Just my two cents...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/1/2000 5:30:54 PM:Roman
This code works GREAT!
Thanx!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/16/2000 1:40:14 PM:Tom
The code works, but was it really THAT 
important????
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/24/2000 10:44:28 PM:Brian
OK, so the VB command buttons look ugly 
and flat when the're pushed, but 
frankly, in 12 years of using Windows 
(5 of them using Win32), I really 
haven't noticed the difference. I know 
that it's the code we've all been 
waiting for, but frankly, it's one line 
of code - and it's the #5 best rated 
code of all time on PSC. Why? Sure, 
it's cool, but does it really make a 
dramatic difference in your programs? 
Is it really that important? No 
offence, I'm greatful that someone 
thought of this, but I'll stick with my 
regular flat command buttons, and if I 
need heavy duty looks, I'll use the 
upcoming B2Skin controls (which use 
skins directly from B2, and can also 
provide translucency and window 
skinning). Or I'll use the Flat Button 
OCX (it's free, and looks cool!). As I 
said previouslly, I'm not insulting 
your code, I just wonder why it's #5 on 
PSC. That's my $.02 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/10/2000 7:36:16 PM:Vasilis Sagonas
Can we remove also the focus points 
...........
. Button  
.
...........
things when its 
focused? And please please is there any 
way to keep the picture? Thanks a lot! 
:-)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/13/2000 2:34:06 PM:Gabriel Pensador
I think that this got so many votes 
because it lets VB programmers pretend 
to be VC++ programmers.
Wouldn't it 
be great if all these people took the 
trouble to learn VC++ and write these 
_professional_ apps they strive for.
I 
would like to recomend an excellent 
book:
Using Visual C++ 6 (special 
edition)
by Kate Gregory
I 
guarantee that anyone who reads this 
book will learn VC++.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/31/2000 5:22:45 PM:MangaMorgan
This code is good 4 doing the little 
[_], [o] nd [X] buttons on the title bar
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/18/2000 3:19:28 PM:livinINvb
under paint this will turn a check, 
frame, and option to look like a button!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/23/2001 9:48:08 AM:Genocide Flux
No offense, but most vb programmers are 
not able to afford VC++ & VB 
(considering vb is easier for the 
script kiddies to find pirated.) i 
spent over $200 on vb6 pro edition and 
that was on sale, plus not many places 
have vc++, or any others then the 
starter kits. Although there is always 
Borland. Although in the long run 
(right now) it's better to learn C++ 
but i find that vb suites most my needs 
and i don't use my vc++ 6 all that 
much.
Then again it is easier to make 
forms with vb, but i feel if you settle 
for a generic form generator then you 
settle for what it gives you. Plus, vb 
is used more for applications (from 
what i have seen) and c++ is more game 
used. But again, that is only from what 
i've seen on the market place. C++ also 
has a lot of applications to it's name 
as well though. But all this is a 
different story.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/6/2001 11:00:06 PM:tec
Im sorry, but this code is bad... i 
have no idea why it got so many 
excellent ratings, and it really takes 
the quality of psc voting down.. i 
mean... if stuff like this can make it 
into the code of the month, what else 
can! ive seen code that is truely 
remarkable, and it didnt even get 3 
excellent ratings... obviously there is 
something wrong here.. 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/10/2002 1:11:36 PM:Tim Sørensen
This really rocks!!
Beautifull 
button.
I´m implementing it in 
all
my apps.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/15/2002 10:04:23 AM:UDMX IOCP®
code sound so great!!! buT.. I can't 
seem to make it work... can't you make 
a project and post it or something??
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/28/2002 5:34:42 AM:Charles R
I have just read all of this and just 
let me say Wow. Haven't tried it yet, 
but I'm sure it's decent, anyway I have 
a problem you may be able to solve with 
one of my projects. I need to run some 
code when the desktop gets clicked, I'm 
not sure if the desktop icons are a 
child of the desktop or seperate so 
this may be two problems in one. Just 
detecting the desktop click and not the 
icons click is ok if it's not possible 
to do both.
Thanking you in 
Advance
Charles
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/29/2003 6:23:11 AM:Casey (Kc) Kneale
I have a sort of dumb question that may 
or may not go along wiht this at 
all...how can i make the mouse move to 
a different part of the screen thenhave 
the same acttion as a mouseclick?eamil 
me if ya wanna 
help...KcKneale777@hotmail.com
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.