Thread: WM_PAINT prob

  1. #1
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178

    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);
    	}
    }
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  2. #2
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    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.
    Last edited by Jaken Veina; 07-12-2005 at 09:57 PM.
    Code:
    void function(void)
     {
      function();
     }

  3. #3
    C++ Beginner
    Join Date
    Jun 2005
    Posts
    39
    I'm using dev-c++ too, and I'm having the same problem, any help?
    I'm a beginner C++ programmer, but I have studied HTML and Java. So if you need to help me I should catch on fast =)

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    *this
    Join Date
    Mar 2005
    Posts
    498
    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.
    Last edited by JoshR; 07-12-2005 at 11:25 PM.

  6. #6
    *this
    Join Date
    Mar 2005
    Posts
    498
    Make sure you compile it as a windows project.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 06:53 PM
  2. wierd fopen prob
    By winterflood_j in forum C Programming
    Replies: 10
    Last Post: 02-24-2004, 06:31 AM
  3. prob function call
    By mouse163 in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 12:16 PM
  4. if-else prob..very basic so sorry to trouble u guys
    By bugeye in forum C Programming
    Replies: 2
    Last Post: 01-26-2002, 08:55 AM
  5. prob with fopen
    By ukcpaul in forum C Programming
    Replies: 2
    Last Post: 01-09-2002, 08:23 AM