linking errors in compilation

hii!!
there are some kind of linking errors coming up when compiled in dev c, is any kind of header file missing or some bugs.....
please help...i am really worried. .
thnx in advance..
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
#include<windows.h>

void OnPaint(HWND hWnd)
{  HDC hdc;
    
    PAINTSTRUCT ps;

HBRUSH hbr;

HGDIOBJ holdbr;

   POINT pt[5]={250,150,250,300,300,350,400,300,320,190};
  
  hdc=BeginPaint(hWnd,&ps);

     hbr=CreateSolidBrush(RGB(255,0,0));
    
    holdbr=SelectObject(hdc,hbr);
   
   MoveToEx(hdc,10,10,NULL);
   
   LineTo(hdc,200,10);
    
    Rectangle(hdc,10,20,200,100);
RoundRect(hdc,10,120,200,220,20,20);
Ellipse(hdc,10,240,200,340);
Pie(hdc,250,10,350,11,350,110,350,10);
Polygon(hdc,pt,5);
    
    SelectObject(hdc,holdbr);
     DeleteObject(hbr);
EndPaint(hWnd,&ps);
}
_stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdline,int nCmdShow)
{HWND hwnd;
OnPaint(hwnd);
}

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
39
40
41
42
43
44
45
46

LRESULT CALLBACK WndProc ( HWND, UINT, WPARAM, LPARAM ) ;

HINSTANCE hInst ; // current instance

/*   FUNCTION: InitInstance ( HANDLE, int 
     PURPOSE: Saves instance handle and creates main window
     COMMENTS: In this function, we save the instance handle in a global  
                            variable and create and display the main program window.
*/
BOOL InitInstance ( HINSTANCE hInstance, int nCmdShow, char* pTitle )
{
	char classname[ ] = "MyWindowClass" ;
	HWND hWnd ;

	WNDCLASSEX wcex ;
	wcex.cbSize			= sizeof ( WNDCLASSEX ) ; 
	wcex.style			= CS_HREDRAW | CS_VREDRAW ;
	wcex.lpfnWndProc	= ( WNDPROC ) WndProc ;
	wcex.cbClsExtra		= 0 ;
	wcex.cbWndExtra	= 0 ;
	wcex.hInstance		= hInstance ;
	wcex.hIcon			= NULL ;
	wcex.hCursor		= LoadCursor ( NULL, IDC_ARROW ) ;
	wcex.hbrBackground	= ( HBRUSH )( COLOR_WINDOW + 1 ) ;
	wcex.lpszMenuName	= NULL ;
	wcex.lpszClassName	= classname ;
	wcex.hIconSm		= NULL ;

	if ( !RegisterClassEx ( &wcex ) )
		return FALSE ;

	hInst = hInstance ; // Store instance handle in our global variable

	hWnd = CreateWindow ( classname, pTitle, 
					WS_OVERLAPPEDWINDOW,
					CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, 
					NULL, hInstance, NULL ) ;
	if ( !hWnd )
	    return FALSE ;
   
	ShowWindow ( hWnd, nCmdShow ) ;
	UpdateWindow ( hWnd ) ;

	return TRUE ;
}

and this is where they are called..
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
39
40
41
42
43
44
#include<windows.h>
#include"helper.h"
void OnPaint(HWND);
void OnDestroy(HWND);
_stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdline,int nCmdShow)
{MSG m;
InitInstance(hInstance,nCmdShow,"Text");
while(GetMessage(&m,NULL,0,0))
DispatchMessage(&m);
return 0;
}
LRESULT CALLBACK WndProc(HWNd hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{switch(message)
{case WM_DESTROY:
      OnDestroy(hWnd);
      break;
      case WM_PAINT:
           OnPaint(hWnd)
           break;
           default:return DefWindowProc(hWnd,message,wParam,lParam);}
           return 0;}
           void OnDestroy(HWND hWnd)
           {PostQuitMessage(0);
           }
           void OnPaint(HWND hWnd)
           {HDC hdc;
           PAINTSTRUCT ps;
           HFONT hfont;
           LOGFONT f={0};
           HGDIOBJ holdfont;
           char *fonts[]={"Arial","Times New Roman","Comic Sans MS"};
           int i;
           hdc=BeginPaint(hWnd,&ps);
           for(i=0;i<3;i++)
           strcpy(f.lfFaceName,fonts[i]);
           f.lfHeight=40*(i+1);
           f.lfItalic=1;
           hfont=CreateFontIndirect(&f);
           holdfont=SelectObject(hdc,hfont);
           SetTextCOlor(hdc,RGB(0,0,255));
           TextOut(hdc,10,70*i,"HELLO WINDOW",13);
           SelectObject(hdc,holdfont);
           DeleteObject(hfont);
           }

Last edited on
Please post the errors as well as the commands that compile it, if possible.
this compiles fine with me.. you just forgot some spelling and semicolon. also you have two OnPaint function, uncomment the other to show the shapes.
helper.h
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
39
40
41
42
43
44
45
46
#pragma once
#include <windows.h>

LRESULT CALLBACK WndProc ( HWND, UINT, WPARAM, LPARAM ) ;
HINSTANCE hInst ; // current instance

/*   FUNCTION: InitInstance ( HANDLE, int
     PURPOSE: Saves instance handle and creates main window
     COMMENTS: In this function, we save the instance handle in a global
                            variable and create and display the main program window.
*/
BOOL InitInstance ( HINSTANCE hInstance, int nCmdShow, char* pTitle ) {
    char classname[ ] = "MyWindowClass" ;
    HWND hWnd ;

    WNDCLASSEX wcex ;
    wcex.cbSize			= sizeof ( WNDCLASSEX ) ;
    wcex.style			= CS_HREDRAW | CS_VREDRAW ;
    wcex.lpfnWndProc	= ( WNDPROC ) WndProc ;
    wcex.cbClsExtra		= 0 ;
    wcex.cbWndExtra	    = 0 ;
    wcex.hInstance		= hInstance ;
    wcex.hIcon			= NULL ;
    wcex.hCursor		= LoadCursor ( NULL, IDC_ARROW ) ;
    wcex.hbrBackground	= ( HBRUSH )( COLOR_WINDOW + 1 ) ;
    wcex.lpszMenuName	= NULL ;
    wcex.lpszClassName	= classname ;
    wcex.hIconSm		= NULL ;

    if ( !RegisterClassEx ( &wcex ) )
        return FALSE ;

    hInst = hInstance ; // Store instance handle in our global variable

    hWnd = CreateWindow ( classname, pTitle,
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL,
                          NULL, hInstance, NULL ) ;
    if ( !hWnd )
        return FALSE ;

    ShowWindow ( hWnd, nCmdShow ) ;
    UpdateWindow ( hWnd ) ;

    return TRUE ;
}


paint.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once

void OnPaint(HWND hWnd) {
    HDC hdc;
    PAINTSTRUCT ps;
    HFONT hfont;
    LOGFONT f={0};
    HGDIOBJ holdfont;
    char *fonts[]={"Arial","Times New Roman","Comic Sans MS"};
    int i;
    hdc=BeginPaint(hWnd,&ps);
    for (i=0;i<3;i++)
        strcpy(f.lfFaceName,fonts[i]);
    f.lfHeight=40*(i+1);
    f.lfItalic=1;
    hfont=CreateFontIndirect(&f);
    holdfont=SelectObject(hdc,hfont);
    SetTextColor(hdc,RGB(0,0,255));
    TextOut(hdc,10,70*i,"HELLO WINDOW",13);
    SelectObject(hdc,holdfont);
    DeleteObject(hfont);
}




/*
void OnPaint(HWND hWnd) {
    HDC hdc;

    PAINTSTRUCT ps;

    HBRUSH hbr;

    HGDIOBJ holdbr;

    POINT pt[5]={250,150,250,300,300,350,400,300,320,190};

    hdc=BeginPaint(hWnd,&ps);

    hbr=CreateSolidBrush(RGB(255,0,0));

    holdbr=SelectObject(hdc,hbr);

    MoveToEx(hdc,10,10,NULL);

    LineTo(hdc,200,10);

    Rectangle(hdc,10,20,200,100);
    RoundRect(hdc,10,120,200,220,20,20);
    Ellipse(hdc,10,240,200,340);
    Pie(hdc,250,10,350,11,350,110,350,10);
    Polygon(hdc,pt,5);

    SelectObject(hdc,holdbr);
    DeleteObject(hbr);
    EndPaint(hWnd,&ps);
}
*/


main.cpp
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
#include <windows.h>
#include "helper.h"
#include "paint.h"

void OnPaint(HWND);
void OnDestroy(HWND);

_stdcall int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdline,int nCmdShow) {
    MSG m;
    InitInstance(hInstance,nCmdShow,"Text");
    while (GetMessage(&m,NULL,0,0))
        DispatchMessage(&m);
    return 0;
}



LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) {
    switch (message) {
    case WM_DESTROY:
        OnDestroy(hWnd);
        break;
    case WM_PAINT:
        OnPaint(hWnd);
        break;
    default:
        return DefWindowProc(hWnd,message,wParam,lParam);
    }
    return 0;
}



void OnDestroy(HWND hWnd) {
    PostQuitMessage(0);
}
@backcoder41
thanx a lot dude,....
ya its running perfectly now...its ws of great help...!
thkew
Topic archived. No new replies allowed.