How to set text to a static from a .txt file

Part from my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
.
.
void LoadFileInResource(int name, int type, DWORD& size, const char*& data)
{
    HMODULE handle = ::GetModuleHandle(NULL);
    HRSRC rc       = ::FindResource(handle, MAKEINTRESOURCE(name), MAKEINTRESOURCE(type));
    HGLOBAL rcData = ::LoadResource(handle, rc);
    size           = ::SizeofResource(handle, rc);
    data           = static_cast <const char*>(::LockResource(rcData));
/////////////////////////////////////////
//send text here
void staticWindow(HWND hWnd)
{
    hStatic = CreateWindowW(L"Static", L"",
                  WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_VSCROLL,
                          706, 123, 355, 411, hWnd, NULL, NULL, NULL);
}
/////////////////////////////////////////
// code when user press the button to send text
case WM_COMMAND:
	switch(wp)
	{
		case IDCH_BOX1:
                    {
                    DWORD size = 0;
                    const char* data = NULL;
                    LoadFileInResource(IDR_MYTEXT, TEXTFILE, size, data);
                    char* buffer = new char[size + 1];
                    ::memcpy(buffer, data, size);
                    buffer[size] = 0;
                    SendMessageW((HWND)hStatic, WM_SETTEXT, 0, 0);
                    delete[] buffer;
                    return DefWindowProc(hWnd, msg, wp, lp);
                    }
		default:
			return DefWindowProc(hWnd, msg, wp, lp);
	}
}


in my resource.h I have:

#define TEXTFILE 256
#define IDR_MYTEXT 101

and i my resource.rc I have:

IDR_MYTEXT TEXTFILE "AmazonBasic.txt"


And in my main project folder I have this AmazonBasic.txt

I only know that is something wrong with the SendMessageW(HWND, UINT, WPARAM, LPARAM) and the LPARAM doesn't have to be 0 if I have to send the hStatic the text.
Can anyone show me the right way in to doing this.. ?
Did you ever bother to look at the docu for WM_SETTEXT ?
Why do you pass 0 for LPARAM and expect to see any text?
Yes Thomas.. I did.. and I set it like this for the post.. I know it doesn't have to be 0
but what should I set to: SendMessageW((HWND) hStatic, WM_SETTEXT, 0, (LPARAM)"?");
This is where I don't get it..
I mean I know it has to be like this:
SendMessageW((HWND)hStatic, WM_SETTEXT, 0, (LPARAM)L"text here");

but instead of (LPARAM)L"text here"), has to be my .txt file from my main folder. How to set this.. this is what I don't understand.
And I expect people to see the real reason I'm asking this.. I do recognize an error like that I set it 0 cause I thought a experienced programmer will know that I didn't set it by error but just to show the code.. and he will know what did I meant ... So my question is what should I wrote instead of 0 that I know is the LPARAM and it doesn't have to be 0 if any text has to be sent in my case (from the .txt that is in my project folder)...?
Last edited on
You load the text into data. So you should pass data to the static control.
But first you should check that data contains the text you expect.
SendMessageA((HWND)hStatic, WM_SETTEXT, 0, (LPARAM)data);
But why is data const if you want to store the text in it?
Also don't use SendMessageW when you have a char. SendMessageW expects a wchar_t.
OK.. Thomas.. as I expected I wanted to see your answer .. I did pass (LPARAM)data <- in it
but what I did see on the static is chinese text.. unreadable..
Now I only changed the SendMessage instead of SendMessageW and the data shows up like on the .txt file The only problem now is that .. I did set the WS_HSCROLL | WS_VSCROLL, on the static but doesn't seems to work , I can only see a part of it.. :\
This might help: https://stackoverflow.com/questions/13775046/static-control-scroll-bar-not-working-win32

Why do you use a static control for longer text? Normally the used as labels, for example a header for a listbox...
Why don't you just use a textbox?
Well.. my static control is where other messages will be shown up and not only text, even bitmap. That's why I wanna keep the static control I design for all the messages I wanna show is in that location. I thought this will be easy but the fact is I have to redesign the SDI I have.

Thank you very very much for the help Thomas ..
You are very welcome.
Topic archived. No new replies allowed.