hey, i am a beginner in windows programming. I have written a code for drawing shapes as follows:-
#include <windows.h>
void OnPaint(HWND);
void OnDestroy(HWND);
int stdcall WinMain(HINSTANCE HInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdline, int nCmdShow)
{
MSG m;
//PERFORM APPLICATION INITIALIZATION
InitInstance(hinstance, nCmdShow, "Text");
//main message loop
while(GetMessage(&m,NULL,0,0))
DispatchMessage(&m);
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd , UINT message, WPARAM wParam,LPARAM lParam)
/*WndProc=windows procedure.This function is a message processing function
for our window. It will process any messages Windows sends to our program.
A callback function is a function in your program that is called by the operating system.
You see, in our program we will never actually call the function WndProc().
Windows will do that when ever it sends a message to our program. more on that later.*/
{
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;
HBRUSH hbr;
HGDIOBJ holdbr;
POINT pt[5]={250,150,250,300,300,350,400,300,320,190};
hdc=BeginPaint(hWnd,&ps);
hbr=CreateSolidBrush(RGB(25,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,110,350,110,350,10);
Polygon(hdc,pt,5);
SelectObject(hdc,holdbr);
DeleteObject(hbr);
EndPAint(hWnd, &ps);
}
and i am getting following errors:
C:\Documents and Settings\acer\My Documents\Pelles C Projects\new_try\nn.c(9): error #2001: Syntax error: expected ';' but found 'WinMain'.
C:\Documents and Settings\acer\My Documents\Pelles C Projects\new_try\nn.c(9): warning #2099: Missing type specifier; assuming 'int'.
C:\Documents and Settings\acer\My Documents\Pelles C Projects\new_try\nn.c(10): error #2120: Redeclaration of 'WinMain', previously declared at C:\Program Files\PellesC\Include\Win\winbase.h(1438); expected 'int __stdcall function(HINSTANCE, HINSTANCE, char *, int)' but found 'int __cdecl function(HINSTANCE, HINSTANCE, char *, int)'.
C:\Documents and Settings\acer\My Documents\Pelles C Projects\new_try\nn.c(14): warning #2018: Undeclared function 'InitInstance'; assuming 'extern' returning 'int'.
C:\Documents and Settings\acer\My Documents\Pelles C Projects\new_try\nn.c(14): error #2048: Undeclared identifier 'hinstance'.
C:\Documents and Settings\acer\My Documents\Pelles C Projects\new_try\nn.c(76): warning #2018: Undeclared function 'EndPAint'; assuming 'extern' returning 'int'.
*** Error code: 1 ***
Done.
Please help me out :(
int WINAPI WinMain(...
InitInstance(HInstance
The compiler sees int stdcall
as definition of an int variable named stdcall and wants a closing ';'
Thanxs for the help but now i m getting other errors as mentioned below:
C:\Documents and Settings\acer\My Documents\Pelles C Projects\new_try\nn.c(81): warning #2018: Undeclared function 'EndPAint'; assuming 'extern' returning 'int'.
Building new_try.exe.
POLINK: error: Unresolved external symbol '_InitInstance'.
POLINK: error: Unresolved external symbol '__imp__DispatchMessageA@4'.
POLINK: error: Unresolved external symbol '__imp__GetMessageA@16'.
POLINK: error: Unresolved external symbol '__imp__DefWindowProcA@16'.
POLINK: error: Unresolved external symbol '__imp__PostQuitMessage@4'.
POLINK: error: Unresolved external symbol '__imp__BeginPaint@8'.
POLINK: error: Unresolved external symbol '__imp__CreateSolidBrush@4'.
POLINK: error: Unresolved external symbol '__imp__SelectObject@8'.
POLINK: error: Unresolved external symbol '__imp__MoveToEx@16'.
POLINK: error: Unresolved external symbol '__imp__LineTo@12'.
POLINK: error: Unresolved external symbol '__imp__Rectangle@20'.
POLINK: error: Unresolved external symbol '__imp__RoundRect@28'.
POLINK: error: Unresolved external symbol '__imp__Ellipse@20'.
POLINK: error: Unresolved external symbol '__imp__Pie@36'.
POLINK: error: Unresolved external symbol '__imp__Polygon@12'.
POLINK: error: Unresolved external symbol '__imp__DeleteObject@4'.
POLINK: error: Unresolved external symbol '_EndPAint'.
POLINK: error: Unresolved external symbol '_main'.
POLINK: fatal error: 18 unresolved external(s).
*** Error code: 1 ***
Done.
Here is the formatted code:
#include <stdio.h>
#include<conio.h>
#include <windows.h>
//#include <helper.h>
void OnPaint(HWND);
void OnDestroy(HWND);
int WINAPI WinMain(HINSTANCE HInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdline, int nCmdShow)
{
MSG m;
//PERFORM APPLICATION INITIALIZATION
InitInstance(HInstance, nCmdShow, "Text");
//main message loop
while(GetMessage(&m,NULL,0,0))
DispatchMessage(&m);
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd , UINT message, WPARAM wParam,LPARAM lParam)
/*WndProc=windows procedure.This function is a message processing function
for our window. It will process any messages Windows sends to our program.
A callback function is a function in your program that is called by the operating system.
You see, in our program we will never actually call the function WndProc().
Windows will do that when ever it sends a message to our program. more on that later.*/
{
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;
HBRUSH hbr;
HGDIOBJ holdbr;
POINT pt[5]={250,150,250,300,300,350,400,300,320,190};
hdc=BeginPaint(hWnd,&ps);
hbr=CreateSolidBrush(RGB(25,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,110,350,110,350,10);
Polygon(hdc,pt,5);
SelectObject(hdc,holdbr);
DeleteObject(hbr);
EndPAint(hWnd, &ps);
}
It looks as if you haven't made a windows but a console project.
If this doesn't help, make a zip from your project and post it as attachment.
The llinker missing symbol errors are telling you that you have not included system libraries in the link.
Quote from: neha kapila on January 28, 2015, 08:06:21 AMwarning #2018: Undeclared function 'EndPAint'; ...
EndPAint(hWnd, &ps);
This is the second time that your compiler tells you to be more careful with your spelling. Are you sure you have a future in programming?
i have attached the zip file. Please help as i am a novice and no idea about how to make a windows project from the console one.
This is a console project, not a windows project.
then how can i make it a windows project?
Quote from: neha kapila on January 29, 2015, 10:11:41 AM
then how can i make it a windows project?
File->New->Project->win32
win32 program (exe)
win32 dynamic library (DLL)
win32 static lib
which 1 out of these?
What do you want to write, a program or a library?
A program to draw shapes.
Quote from: neha kapila on February 03, 2015, 07:54:07 AM
A program to draw shapes.
If you want to write a
program, you should select win32
program (exe).
hi czerny,
i am thankful that you are helping me out. Actully this is not my domain and i have to do it coz my boss hav assigned some task.
i made the program in win32 exe. and now i am getting the three errors
warning #2018: Undeclared function 'InitInstance'; assuming 'extern' returning 'int'.
warning #2018: Undeclared function 'rectangle'; assuming 'extern' returning 'int'.
warning #2018: Undeclared function 'EndPAint'; assuming 'extern' returning 'int'.
Building shapes.exe.
POLINK: error: Unresolved external symbol '_InitInstance'.
POLINK: error: Unresolved external symbol '_rectangle'.
POLINK: error: Unresolved external symbol '_EndPAint'.
POLINK: fatal error: 3 unresolved external(s).
Check the spelling of these 3 words. C is a case sensitive language.
If you can not fix your errors this way, zip your project end post it as attachment.
now only one error is present in the attached zip file.
i marked that line containing error as a comment and then executed. the program executed with no error but was not able to run.
if you can try to run the same in your pc/laptop whether its working or not that would be very helpful.
also helper.h is also showing error so i just marked it as a comment. plz tell me about how to resolve that also.
You have only send the project file (*.prj) not the whole project, Select (Project --> ZIP files) in the ide and post the zip file.
oh i am sorry.
here is the zip file
Ok, you should still check your spelling!
And you have called a function 'Initinstance' which you have never defind. Write it!