Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Including a readme.txt IN a dialog

1 view
Skip to first unread message

Scoots

unread,
Nov 10, 2009, 10:02:42 AM11/10/09
to
Hello all,

I'm hoping this is easy, but google search is entirely failing me, as
the text "readme" causes every application ever written to appear in
the results.

I have an mfc dialog app utility that I want to ship with my main
application. The main application has a readme, and I really don't
want to add additional files to fileset, as it is confusing enough.

The utility has some fairly extensive command line support, and I'd
like to include documentation with it, but I don't want to include it
as additional files. To the user, I want my utility, that's it. When
they run the application, I want them to be able to view the readme,
even if it's just in a textbox. But despite wracking my brain, the
only thing I can think of is to load the readme at runtime from a
separate file, which is exactly what I want to avoid.

What's the best way of doing this? I'd really like to avoid having
additional files if I can.

Thanks,
~Scoots

Kerem Gümrükcü

unread,
Nov 10, 2009, 10:22:59 AM11/10/09
to
Hi Scoots,

> But despite wracking my brain, the
> only thing I can think of is to load the readme at runtime from a
> separate file, which is exactly what I want to avoid.


if you want exactly to avoid this, then you can add a resource file
to your application and compile the readme text into the resource
file, then compile your application with the resource file and access
the resource files data within your binary with the windows resource
functions.

http://msdn.microsoft.com/en-us/library/aa380599%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms632583%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms674841%28VS.85%29.aspx

Regards

Kerem

--
-----------------------
Beste Gr�sse / Best regards / Votre bien devoue
Kerem G�mr�kc�
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------

David Lowndes

unread,
Nov 10, 2009, 10:26:38 AM11/10/09
to
>The utility has some fairly extensive command line support, and I'd
>like to include documentation with it, but I don't want to include it
>as additional files. To the user, I want my utility, that's it. When
>they run the application, I want them to be able to view the readme,
>even if it's just in a textbox. But despite wracking my brain, the
>only thing I can think of is to load the readme at runtime from a
>separate file, which is exactly what I want to avoid.
>
>What's the best way of doing this? I'd really like to avoid having
>additional files if I can.

In that case I'd look into having the "file" as a resource. The
following may help point you in the right direction:
http://www.codeproject.com/KB/cpp/usingtextfile_resources.aspx

Dave

Tom Serface

unread,
Nov 10, 2009, 11:43:52 AM11/10/09
to
You can certainly add a file as a resource, but you will find it more
difficult to maintain as the project gets closer to release. I think having
the file installed as text on the disk is actually easier and you can easily
load it into a CStringArray (or directly into a CEdit or CListBox) using
CStdioFile to read the file. I know you say you are trying to avoid this,
but if you want to modify it close to the end of the cycle you have to redo
it in the resources and it's kind of a pain to update it.

Depending on how long the text is you could just have it as a string
resource as well. I think you can have several K of text in a single
string.

Tom

"Scoots" <linki...@msn.com> wrote in message
news:12f4d859-221e-4dfe...@a31g2000yqn.googlegroups.com...

Malachy Moses

unread,
Nov 10, 2009, 12:38:47 PM11/10/09
to
If you want formatted text (bold, headings etc) or screenshots, then
use a rich edit control and this article, which exactly describes your
own goals of an "embedded" help functionality:

"A Rich Edit Control That Displays Bitmaps and Other OLE Objects" at
http://www.codeproject.com/KB/edit/COleRichEditCtrl.aspx

As suggested by others above, the actual text is contained in a
resource file that's compiled into the program, not a separate file
that must be distributed to the end user.

Joseph M. Newcomer

unread,
Nov 10, 2009, 1:42:52 PM11/10/09
to
Do the following.

In your resource file, go to the option to manually edit the resource file and add the
line:

1 README "readme.txt"

DO NOT just hand-edit this into your resource file; it won't work. Alternatively, place
it in your .rc2 file, which you CAN hand-edit.

Then do, in your OnInitDialog handler:

HRSRC readrsrc = ::FindResource(AfxGetInstanceHandle(), MAKEINTRESOURCE(1), _T("README"));
if(readrsrc == NULL)
... deal with error

HGLOBAL readglbl = ::LoadResource(AfxGetInstanceHandle(), readrsrc);
if(readglbl == NULL)
... deal with error

char * readme = ::LockResource(readglbl);
LPSTR readme = ::LockResource(readglbl);

your choice of type, but *NOT* LPTSTR!

Note that while most resources are stored as Unicode, user-defined resources defined by a
file are stored as bitwise copies of the contents of the file, so if it was an ANSI file
(the usual case) the resource is ANSI (8-bit characters).

(or

LPWSTR readme = ::LockResource(readglbl);

if the resource is a Unicode text file)

if(readme == NULL)
... deal with error

If your app is Unicode, you can then do

CString ReadMeStr(readme);

which will accept either a char */LPSTR or LPWSTR and make sure the string is a Unicode
string.

c_ReadMeText.SetWindowText(ReadMeStr);

The text of the file appears in the control c_ReadMeText.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer

unread,
Nov 10, 2009, 1:45:15 PM11/10/09
to
In my Locale Explorer, I created the individual help text files with WordPad; they include
text (with formatting) and occasional images. Then I just used the technique I described
above to create resources that represent these files. No special work was required. I
just take the stream and stream it into the edit control. It makes editing the rich text
very easy, because I just use WordPad (No, don't use Word and store the rtf; it is gross
and ugly and massive beyond all reason)
joe

James Juno

unread,
Nov 11, 2009, 1:24:54 PM11/11/09
to
Very handy. Thanks for this tip.

-JJ

"Joseph M. Newcomer" <newc...@flounder.com> wrote in message
news:d2djf5pp5scscop0f...@4ax.com...

Scoots

unread,
Nov 18, 2009, 5:59:09 PM11/18/09
to
Technique worked wonderfully, thanks!
~Scoots
0 new messages