Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I output .txt file contents into a MessageBox?

Status
Not open for further replies.

Unrivaled1

IS-IT--Management
Feb 9, 2005
20
US
Is there any way to output the contents of a standard ms-dos text file directly into a MessageBox?
 
Just open that file and display it in MessageBox:

Code:
HWND hWnd;            //Parent Window handle
LPCTSTR pFileName;    //File path

HANDLE hFile = CreateFile(pFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
    UINT nFileLen = GetFileSize(hFile, NULL);
    if(nFileLen != INVALID_FILE_SIZE)
    {
        BYTE* pData = new BYTE[nFileLen + 1];
        pData[nFileLen] = '\0';

        DWORD ncbRead;
        if(ReadFile(hFile, (LPVOID)pData, nFileLen, &ncbRead, NULL) && ncbRead == nFileLen)
        {
                MessageBox(hWnd, pData, "Program Name", MB_OK | MB_ICONINFORMATION);
        }

        delete[] pData;
    }
    CloseHandle(hFile);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top