Shaded Buttons -------------- v. 1.05 (1997) by Hubert Chan WHAT IT IS ---------- It is a new window class that creates buttons with a rounded look by using a gradient pattern, so that the top of the button is lighter and the bottom is darker. Buttons can also have rounded sides, they can have icons, and they can be vertical (so that the gradient pattern goes from left to right instead of top to bottom). IMHO, it looks a lot nicer than normal push buttons. Included is a sample program, modified from Petzold's "OS/2 Presentation Manager Programming". It's a simple window with ten buttons: two in the middle with arrows pointing in or out, six coloured buttons on top of those buttons, with either a '<' or '>', one labelled "About", and one at the bottom which acts as a status bar. The buttons in the middle, when pushed, either shrink or enlarge the window. The coloured buttons change the colour of the "About" button. The status bar reports the RGB values for the "About" button. The "About" button does what you think it does. I have included the source file. Feel free to modify it as you please for your own programs. If you can fix any bugs, or if you change/add anything that you think may be helpful, send it to me, and I may include it in future versions. Especially, help would be appreciated in getting the presentation parameters to work. HOW TO USE IT ------------- Include ShadeBtn.H in your source file. To register the class with the Presentation Manager, call shBtnInit. The class is called WC_shBUTTON. To make a button, call WinCreateWindow as you normally would to create a button (except that you use WC_shBUTTON instead of WC_BUTTON as the window class). Valid button styles are: shBS_PUSHBUTTON -creates a pushbutton (default) X shBS_CHECKBOX -creates a check box X shBS_RADIOBUTTON -creates a radio button X shBS_3STATE -creates a 3 state button shBS_ICON -uses an icon instead of text uses button "text" as the id number of the icon. The text should be in the form "#[iconid]<,[disablediconid]>" where [iconid] is the id number of the icon, [disablediconid] is the id number of the icon to be displayed when the button is disabled. The portion in between the triangular brackets ( "<...>" ) is optional. Normal text can be placed at the end, but will be ignored (for now - in future versions, it will be displayed along with the icon). X shBS_MINIICON -same as shBS_ICON, but uses the smaller icon size shBS_HELP -sends a WM_HELP message when clicked shBS_SYSCOMMAND -sends a WM_SYSCOMMAND message when clicked X shBS_DEFAULT -makes the button the default shBS_NOLEFTLINE -removes the border on the left side of the button shBS_LEFTROUND -makes the left side rounded shBS_NORIGHTLINE -removes the border on the right side of the button shBS_RIGHTROUND -makes the right side rounded shBS_VERTICAL -makes the button vertical (left to right gradient pattern) shBS_NOTOPLINE -removes the border on the top side of the button (when VERTICAL is set) shBS_TOPROUND -makes the top side rounded (when VERTICAL is set) shBS_NOBOTTOMLINE-removes the border on the bottom side of the button (when VERTICAL is set) shBS_BOTTOMROUND -makes the bottom side rounded (when VERTICAL is set) shBS_NOPUSH -makes the button non-pushable (eg. to make status bars) shBS_NOBORDER -removes the border on the edges of the button. (left and right borders if horizontal, top and bottom if vertical) NOTE: styles marked with an X are not yet implemented I've tried to make it as compatible with the normal button class. Unless you use BS_NOPOINTERFOCUS, BS_NOBORDER, BS_NOCURSORSELECT, or BS_AUTOSIZE, you should be able to just replace WC_BUTTON with WC_shBUTTON in your source files. You can also make a button in a dialog box in a resource file. See ButtonTest.rc for an example. When the button is pushed, it will send a WM_COMMAND message to its owner, just like a normal push button does. It can also be activated by hitting the space bar when it has the focus. To change the colour of the button, send it a shBM_SETCOLOR with mp1 set to the RGB value of the colour, and mp2 set to shBSC_BUTTONFACE to change the button face colour, or shBSC_BACKGROUND to change the background colour. Another way to change the colour of the button is to use presentation parameters. (You can also change the font this way, but you will need to force a window repaint. I'll try to fix this.) The presentation parameters that are handled are: shBPP_BUTTONCOLOR - change the button colour (using RGB values) shBPP_BUTTONCOLORINDEX - change the button colour (using colour indices) shBPP_BUTTONBGCOLOR - change the background colour (using RGB values) shBPP_BUTTONBGCOLORINDEX - change the background colour (using colour indices) To try it out, drag a colour from the Mixed Color Palette onto a button in the demo program. To determine the version of Shaded Buttons, use shBtnQueryVersion(). It returns the version number * 100 (eg. v 1.20 -> 1.20 * 100 = 120). When you link your program, link it with ShadeBtn.lib. (hopefully it should work with compilers other than emx. If not, let me know, and I'll see what I can do about it.) Make sure ShadeBtn.dll is in a directory in your LIBPATH. CHANGES ------- In v. 1.05: - I went on another renaming spree. Now everything is prefixed by shB instead of SB to avoid confusion with the scroll bar class. Creating a header file with the appropriate #define's shouldn't be too hard if you're too lazy to change your code. I promise not to rename anything anymore. - I made the button styles to have the same values as corresponding styles in normal buttons (so any programs will need to be recompiled in order to use the new DLL file). - added ability to display a different bitmap when button is disabled. - cleaned up the code a bit. - presentation parameters seem to be working now -- actually, I think they were working all along, but I just forgot to repaint the window. - fixed the header file to be more C friendly (used C comments instead of C++) - vertical buttons now work. In v. 1.01: - minor bugfix in the example program. The background was black instead of light grey when it was run in Warp 4. Apparently, Warp 4 defaults to using the RGB colours, while Warp 3 defaults to using indexed colours. - disabled buttons are displayed with a more chiseled look - minor change in the example program. The "About" button is disable/enabled when the shrink button is disabled/enabled, to demonstrate the new look for disabled buttons. In v. 1.00: - it now works as a DLL! - previous versions wouldn't have worked if you tried to link to a normal C file. This is now fixed. - renamed pretty much everything. Now you call SBtnInit() to register the window class. Button styles are now prefixed with SBS, button messages are prefixed with SBM, and presentation parameters are prefixed with SBPP. The class name is changed, with WC_SHADEBTN defined as the new name (don't use SHADEDBTNCLASS any more). All the previous Button.* files are renamed to ShadeBtn.*. (It shouldn't be hard to create a header file to make appropriate #define's so that old code can be reused) - added a function to return the version number (SBtnQueryVersion). - added ability to change background colour. - fixed the colouring outside of the lines when drawing rounded buttons, and got rid of some floating point calculations. In v. 0.20: - added a window message (GBM_SETCOLOR) to change the colour of the button - added a few buttons to the demo program, and made the status bar do something more interresting - buttons can now have rounded sides - I've decided to make it completely free - fixed some spelling mistakes in this file ;-) In v. 0.10: - initial release KNOWN BUGS ---------- - sometimes there is a noticeable flicker when you click on a button - if the button is too tall, or the colour is too dark, the button will be a solid colour (no gradient). - changing the font using presentation parameters requires the user to force a repaint (eg, minimizing the window, then restoring) in order to display the now font. - bitmaps in the buttons aren't exactly centred? COMING SOON (?) --------------- Things I will probably add or change: - allow text and bitmaps to be in the same button - display button differently when it has the focus (I haven't decided exactly how it should look when it has the focus -- suggestions?) - add more classes (eg. radio buttons, check boxes, spin buttons, etc.) - allow different bitmaps when button is clicked - make a better example program (ie. that shows off more features) THE AUTHOR ---------- You can e-mail me at , or snail mail me at Hubert Chan 3 Falstaff Ave. St. Albert, AB Canada, T8N 1V3 Send me comments, criticism, or $$$ ;-) I have a home page set up at http://www.ualberta.ca/~hyc/Programming/. The newest version of "Shaded Buttons" will always be there. COST ---- Free. If you really do want to send me something, though, I'm not going to complain. Of course, I would very much appreciate if you acknowledged your use of Shaded Buttons. :-) WHERE TO GET IT --------------- From my home page: http://www.ualberta.ca/~hyc/Programming/ From Hobbes: http://hobbes.nmsu.edu or ftp://hobbes.nmsu.edu These are the only places that I will put the files in. Feel free to upload it to other sites.