-
WM_PAINT prob
i get this linker error with Dev-C++ when i do this:
[Linker error] undefined reference to `TextOutA@20'
Code:
// This program shows the working of the WM_PAINT message
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
void Paint(HWND hwnd);
int WINAPI WinMain (HINSTANCE hinst, HINSTANCE hprevinst, LPSTR lpCmdLine, int cmdShow)
{
if (hprevinst == NULL)
{
WNDCLASS wclass;
memset (&wclass, 0, sizeof(wclass));
wclass.style = CS_HREDRAW | CS_VREDRAW;
wclass.lpfnWndProc = WndProc;
wclass.hInstance = hinst;
wclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wclass.lpszClassName = "BASIC2";
if (!RegisterClass (&wclass)) return 0;
}
HWND hwnd = CreateWindow("BASIC2", "The Title", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hinst, NULL);
ShowWindow(hwnd, cmdShow);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
Paint(hwnd);
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
}
void Paint(HWND hwnd)
{
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
if (ps.hdc)
{
TextOut(ps.hdc, 10, 10, "Hello world", 11);
EndPaint(hwnd, &ps);
}
}
-
I'm not familiar with the TextOut function, but that error means that the function has a prototype, meaning you have included the correct headers, but the actual definition of the function isn't present. This means that the library needed has not been linked. Not being familiar with TextOut, I don't know which library this would be.
My guess is that you're not linking to the gdi32 library. It uses the same idea as the commctl32 library.
-
I'm using dev-c++ too, and I'm having the same problem, any help?
-
Look up the missing function in the manual.
Find which library it is from.
Link your app to this library. (I don't know how in Dev C++ but I'm sure someone has posted how here before)
-
Also put EndPaint out of the if statement because you want to execute it no matter what.
And...
For future reference you should add TranslateMessage to your message loop so virtual keys are automatically translated to characters
Code:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
You dont need this:
Code:
memset (&wclass, 0, sizeof(wclass));
Code:
if (hprevinst == NULL)
{
And you shouldn't refer to the previous instance, it's an old way of saving memory that shouldn't be done anymore.
-
Make sure you compile it as a windows project.