NO

Author Topic: Windows Programming  (Read 13774 times)

neha kapila

  • Guest
Windows Programming
« on: January 20, 2015, 07:18:02 AM »
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 :(

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Windows Programming
« Reply #1 on: January 20, 2015, 07:36:05 AM »
int WINAPI WinMain(...
 InitInstance(HInstance

czerny

  • Guest
Re: Windows Programming
« Reply #2 on: January 20, 2015, 08:17:08 AM »
The compiler sees
Code: [Select]
int stdcall as definition of an int variable named stdcall and wants a closing ';'

neha kapila

  • Guest
Re: Windows Programming
« Reply #3 on: January 28, 2015, 08:06:21 AM »
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);
}





czerny

  • Guest
Re: Windows Programming
« Reply #4 on: January 28, 2015, 10:47:46 AM »
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.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: Windows Programming
« Reply #5 on: January 28, 2015, 10:55:37 AM »
The llinker missing symbol errors are telling you that you have not included system libraries in the link.
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Windows Programming
« Reply #6 on: January 28, 2015, 02:29:03 PM »
warning #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?

neha kapila

  • Guest
Re: Windows Programming
« Reply #7 on: January 29, 2015, 09:38:58 AM »
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.

czerny

  • Guest
Re: Windows Programming
« Reply #8 on: January 29, 2015, 09:59:22 AM »
This is a console project, not a windows project.

neha kapila

  • Guest
Re: Windows Programming
« Reply #9 on: January 29, 2015, 10:11:41 AM »
then how can i make it a windows project?

czerny

  • Guest
Re: Windows Programming
« Reply #10 on: January 29, 2015, 11:30:01 AM »
then how can i make it a windows project?
File->New->Project->win32

neha kapila

  • Guest
Re: Windows Programming
« Reply #11 on: January 29, 2015, 11:49:16 AM »
win32 program (exe)
win32 dynamic library (DLL)
win32 static lib
which 1 out of these?

czerny

  • Guest
Re: Windows Programming
« Reply #12 on: January 29, 2015, 01:07:13 PM »
What do you want to write, a program or a library?

neha kapila

  • Guest
Re: Windows Programming
« Reply #13 on: February 03, 2015, 07:54:07 AM »
A program to draw shapes.

czerny

  • Guest
Re: Windows Programming
« Reply #14 on: February 03, 2015, 08:08:00 AM »
A program to draw shapes.
If you want to write a program, you should select win32 program (exe).