Like Tree1Likes
  • 1 Post By oogabooga

Displays text using DrawText after loading it from a file

This is a discussion on Displays text using DrawText after loading it from a file within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I am trying to display the text in win32 console window using DrawText after loading the string lines from ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    27

    Displays text using DrawText after loading it from a file

    Hello, I am trying to display the text in win32 console window using DrawText after loading the string lines from a text file.

    Here's the code for the file loading:
    Code:
       std::vector<basic_string<TCHAR>> vectorLine;
       wfstream file ;
       basic_string<TCHAR> line;
       
       vectorLine.clear();
       wcscpy(fileName,_fileName);
       file.open("data/data_test.txt");
       if (!file) {
    	   printf("Error: TokenManager: invalid   file");
       }
       
       while( getline(file, line)) {
    	   vectorLine.push_back(line);
       }
    
     //Next, I draw the text from the lines stored in a vector.
     
      basic_string<TCHAR> tempString;
      for (int i=0; i < tokenManager.vectorLine.size(); i++) {
    	  tempString=tokenManager.vectorLine[i].c_str()
    	  DrawText(hdc, tempString, -1,&rectTextLine,DT_SINGLELINE | DT_LEFT | DT_VCENTER);
      }
    The error is DrawText does not accept basic_string<TCHAR> and needs a long pointer to a string. This is where I am confused. I tried changing basic_string<TCHAR> to std::string and std::wstring but to no avail.
    Hope someone can help recommend me the change. It's either how I delcare the vectorLine or add some macros for the conversion.

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Since c_str returns a pointer to the raw characters of the string object, you need to define tempString as
    Code:
    const TCHAR* tempString;
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    27
    Quote Originally Posted by oogabooga View Post
    Code:
    const TCHAR* tempString;
    What is the difference between const TCHAR* tempString and LPWSTR? According to msn.microsoft website LPWSTR is
    Code:
    typedef wchar_t* LPWSTR, *PWSTR
    so LPWSTR is just a convention for easier reading??



    Also the _t in wchat_t, what does that signify?

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    TCHAR is defined as either char if UNICODE is not defined and wchar_t if UNICODE is defined.

    _t presumably stands for "type".

    To learn windows, you must learn your way around MSDN:
    MSDN Library

    Try looking up TCHAR in the search box.
    Salem likes this.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading Text File Resources
    By Brokenhope in forum Windows Programming
    Replies: 4
    Last Post: 10-11-2010, 04:32 AM
  2. Help loading from text file!
    By Cherry65 in forum C++ Programming
    Replies: 8
    Last Post: 12-15-2008, 10:13 AM
  3. Is there any free text editor that displays number of rows?
    By Roy01 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-21-2006, 09:35 PM
  4. Problems loading a text file into a struct of vectors
    By alt234 in forum C++ Programming
    Replies: 7
    Last Post: 12-04-2005, 08:58 PM
  5. Loading text from file into struct
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 03-19-2002, 04:33 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21