Thread: String as Resource in txt file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User KeithS's Avatar
    Join Date
    Jul 2009
    Location
    Colombia
    Posts
    21

    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..

    Code:
    // Snippet applicable declarations...
    LPCTSTR ClsName = "Basic_Window";
    TCHAR szBuffer[250];
    LPSTR outBuffer;
     
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
     switch(Msg)
     {
     // Not applicable code removed....
       case WM_CREATE:
      { 
       UINT_PTR ret;
       BITMAP bm;
    //  Etcetera....
     
       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);
      }
      break;
     case WM_PAINT:
      {
       // removed for post... 
      }
      break;
     
     }
     return 0;
    }
     
    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);
     HBITMAP hbmOldBuffer;
     
    // 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);
     SelectObject(hDcMem, g_hbmBebop);
     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);
     
     SelectObject(hDcMem, hbmOld);
     DeleteDC(hDcMem);
     SelectObject(hDcBuffer, hbmOldBuffer);
     DeleteDC(hDcBuffer);
     DeleteObject(hbmBuffer);
     }
    What I have already covered (please note the comments in the code, too).

    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,

    KeithS
    Last edited by KeithS; 08-19-2009 at 12:29 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM