Thread: Filling in the edit with the file

  1. #16
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    golfinguy4 - my point exactly! (Read one of the threads about ASM if you dont understand) What he should have done was use as many C++ libary functions as possible, this maintains code (code not executible) portability.
    VC++ 6

  2. #17
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I don't write functions like that so avoid using the win api. I have no gripes about overhead or speed when it comes to IO on any operating system. However, why write something you'll just need to re-write later. I think one advantage to making portable code that no-one really talks about is that I can get programming help from a Unix message board. I really don't care if fopen, fclose, fread, fwrite, read, write, creat, open, and close all use the api (which would make sense since they interface with the actual operating system) they get the job done without me needing to look in the Windows SDK manual every time I need to use them.

  3. #18
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by VBprogrammer
    golfinguy4 - my point exactly! (Read one of the threads about ASM if you dont understand) What he should have done was use as many C++ libary functions as possible, this maintains code (code not executible) portability.
    Yes but the fundemental goal was to display data in an editbox......therefore his code cannot be portable.....

  4. #19
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Fordy is right to some extent. But once again, portable doesn't necessarily mean you take windows source code and compile it to linux. It means I that one doesn't need to spend 5 hours changing window's specific calls to linux specific calls. I think people have a personal preference when it comes to making portable code. The way I look at is that one day microsoft may crumble and we are all using some new operating system. Some of us will be able to take our code and with little changes be able to re-use it. Others will have to start over from the top. I make portable code so I can make open source projects that other platforms can use.

  5. #20
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by master5001
    Fordy is right to some extent. But once again, portable doesn't necessarily mean you take windows source code and compile it to linux. It means I that one doesn't need to spend 5 hours changing window's specific calls to linux specific calls. I think people have a personal preference when it comes to making portable code. The way I look at is that one day microsoft may crumble and we are all using some new operating system. Some of us will be able to take our code and with little changes be able to re-use it. Others will have to start over from the top. I make portable code so I can make open source projects that other platforms can use.
    Another interersting angle.......if I develop a commercial app for windows, and I lose the source......would I want it to be easily ported to *nix?....dont think so....

  6. #21
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, I got it working to open a file and put the text in the edit, but now how would I take the text and save it to a file? Thanks, fellas!
    1978 Silver Anniversary Corvette

  7. #22
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Garfield
    Okay, I got it working to open a file and put the text in the edit, but now how would I take the text and save it to a file? Thanks, fellas!
    Send Messages EM_GETTEXTLENGTHEX & EM_GETTEXTEX To get the text...then WriteFile();

  8. #23
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Fordy, what are the parameter specifics of those messages? This bothers me. Is there any place that I can get the SDK CD for free? I need these documentations...
    1978 Silver Anniversary Corvette

  9. #24
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    I have a question regarding this code
    Code:
    hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    
    	if(hFile != INVALID_HANDLE_VALUE)
    	{
    		DWORD dwFileSize;
    
    		dwFileSize = GetFileSize(hFile, NULL);
    
    		if(dwFileSize != 0xFFFFFFFF)
    		{
    			LPSTR FileText;
    
    			SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Opening...");
    
    			FileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1);
    
    			if(FileText != NULL)
    			{
    				DWORD dwRead;
    
    				if(ReadFile(hFile, FileText, dwFileSize, &dwRead, NULL))
    				{
    					FileText[dwFileSize] = 0;	// Set the NULL terminator
    
    					SetWindowText(hEdit, FileText);
    				}
    				GlobalFree(FileText);
    			}
    		}
    		CloseHandle(hFile);
    		SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Ready...");
    		
    		char WindowText[256];
    		strcpy(WindowText, "NotepadX -- ");
    		strcat(WindowText, FileName);
    		SetWindowText(hwnd, WindowText);
    	}
    }
    This works fine when I am using it to open smaller files. In fact it has worked on ASCII files up to 1.8 Mb large. When I tried a 4 Mb ASCII file it failed. I debugged and found it was failing at if(dwFileSize != 0xFFFFFFFF). Is this way limited by the size of the file? I am not using an edit control by the way I am using a richedit control.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  10. #25
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Garfield
    Fordy, what are the parameter specifics of those messages? This bothers me. Is there any place that I can get the SDK CD for free? I need these documentations...
    Info here

  11. #26
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, I remember that thread, but I can't always go online to look up a function or some other stuff, so what's why I would need the CD. Anywhere?
    1978 Silver Anniversary Corvette

  12. #27
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Garfield
    Yeah, I remember that thread, but I can't always go online to look up a function or some other stuff, so what's why I would need the CD. Anywhere?


    No Garf...the link given by Robert602 allows you to go and download the docs of the SDK.....this is very much like the MSDN you get with VC++....except its more up to date and doesnt have any std lib functions (but all documented APIs are in there).....

  13. #28
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Fordy, do I want to install the Core SDK or the Windows installer SDK? Thanks...
    1978 Silver Anniversary Corvette

  14. #29
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Garfield
    Fordy, do I want to install the Core SDK or the Windows installer SDK? Thanks...
    I would get the core SDK...it will have the new libs and includes......add them to your options->directories in VC++ and you can use the newly defined functions....

  15. #30
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, I pretty much just need them for reference on params and the such...
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM