Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 656497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:43:14+00:00 2026-05-13T22:43:14+00:00

I’m trying to read the contents of a small text file using the common

  • 0

I’m trying to read the contents of a small text file using the common dialog box, pass the text in the file into a buffer and draw it to the form by invalidating the window and forcing the repaint.

Everything works with exception to displaying the text on the screen, when I click on the OK button on the dialog box no text appears.

I’m new to C so I might of missed a keyword or used an incorrect pointer.

Here’s a snippet of my code so far:

LRESULT CALLBACK WindowFunc(HWND hMainWindow, UINT message, 
                            WPARAM wParam, LPARAM lParam)
{
    CHAR fileText[1024];
    HDC hdc;
    OPENFILENAME ofn;
    TCHAR szFile[MAX_PATH];
    HANDLE fileHandle;
    RECT clientArea;
    PAINTSTRUCT pStruct;

    // Act on current message
    switch(message)    
    {
    case WM_CREATE:
        AddMenus(hMainWindow);
        break;

    case WM_COMMAND:


        switch(LOWORD(wParam))
        {
        case IDM_FILE_OPEN:

            ZeroMemory(&ofn, sizeof(ofn));
            ofn.lStructSize = sizeof(ofn);
            ofn.lpstrFile = szFile;
            ofn.lpstrFile[0] = '\0';
            ofn.hwndOwner = hMainWindow;
            ofn.nMaxFile = sizeof(szFile);
            ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0");
            ofn.nFilterIndex = 1;
            ofn.lpstrInitialDir = NULL;
            ofn.lpstrFileTitle = NULL;
            ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

            if(GetOpenFileName(&ofn))
            {
                fileHandle = CreateFile(&ofn.lpstrFile,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
                ReadFile(fileHandle,fileText,1023,0,0);
                CloseHandle(fileHandle);
            }

            GetClientRect(hMainWindow, &clientArea);
            InvalidateRect(hMainWindow,
                            &clientArea,
                            TRUE
                            );          

            break;
        case IDM_FILE_QUIT:
            SendMessage(hMainWindow, WM_CLOSE, 0, 0);
            break;

        }
        break;

    case WM_PAINT:

        hdc = BeginPaint(hMainWindow, &pStruct);

        DrawTextA(hdc,
                fileText, 
                -1,
                &clientArea,
                DT_WORDBREAK);

        EndPaint(hMainWindow, &pStruct);

        break;

    case WM_DESTROY:

        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc(hMainWindow, message, wParam, lParam);
    }
    return 0;
}

Where am I going wrong exactly? Also I know it’s not perfect in it’s conception as my aim is to simply get it working and then re factor it afterwards.

Thank you for your time.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:43:15+00:00Added an answer on May 13, 2026 at 10:43 pm

    CreateFile(W)’s first parameter’s type is LPCWSTR (Constant WString).

    ofn.lpstrFile is a LPWSTR (WString)

    So &ofn.lpstrFile is wrong in your code (being a LPWSTR*).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.