Hi there,
I have just started programming in the win32 API and I've had a small problem that's been bothering me for a couple of days - I'm sure I'm missing out something fundamental, so apologies if I'm doing something foolish.
The windows procedure for left mouse button press calls LPSTR from ReadText() and displays the correct text. However, when the window is resized and LM button is pressed again "/0" is displayed - and I'm not sure why, I was expecting the correct text to be displayed. If I call readfile() there is no problem and the string displays correctly.
I have copied my code below, followed by the functions - any help would be really appreciated. Many thanks!
WinMain:
case WM_LBUTTONDOWN:
{
hdc = BeginPaint(hWnd, &ps);
//Application-specific layout
str = ReadTxt();
TextOut(hdc,
5, 5,
str, strlen(str));
// End application-specific layout section.
EndPaint(hWnd, &ps);
}
break;
ReadTxt():
LPSTR ReadTxt (void)
{
char FileBuffer[128] = {"/0"};
DWORD dwBytesRead = 0;
LPSTR strFB = "0" ;
if(!ReadFile(hFile, FileBuffer, 128, &dwBytesRead, NULL))
{
void* lpBuffer;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpBuffer,
0,
NULL );
MessageBox( NULL, (LPCTSTR)lpBuffer, __T("Last Error"), MB_OK );
LocalFree( lpBuffer );
}
else
{
strFB = FileBuffer;
return _T(strFB);
}
return 0;
}
readfile():
LPSTR readfile (void)
{
LPSTR greeting = _T("Hello World!");
return greeting;
}
Many thanks again!