Form Captions with Unicode characters in VB6

Posted on 2007-10-08
Last Modified: 2013-12-26
I want to display Unicode characters in a VB6 Form caption.
All attempts with SetWindowsTextW are failing and the string gets converted to ANSI.

Any code snippets available anywhere?

Question by:ToFri
    LVL 28

    Expert Comment


    Author Comment

    Thank you,

    Nice, but not really a solution for the problem.
    I need to show arbitrary Unicode in the caption under every Windows locale setting.

    We have customers all over the world using different Windows XP versions, like Russion, Greek, Hebrew, Arabic and so on. And I just want to call SetWindowTextW.

    I know (think I know) this does not work because the VB6 Form is not a Unicode-Window and so a conversion from Unicode to ANSI takes place behind the scenes.
    I read somewhere, that one needs to install a hook (CBT?) and send the SetWindowTextW from inside the Hook in order to achieve the desired result&

    Some code snippets for that would be very apprechiated.

    Thank You anyway

    LVL 22

    Expert Comment

    Vb Command button has a hWnd so you can use HCBT_ACTIVATE and SetWindowTextW however Vb Label does not (class is "ThunderFormDC") so you cannot hook it.

    Here is a Unilabel control that works but requires that the Unicode caption be set at run-time:

    To do this correctly though you need at least the following:
       1. Render Unicode using API DrawTextW
       2. Implement AutoSize using GetTextExtentPoint32W so that it gets correct metrics for Unicode strings.
       3. Vb IDE Properties window does not support Unicode strings. You can cheat by pasting UTF-8 here and converting it inside your control to UTF-16, otherwise to do it right you need a Property Page with a Unicode aware TextBox to input the Unicode caption.
       4. Modify PropertyBag persiststance of caption to use a byte array so that it does not automatically change the caption to ANSI when writing.

    Author Comment

    Yes Thank you !
    I understand this works for controls inside the Form.
    My question is regarding the Form Caption!
    Not regarding any control inside. We did solve these problems already.
    The "only" problem remaining is the Title of the application Window itself.
    I mean the text between the Icon of the application and the Minimize, Restore, Close boxes.

    Thank you anyway

    LVL 22

    Accepted Solution

    Sorry I misread your question.
    To manipulate the Form Caption aka "TitleBar" for Unicode support here are a couple links to get you started:
       You need to change from DrawTextA to DrawTextW as well as account for XP Themes.
       This one apperas to be better than "VB6_Graduated_Title_Bar_Sample" and is buried in ThunderVb and can be found at folder "C:\ThunderVB_v_1_0_0_31_7_2005\ThunVBCC\V1\ThunderVB Controls\uniCaption"
       You will probably want to change the subclassing to either Paul Caton (latest version ) or VbAccelerator( ).

    Author Comment

    Thank you very much.
    This will help.
    I did not think of this obvious way.
    Good to have some sourcecode to start with.

    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now