Welcome to Technolog Sign in | Join | Help

July 2006 - Posts

You don't need to if you thought so :) use CString only to get the best of string manipulation within the C++ environment in a mixed COM environment. This CComBSTR replacement offers the most you need without having to cast strings forward and backward and loose performance. Expect your multithreaded and SMP performance to improve while still using native BSTR variable storage.
Posted Tuesday, July 25, 2006 1:20 PM from eprogrammer | 0 Comments
Filed under: ,

Attachment(s): CComBSTR.zip

If you ever might want cute buttons, independently of your clients browser and theme, you might create buttons by using some dynamic GDI based code.


I found this solution, which costed just 2 hours programming not bad at all, and you might profit from it as well.


This code, automatically wraps text, all using .NET power. It even can be improved, to support hover as well. B.t.w. on Windows Vista XAML supports this but we’re still on the internet man!

So why not make our own buttons.


Paste code below, onto an empty ASPX page (for instance button.aspx), and call use it through the following arguments (other tag arguments omitted for simplicity).


<asp:ImageButton id=”myButton” ImageUrl=Button.aspx?t=Hello%20World&w=150&h=35” runat=”server”/>


Syntax below is based on C# 2.0 


The output might look like this(appConfig must contain the buttoncolors)



public partial class button : System.Web.UI.Page


    private static Color parsRgb(string rgbColor)


        int red, green, blue;


        red = int.Parse(rgbColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);

        green = int.Parse(rgbColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);

        blue = int.Parse(rgbColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);


        return Color.FromArgb(red, green, blue);


    protected void Page_Load(object sender, EventArgs e)


        System.Collections.Specialized.NameValueCollection req= Request.QueryString;


        //get height

        string h=req["h"];

        //get width

        string w = req["w"];

        // get text

        string t = req["t"];

        if (t == null || t.Length == 0)

            throw new HttpException("QueryString  t not supplied");

        int hashCode = t.GetHashCode();

        string checkEtag = Request.Headers["ETag"];

        if (checkEtag != null && checkEtag.Length != 0)


            if (checkEtag == hashCode.ToString())


                Response.StatusCode = (int)System.Net.HttpStatusCode.NotModified;

                Response.StatusDescription = "Not modified";

                Response.SuppressContent = true;





        req= System.Web.Configuration.WebConfigurationManager.AppSettings;


        string colrRadiantStart = req["btnBgRadiantStart"];

        string fontSize = req["btnFontSize"];

        string FontName = req["btnFontName"];

        string colrRadiantEnd = req["btnBgRadiantEnd"];

        string FontColor = req["btnFontColor"];


        System.Drawing.Color ocolorEnd, colorStart, colorFont ;


        if (colrRadiantStart != null && colrRadiantStart.Length == 6)

            colorStart = parsRgb(colrRadiantStart);


            throw new HttpException("You must provide a valid btnBgColor hex rgb-code in appConfig");


        if (colrRadiantEnd == null || colrRadiantEnd.Length != 6)

            throw new HttpException("You must provide a valid btnBgColor hex rgb-code in appConfig");


            ocolorEnd = parsRgb(colrRadiantEnd);

        if (FontColor == null || FontColor.Length != 6)

            colorFont = Color.Black; //default


            colorFont = parsRgb(FontColor);


        int iH = int.Parse(h);

        int iW = int.Parse(w);

        Bitmap oBmp1 = new Bitmap(iW, iH);

        Graphics oGrp1 = Graphics.FromImage(oBmp1);


        // seems not to have effect

        oGrp1.CompositingQuality = CompositingQuality.HighQuality;

        oGrp1.InterpolationMode = InterpolationMode.HighQualityBilinear;


        LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0, iW, iH), colorStart, ocolorEnd, LinearGradientMode.Vertical);

        oGrp1.FillRectangle(lgb, 0, 0, iW, iH);


        System.Drawing.FontFamily fntFam = new FontFamily(FontName);


        Font fnt = new Font(fntFam, float.Parse(fontSize));

        StringFormat stringFormat = StringFormat.GenericDefault;

         //we must set this value, other wise text will default to left.

        stringFormat.Alignment = StringAlignment.Center;

        SizeF szf = oGrp1.MeasureString(t, fnt, new SizeF(iW, iH), stringFormat);


        PointF FPoint = new PointF((iW - szf.Width) / 2, (iH - szf.Height) / 2);


        oGrp1.DrawString(t, fnt, new SolidBrush(colorFont), new RectangleF(FPoint.X, FPoint.Y, szf.Width, szf.Height), stringFormat);




        Response.ContentType = "image/jpeg";




        oBmp1.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);               





There are several tricks but I've not seen this one so I would like to mention this trick as well.

The idea is that IIS can be managed through ADSI interfaces right? You would use (in vbscript)

Sest myIIS = GetObject("IIS:") and now you have the namespace. But if IIS is not installed, it would return 'invalid syntax'. Not really a good error.
A cleaner method would be
Set myIIS = CreateObject("IIS")

This way, you use the progid that the IIS namespace, normally is fetched by a url moniker and GetObject().

so complete code:
Dim myIIS, isIISInstalled
On Error Resume Next
Set myIIS = CreateObject("IIS")
'ActiveX component cannot create object: 'IIS'
isIISInstalled = Err.Number <> &H800A01AD
On Error GoTo 0

You can apply the concept above to -any- language, including javascript, VB6, C# and VB.NET.