String as Resource in txt file
Hi to everyone. First post.
WIN API fan, and have been "lurking" for a while, getting most questions answered on MSDN or indirectly here. Not a programmer by profession, but need it every once in a while for my work, & besides it is a cool hobby. Been programming in various forms of BASIC on various platforms since 1985, some "C" practice over 10 years ago, recent convertee to C++. Okay, enough blurb...
I have finally been trumped with this one. Could someone offer some help, please? How do you access the string in a resource *.txt file? Here's the abreviated code snippet first, description of my trouble shoot after..
What I have already covered (please note the comments in the code, too).
// Snippet applicable declarations...
LPCTSTR ClsName = "Basic_Window";
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
// Not applicable code removed....
LoadString(GetModuleHandle(NULL), IDS_STRING, szBuffer, 0); /*sizeof(TCHAR));*/
FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER, szBuffer, IDS_STRING, NULL, outBuffer, NULL, NULL);
// removed for post...
void DrawBebop(HDC hdc, RECT* prc)
// This version of the drawing integrates double-buffering
HDC hDcBuffer = CreateCompatibleDC(hdc);
HBITMAP hbmBuffer = CreateCompatibleBitmap(hdc, prc->right, prc->bottom);
// Not applicable code removed...
//TextOut(hDcBuffer, 100, 100, "TESTING", 7); // This works....
BitBlt(hDcBuffer, (BmpPos.bx - Ofst), (BmpPos.by - Ofst), BmpPos.width, BmpPos.height, hDcMem, 0, 0, SRCAND);
BitBlt(hDcBuffer, (BmpPos.bx - Ofst), (BmpPos.by - Ofst), BmpPos.width, BmpPos.height, hDcMem, 0, 0, SRCPAINT);
DrawText(hDcBuffer, outBuffer, -1, prc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);// This shows nothing...
//DrawText(hDcBuffer, "Hi There!", -1, prc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); // This works...
//DrawText(hDcBuffer, ClsName, -1, prc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); // And this works...
// Hmmm. Normal, interpreted as Null Terminated ("**"), strings prints no problem, as does
// a standard char array buffer. The question is, then, how do you get a STRING
// resource to format as char? FormatMessage does not seem to do the trick.
// Or I am not using it correctly. There is only
// some stuff in Japanese about it on MSDN, so
// I have no reference....
// Just a note, the STRING resource, that comes from a *.txt file, is NOT stored with the
// *.exe as letters, but apparently as its character (scan?) codes. Ie; non hexadecimal numbers.
// I am wondering if the conversion to characters is required in a separate function, even though
// a scant, indirect reference seems to promise that this
// is not needed when using FormatMessage() function.
// So, my doubt: Is the way I am embedding a STRING resource the right way (ie; as a txt file)?
// Is there another way? Is this possibly the problem?
BitBlt(hdc, 0, 0, prc->right, prc->bottom, hDcBuffer, 0, 0, SRCCOPY);
The txt file that contains the string embeds correctly. I have tried the string with and without "" quotation marks around it. The compiler setup is correct, or it would not be printing the NULL terminated char array. Various string typecastings of the LoadString() or the char Buffers does not produce any results either. The string WILL load and display properly from the txt file, if I donīt embed it, and access it through an IOstream. Resource.h and TestQuiz.rc files are working perfectly, too, as the bitmaps and icons load okay (I have tried STRING and RT_STRING already, as resource types in the *.rc file, same results). I think MAKEINTRESOURCE is not applicable to this case, as the string is already loaded with its resource ID (in LoadString). Tried it anyway, did not work.
So, I believe this narrows it down to a character access problem, as described, or a LoadString problem. Something in the formatting of the embedded resource?
My thanks in advance,