.res file not displaying properly

Posted on 2007-07-30
Last Modified: 2010-04-30
Now that I figured how to use .res and add any kind of file, I have a slight problem with my .rtf file. My .rtf file has information in it, including the formatting of colors and text as Arial Narrow.
When I use LoadResData(101, "CUSTOM") to open the .rtf file, it shows alll question marks in my rich text box. The formatting of the .rtf file is gone too. There are no more colors and the font and size changed all of a sudden to blank question marks.

May I know why?
Question by:Zeyadss
    LVL 13

    Accepted Solution


    if you open the file before it is put in a resource with notepad or the like, it looks like this, right?:

    {\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
    {\colortbl ;\red255\green0\blue0;}
    \viewkind4\uc1\pard\lang1033\f0\fs17 Ric\cf1 hTextB\cf0 ox1
    \par }

    then you added it to a resource with the resource editor as custom resource
    saved the resource.

    and then you did:
    Richtextbox1.textRTF = Loadresdata(101, "CUSTOM")

    but that wil fail, becaus Loadresdata returns a byte array.
    you have to convert it to a string, before trying to use it as a string.

    something like this will work:

    Private Sub Command1_Click()
    Dim sBuf As String
        sBuf = strconv( LoadResData(101, "CUSTOM"), vbUnicode )
        Richtextbox1.textRTF = sBuf
    End Sub

    or you could leave sBuf out totally, but this way you can manipulate the data before it is in the textbox
    LVL 2

    Author Comment

    I have done what you said exactly. I can see the text in english, but the fonts, colors and size of the fonts are not working. I also still see the codes like these:
    {\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1025{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial Narrow;}}
    {\colortbl ;\red0\green128\blue128;}
    I use wordpad to create my formatting for my chapters and save them as .txt and when I open the text file it shows all those weird codes. I have the same problem with .rtf files. I also heard that wordpad also uses richtextbox to open those files but im not sure if it does. If you look at those weird codes above, it looks like wordpad creates them to give the formatting colors, sizes and look of my text.

    The code you gave me worked since I can read the text, but those weird codes are still shown and the formatting of my text is not working.
    LVL 2

    Author Comment

    Oh wait a minute nevermind!. It worked. lol. I guess when I restarted visual basic it worked then. Sorry!
    LVL 13

    Expert Comment


    LVL 2

    Author Comment

    Thanks again. I may have few more questions. You might want to participate.
    LVL 13

    Expert Comment


    thanks for the points and the grade!

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    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 …
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    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…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    729 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

    24 Experts available now in Live!

    Get 1:1 Help Now