Announcement

Collapse
No announcement yet.

Radio button background color

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Radio button background color

    How can I use WM_CTLCOLORSTATIC to change background color of radio buttons? Please give me example code. Jeffrey.

  • #2
    Jeffrey, there have been a loty of examples for this posted on the BBS - try searching for 'ctlcolorstatic' and you should find a *lot* of examples.

    Also, take a look at the SMTP.BAS example shipped with PB/DLL 6. There is an update for this file available from http://www.powerbasic.com/files/pub/pbwin/inet/smtp.zip

    If you have not done so, download and install WIN32.HLP - this helpfile gives your the details of how this message (WM_CTLCOLORSTATIC) works. You can find the help file (it's an 8mb download) at http://www.powerbasic.com/files/pub/mstools/win32.zip

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance, I took a look at the SMTP.BAS example, took some code from it, put it in my subway stop program, edited it, and almost got it working but I think that the default font for controls is variable-width font, not fixed-width font. Here is part of the code:

      Code:
      callback function form1proc
        select case cbmsg
          case %wm_ctlcolorstatic
            settextcolor cbwparam,%black
            setbkcolor cbwparam,%white
            function=getstockobject(%null_brush)
        end select
      end function
      Jeffrey.

      ------------------


      [This message has been edited by Jeffrey Morris (edited April 30, 2000).]

      Comment


      • #4
        The %WM_CTLCOLORxxxxx messages have nothing to do with the actual font the controls use... To change the font you have to create a font and send a %WM_SETFONT message to each control that will need the font (usually you would create the font during %WM_INITDIALOG) - this makes it a one-time operation.

        You also need to delete the font handle during %WM_DESTROY or you will cause a memory leak. Obviously this will require a STATIC or a GLOBAL variable to hold the font handle.

        Jeffrey, you really need to get yourself an Windows programming book - all of these User Interface topics are well covered in such books. Take a look at the list of recommended titles in the FAQ forum.


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Lance, I have "Programming Windows Fifth Edition", WIN32 Programming" and "Visual BASIC Programmer's Guide to the WIN32 API" books but using PowerBASIC/DLL to write programs is still harder than using MS Visual BASIC to write programs. I tried several fonts in the C:\WINDOWS\FONTS directory but the only fixed-width font is "Courier New" font. I will have to search the Internet for fixed-width fonts. Jeffrey.

          ------------------

          Comment


          • #6
            There is a very good monospace font at the Microsoft site.
            It is called monotype.com and it is free. I believe that Andy Anderson posted the exact URL over a year ago.

            using PowerBASIC/DLL to write programs is still harder than using MS Visual BASIC to write programs
            You are correct, and I agree if you are talking about GUI only. You really need to take six months or more of many hours a day to master the Windows API SDK style GUI programming.
            I do not have that kind of time, so I used a third party product(EZGUI) and changing colors and fonts is now a breeze.
            It is a basic question: Build -or- Buy ?
            In this instance I choose Buy

            Happy coding.

            Joe Murphy

            ------------------

            Comment


            • #7
              Jeffrey;

              There are other Fixed Width fonts with Win95.

              Terminal (A DOS type font with graphic characters)
              FixedSys
              Courier

              besides Courier New


              ------------------
              Chris Boss
              Computer Workshop
              Developer of "EZGUI"
              http://cwsof.com
              http://twitter.com/EZGUIProGuy

              Comment


              • #8
                Why not try Lucida Consol if you need a true-type font
                Quite nice really...

                ------------------
                Fred
                mailto:[email protected][email protected]</A>
                http://www.oxenby.se

                Fred
                mailto:[email protected][email protected]</A>
                http://www.oxenby.se

                Comment


                • #9
                  Joe, Thanks for telling me about monotype.com file on MS web site. Writing programs for Windows in any language is harder than writing programs for DOS. Jeffrey.


                  ------------------

                  Comment


                  • #10
                    Chris, I tried some of the fonts that came with Windows 98 SE and most of them don't look good. Jeffrey.


                    ------------------

                    Comment


                    • #11
                      Fred, I tried Lucida Console font but it doesn't look good when upscaled. Jeffrey.


                      ------------------

                      Comment


                      • #12
                        Did you try using the standard fonts, ala GetStockObject() ?

                        If you ask for a particular font that is not available on the current PC, then Windows will substitute another font that closely matches the specifications, but it could be a completely different font.

                        Getting the font you actually *want* is almost an exact science... When you use CreateFont() or CreateFontIndirect() you are *asking* Windows to create a font as close to your spec's as possible, but the font you get is left to the mercy of Windows. If you do not specify the the font parameters exactly right (esp. the charset and family flags), you may end up with a completely different and unexpected font.

                        For example, if you specify %ANSI_CHARSET with certain "exotic" fonts, you'll get something else - usually using %DEFAULT_CHARSET is a better approach.

                        Further, you should discriminate between the types of font - device/raster fonts are often synthesized by the GDI so the results are often unpredictable or visually aweful. Where possible, stick to truetype fonts.

                        In summary, experimenting with font selection is something you should spend a bit of time on - you may think that one particular font looks terrible but you may not be actually getting the font you expected - as I noted, this is usually because you specified incorrect or sloppy font parameters to Windows.

                        In other words, your results may be misleading if you do not verify the font you get is actually what you requested. To query the current font that a control is using, get a DC to the control, and use the GetFaceName() or GetTextMetrics() API's to verify the results of your %WM_SETFONT code.

                        Finally, if you wish to distribute your apps to other people, verify that your font selection works identically on the different versions of WIndows. CreateFont()/CreateFontIndirect() in Windows 95 often returns a completely different font to Window 2000 when using exactly the same parameters. I found this out the hard way when I was initially developing DOSPRINT and DLLPRINT.


                        ------------------
                        Lance
                        PowerBASIC Support
                        mailto:[email protected][email protected]</A>
                        Lance
                        mailto:[email protected]

                        Comment


                        • #13
                          Lance, If I use GetStockObject, I may not set the size of the font. I found out that I have to use font names that are spelled as shown in the font list box in MS Word or I will get wrong font. Jeffrey.


                          ------------------

                          Comment

                          Working...
                          X