Results 1 to 4 of 4

Thread: Text editor

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Croatia
    Posts
    22
    Somebody have some code of simple text editor in api's??
    VB, C++

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Not for the text editor but functions used to open and save a file using only API.
    PHP Code:
    BOOL SaveFile(HWND hEditLPSTR pszFileName)
    {
       
    HANDLE hFile;
       
    BOOL bSuccess FALSE;

       
    hFile CreateFile(pszFileNameGENERIC_WRITENULLNULL,
          
    CREATE_ALWAYSFILE_ATTRIBUTE_NORMALNULL);
       if(
    hFile != INVALID_HANDLE_VALUE)
       {
          
    DWORD dwTextLength;
          
    dwTextLength GetWindowTextLength(hEdit);
          if(
    dwTextLength 0)// No need to bother if there's no text.
          
    {
             
    LPSTR pszText;
             
    pszText = (char*)GlobalAlloc(GPTRdwTextLength 1);
             if(
    pszText != NULL)
             {
                if(
    GetWindowText(hEditpszTextdwTextLength 1))
                {
                   
    DWORD dwWritten;
                   if(
    WriteFile(hFilepszTextdwTextLength, &dwWrittenNULL))
                      
    bSuccess TRUE;
                }
                
    GlobalFree(pszText);
             }
          }
          
    CloseHandle(hFile);
       }
       return 
    bSuccess;
    }

    BOOL LoadFile(HWND hEditLPSTR pszFileName)
    {
       
    HANDLE hFile;
       
    BOOL bSuccess FALSE;

       
    hFile CreateFile(pszFileNameGENERIC_READFILE_SHARE_READNULL,
          
    OPEN_EXISTINGNULLNULL);
       if(
    hFile != INVALID_HANDLE_VALUE)
       {
          
    DWORD dwFileSize;
          
    dwFileSize GetFileSize(hFileNULL);
          if(
    dwFileSize != 0xFFFFFFFF)
          {
             
    LPSTR pszFileText;
             
    pszFileText = (char*)GlobalAlloc(GPTRdwFileSize 1);
             if(
    pszFileText != NULL)
             {
                
    DWORD dwRead;
                if(
    ReadFile(hFilepszFileTextdwFileSize, &dwReadNULL))
                {
                   
    pszFileText[dwFileSize] = 0// Null terminator
                   
    if(SetWindowText(hEditpszFileText))
                      
    bSuccess TRUE// It worked!
                
    }
                
    GlobalFree(pszFileText);
             }
          }
          
    CloseHandle(hFile);
       }
       return 
    bSuccess;

    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You like those functions, don't you?

    Nothing useful to mention......but did you put that sp; at the beginning? Looks like a bug to me

    Although for a simple text editor there's a sample at http://www.winprog.org/tutorial
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Yeah , i like those functions. Don't know why?

    And yes sp; shouldn't be there. I don't know how it got there.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width