CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2002
    Location
    Germany
    Posts
    8

    Unicode in Form Titles

    Hello!

    Does someone know how i can get Unicode Character Strings into a Titlebar from a Form?
    The Unicode-String is successfully loaded from a SQL-Database, but when i try to set the Caption of that Form like

    me.caption = somestring



    i receive only some "???".
    I also tried to use a API-Function called "SetWindowTextW" but i only get the same result.
    Would be nice if someone helps out or has an idea to try.


    public Declare Function SetWindowTextW Lib "user32" (byval hwnd as Long, byval lpString as string) as Long

    public Sub SetWindowText(hwnd as Long, VarStr as string)
    Dim varbyte() as Byte
    Dim cch as Long

    If VarStr = "" then Exit Sub
    cch = LenB(VarStr) + 2
    ReDim varbyte(0 to cch)

    CopyMemory varbyte(0), byval StrPtr(VarStr), cch

    SetWindowTextW hwnd, VarPtr(varbyte(0))
    Erase varbyte
    End Sub






  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Unicode in Form Titles

    Try the StrConv function

    Please rate it if it answers the question
    or is useful.
    '
    John G

  3. #3
    Join Date
    Feb 2002
    Location
    Germany
    Posts
    8

    Re: Unicode in Form Titles

    Maybe I'm to dumb or somewhat but it wouldn't work for me. The Unicodes are all correct converted (even w/o strconv), but i still get only "???"
    My intention is that the API-Function "SetWindowTextW" or VB messes with my Strings and Converts them to Question Marks. BTW when I use "normal" Characters that have been converted to Unicode (i.e. "ABC" = 65 0 66 0 67 0) the Result is correct.

    Nonetheless thanks, "strconv" its another function to my abilities.
    I'm still open for any Ideas.


  4. #4
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Unicode in Form Titles

    Declaration doesn't look right - try:

    public Declare Function SetWindowTextW Lib "user32" (byval hwnd as Long, lpString as string) as Long




    The reason is that when you use ByVal in an API declaration to a string parameter, VB converst it to a CSTR (null terminated ASCII) format.

    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com/EventVB/Overview.htm - Flatten the API learning curve
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  5. #5
    Join Date
    Feb 2002
    Location
    Germany
    Posts
    8

    Re: Unicode in Form Titles

    I will try another way.
    Does someone know a example where a VB-Project shows Non-Ascii-Characters (i.e. Katakana, Kanji, Kyrillic, ...) in its Window Title and could provide a Download-Link.
    Thanks in advance.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured