Textbox and printing

This is a discussion on Textbox and printing within the C++ Programming forums, part of the General Programming Boards category; OK I have three questions relating to textboxes 1) How do I read in from several .txt files and copy ...

  1. #1
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89

    Textbox and printing

    OK I have three questions relating to textboxes

    1) How do I read in from several .txt files and copy it all into a textbox in my program for previewing and editing

    2) How do i make that text box print to a printer

    3) is it possible to make my text box have a scroll bar?..if so How would I go about doing so also

    thanx in advance,
    Boomba,

  2. #2
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Well, this is obviously OS-specific, so 1) this should go in one of the OS-specific forums, 2) you're not going to get any help until you tell us the details like what OS (Windows? XWin?), what libraries you're using for your window objects (e.g. WinAPI, MFC, OWL, etc.)

  3. #3
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    I apologize I forgot to give the details last night

    I'm using this win32 app on windows xp and windows NT so far..and I'm using windows.h ..hope that helps.

    thanx in advance,
    Boomba

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    1. Read the files, build a memory buffer which contains what you want to show and send them to a multiline edit box with SetWindowsText(). Remember, an edit box requires both "\n\r" to create a carriage return linfeed.

    2. To print from Windows, you will need to set up a PRINTDLG structure then use something like PrintDlg() to get, amongst other things, the printer's device context.

    Once you have that, you can write/copy to the print DC in the same way as a screen DC.

    Once you have done that, you'll need a DOCINFO structure set up, and call StartDoc() then StartPage()/EndPage() until all the pages are spooled, then a final EndDoc() to submitted the print job.

    3. Create the editbox with the ES_AUTOVSCROLL attribute.

    Look up these routines in the help or at MSDN.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    Read the files, build a memory buffer
    my txt files all have the same name "questions.txt" and there is one in each sub folder a sub folder represents a section...and the folder that those subfolders are in is the whole project.

    how would I step through these subfolders and read each "questions.txt" file in them so that i can send them tot he textbox?

    thanx in advance,
    Boomba

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Ope the highest common folder then search for other "folders", open each one in turn. To log directories/folders, look here , use a "questions.txt" search mask in each folder/directory found.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    ok great...this will work but now I'm stuck on when I have to open the txt file...I get an error message becasue the path I specify in fopen is appearently not a const char*

    heres my code, I've tried:
    Code:
    //Check to see if it is a directory
    if(win32FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    strFilePath += "Questions.txt";
    fopen(strFilePath.c_str, "r");
    }
    and i get this error:
    F:\C++ Projects\Generator\Generator.cpp(539) : error C2664: 'fopen' : cannot convert parameter 1 from 'const char *(void) const' to 'const char *'
    but I know that strFilePath.c_str returns a const char* and I've tried setting it to another const char* and using that but I get a similar error about not being able to convert it when initializing.

    so is there a way to conver this thing so i can open my file?

    thanx in advance,
    Boomba

  8. #8
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    ok i figured it out..I think I should learn more about type casting I found this on another site

    I initialized it this way:
    Code:
    char *readPath = const_cast<char*>(strFileName.c_str());
    then i used readPath to open my txt file.

    thanx for your help I'll test to see if my txt file is actually being read.

    thanx,
    Boomba

  9. #9
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by Boomba
    ok great...this will work but now I'm stuck on when I have to open the txt file...I get an error message becasue the path I specify in fopen is appearently not a const char*

    heres my code, I've tried:
    Code:
    //Check to see if it is a directory
    if(win32FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    strFilePath += "Questions.txt";
    fopen(strFilePath.c_str, "r");
    }
    and i get this error:


    but I know that strFilePath.c_str returns a const char* and I've tried setting it to another const char* and using that but I get a similar error about not being able to convert it when initializing.

    so is there a way to conver this thing so i can open my file?

    thanx in advance,
    Boomba
    Your problem has nothing to do with needing casts, and everything to do with needing ()s after the function call to c_str.
    fopen(strFilePath.c_str(), "r");
    is what you need.

    strFilePath.c_str is a function; if you use it as an rvalue, it evaluates to a function pointer, which is what the error was trying to tell you -- you can't convert a function pointer into a character pointer. Type "const char * (void)" means a pointer to a function taking no parameters and returning a const char *.

    Do NOT cast a const * to a non-const *, that's quite bad; things are usually const for a reason.
    Last edited by Cat; 06-14-2003 at 04:51 PM.

  10. #10
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    haha OMG!....well that makes simpler for me..thanx Cat I had no clue...well I'm glad i dont need that type cast anymore

    thanx,
    Boomba

  11. #11
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    ok I now have another problem

    Code:
    strFilePath += "Questions.txt";
    FILE *input = fopen(strFileName.c_str(), "r");
    fscanf(input, "%s", word);
    SetWindowText(txPreview, word);
    is there something wrong with the way I'm reading in....or inmy SetWindowText()?...nothing is being written to my textbox.

    thanx in advance,
    Boomba

Popular pages Recent additions subscribe to a feed

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