Connecting Tech Pros Worldwide Forums | Help | Site Map

Could someone please help me fix this problem i've been having with my Windows GUI.

Newbie
 
Join Date: Oct 2009
Posts: 2
#1: 4 Weeks Ago
I'm only having a problem with a small part, i'm fairly new to computer programming and the program i'm using is Dev-C++. The part that i'm having a problem with is this:

int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int CmdShow);
;{
static WNDCLASS Wc;
memset(&Wc,0,sizeof(Wc));
static MSG Msg;
memset(&Msg,0,sizeof(Msg));

Wc.style=CS_HREDRAW | CS_VREDRAW;
Wc.lpfnWndProc=WndProc;
Wc.cbClsExtra=0;
Wc.cbWndExtra=0;
Wc.hInstance=hInst;
Wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);

Errors:
54 C:\Users\Matthew\Dev-Cpp\Bouncing ball.cpp expected unqualified-id before '{' token
54 C:\Users\Matthew\Dev-Cpp\Bouncing ball.cpp expected `,' or `;' before '{' token
Line 54 is the problem and it's the ";{" line.
Please help me out with this problem, i honestly have no idea what i can do to fix it.

Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,180
#2: 4 Weeks Ago

re: Could someone please help me fix this problem i've been having with my Windows GUI.


Remove the ; at the end of the previous line and the beginning of that line 54.

Make sure you have include Windows.h (directly or indirectly).

Make sure you haven't #defined any symbols with clashing names.
Newbie
 
Join Date: Oct 2009
Posts: 2
#3: 4 Weeks Ago

re: Could someone please help me fix this problem i've been having with my Windows GUI.


That didn't fix the problem, here is all of the work i've done.

Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2.  
  3. #define Show(Window) RedrawWindow(Window,0,0,0);ShowWindow(Window,SW_SHOW);
  4.   [Linker error] undefined reference to `GetStockObject@4' 
  5.  C:\Users\Matthew\AppData\Local\Temp\ccIveaaa.o(.text+0x350) In function `Z7WndProcP6HWND__jjl': 
  6.  
  7. #define AppName "BouncingBall1"
  8. #define Caption "Bouncing Ball ..."
  9.  
  10. char BCX_STR [1024*1024];
  11.  
  12. static int     BCX_GetDiaUnit;
  13. static int     BCX_cxBaseUnit;
  14. static int     BCX_cyBaseUnit;
  15. static int     BCX_ScaleX;
  16. static int     BCX_ScaleY;
  17. static HANDLE  Form1;
  18.  
  19. double  MIN (double,double);
  20. double  MAX (double,double);
  21.  
  22. int     WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
  23. void    FormLoad (HANDLE);
  24. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
  25.  
  26.  
  27. double MAX (double a, double b)
  28. {
  29.   if (a > b)
  30.   {
  31.     return a;
  32.   }
  33.   return b;
  34. }
  35.  
  36.  
  37. double MIN (double a, double b)
  38. {
  39.   if (a < b)
  40.   {
  41.     return a;
  42.   }
  43.   return b;
  44. }
  45.  
  46.  
  47. // standard main for Windows GUI
  48. int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int CmdShow)
  49. {
  50.   static  WNDCLASS  Wc;
  51.   memset(&Wc,0,sizeof(Wc));
  52.   static  MSG  Msg;
  53.   memset(&Msg,0,sizeof(Msg));
  54.  
  55.   Wc.style=CS_HREDRAW | CS_VREDRAW;
  56.   Wc.lpfnWndProc=WndProc;
  57.   Wc.cbClsExtra=0;
  58.   Wc.cbWndExtra=0;
  59.   Wc.hInstance=hInst;
  60.   Wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
  61.   Wc.hCursor=LoadCursor(NULL,IDC_ARROW);
  62.   Wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
  63.   Wc.lpszMenuName=NULL;
  64.   Wc.lpszClassName=AppName;
  65.   RegisterClass(&Wc);
  66.   FormLoad(hInst);
  67.   // 50ms here, lower value gives higher speed
  68.   SetTimer((HWND)Form1,1,50,NULL);
  69.   // ye olde event message loop
  70.   while(GetMessage(&Msg,NULL,0,0))
  71.   {
  72.     if (!IsWindow((HWND)Form1)||!IsDialogMessage((HWND)Form1,&Msg))
  73.     {
  74.       TranslateMessage(&Msg);
  75.       DispatchMessage(&Msg);
  76.     }
  77.   }
  78.   return Msg.wParam;
  79. }
  80.  
  81.  
  82. // create the form and show it (somewhat older style)
  83. void FormLoad (HANDLE hInst)
  84. {
  85.   // get the scale factors
  86.   BCX_GetDiaUnit = GetDialogBaseUnits();
  87.   BCX_cxBaseUnit = LOWORD(BCX_GetDiaUnit);
  88.   BCX_cyBaseUnit = HIWORD(BCX_GetDiaUnit);
  89.   BCX_ScaleX = BCX_cxBaseUnit/4;
  90.   BCX_ScaleY = BCX_cyBaseUnit/8;
  91.   // now the form
  92.   Form1=CreateWindow(AppName,Caption,
  93.     DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU,
  94.     10*BCX_ScaleX,20*BCX_ScaleY,250*BCX_ScaleX,175*BCX_ScaleY,NULL,
  95.     (HMENU)NULL,(HINSTANCE)hInst,NULL);
  96.   Show((HWND)Form1);
  97. }
  98.  
  99.  
  100. // event message handler
  101. LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  102. {
  103.   static  HANDLE  hBitmap;
  104.   static  HBRUSH  hBrush;
  105.   static  HDC  hdc;
  106.   static  HDC  hdcMem;
  107.   static int cxClient;
  108.   static int cyClient;
  109.   static int xCenter;
  110.   static int yCenter;
  111.   static int cxTotal;
  112.   static int cyTotal;
  113.   static int cxRadius;
  114.   static int cyRadius;
  115.   static int cxMove;
  116.   static int cyMove;
  117.   static int xPixel;
  118.   static int yPixel;
  119.   static int nScale;
  120.  
  121.   while(1)
  122.   {
  123.     if (Msg == WM_CREATE)
  124.     {
  125.       hdc = GetDC(hWnd);
  126.       xPixel = GetDeviceCaps(hdc,ASPECTX);
  127.       yPixel = GetDeviceCaps(hdc,ASPECTY);
  128.       ReleaseDC(hWnd,hdc);
  129.       return 0;
  130.       break;
  131.     }
  132.     // draw the ball
  133.     if (Msg == WM_SIZE)
  134.     {
  135.       xCenter = (cxClient=LOWORD(lParam))/2;
  136.       yCenter = (cyClient=HIWORD(lParam))/2;
  137.       nScale = (int)MIN(cxClient*xPixel,cyClient*yPixel)/16;
  138.       cxRadius = nScale/xPixel;
  139.       cyRadius = nScale/yPixel;
  140.       cxMove = (int)MAX(1,cxRadius/4);
  141.       cyMove = (int)MAX(1,cyRadius/4);
  142.       cxTotal = 2*(cxRadius+cxMove);
  143.       cyTotal = 2*(cyRadius+cyMove);
  144.       if (hBitmap)
  145.       {
  146.         DeleteObject(hBitmap);
  147.       }
  148.       hdc = GetDC(hWnd);
  149.       hdcMem = CreateCompatibleDC(hdc);
  150.       hBitmap = CreateCompatibleBitmap(hdc,cxTotal,cyTotal);
  151.       ReleaseDC(hWnd,hdc);
  152.       SelectObject(hdcMem,hBitmap);
  153.       Rectangle(hdcMem,-1,-1,cxTotal+1,cyTotal+1);
  154.       hBrush = CreateHatchBrush(HS_DIAGCROSS,0);
  155.       SelectObject(hdcMem,hBrush);
  156.       SetBkColor(hdcMem,RGB(0,127,255));
  157.       Ellipse(hdcMem,cxMove,cyMove,cxTotal-cxMove,cyTotal-cyMove);
  158.       DeleteDC(hdcMem);
  159.       DeleteObject(hBrush);
  160.       return 0;
  161.       break;
  162.     }
  163.     // move the ball
  164.     if (Msg == WM_TIMER)
  165.     {
  166.       if (!hBitmap)
  167.       {
  168.         break;
  169.       }
  170.       hdc = GetDC(hWnd);
  171.       hdcMem = CreateCompatibleDC(hdc);
  172.       SelectObject(hdcMem,hBitmap);
  173.       BitBlt(hdc,xCenter-cxTotal/2,yCenter-cyTotal/2,cxTotal,cyTotal,hdcMem,0,0,SRCCOPY);
  174.       ReleaseDC(hWnd,hdc);
  175.       DeleteDC(hdcMem);
  176.       xCenter += cxMove;
  177.       yCenter += cyMove;
  178.       if (xCenter+cxRadius>=cxClient||xCenter-cxRadius<=0)
  179.       {
  180.           cxMove = -cxMove;
  181.       }
  182.       if (yCenter+cyRadius >= cyClient || yCenter-cyRadius <= 0)
  183.       {
  184.           cyMove = -cyMove;
  185.       }
  186.       return 0;
  187.       break;
  188.     }
  189.     // clean up and exit program
  190.     if (Msg == WM_DESTROY)
  191.     {
  192.       if (hBitmap)
  193.       {
  194.         DeleteObject(hBitmap);
  195.       }
  196.       KillTimer((HWND)Form1,1);
  197.       PostQuitMessage(0);
  198.       return 0;
  199.     }
  200.     break;
  201.   }
  202.   return DefWindowProc(hWnd, Msg, wParam, lParam);
  203. }
  204.  
About 200 lines and here are the new errors:
C:\Users\Matthew\AppData\Local\Temp\ccIveaaa.o(.te xt+0x100) In function `WinMain':
[Linker error] undefined reference to `GetDeviceCaps@8'
[Linker error] undefined reference to `GetDeviceCaps@8'
[Linker error] undefined reference to `DeleteObject@4'
[Linker error] undefined reference to `CreateCompatibleDC@4'
[Linker error] undefined reference to `CreateCompatibleBitmap@12'
[Linker error] undefined reference to `SelectObject@8'

[Linker error] undefined reference to `Rectangle@20'
[Linker error] undefined reference to `CreateHatchBrush@8'

And several others continuing along those lines of linker errors.
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,180
#4: 4 Weeks Ago

re: Could someone please help me fix this problem i've been having with my Windows GUI.


Actually that did fix the problem, its just that you had a second underlying problem that has now surfaced.

You program appears to compile where it didn't before but you now have linker programs (ignoring that fact that you seem to have a linker error embedded in the top of your code which I assume is a posting error).

"Undefined Reference" means that the linker was unable to resolve all the symbols in the program into addresses. In this case you have called functions that the linker can not find in any of you object files or any libraries that it is using.

Checking the help for GetDeviceCaps it seems likely that you have left gdi32.lib out of your linker command line, or if you are using an IDE then you have failed to specify it in the section for additional libraries.

So far all the functions I have checked have come from that library but if you add it and that does not resolve all the undefined symbols then look up those symbols that are still causing the error to see which library you need to include.
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 385
#5: 4 Weeks Ago

re: Could someone please help me fix this problem i've been having with my Windows GUI.


What is linker's command line?
http://aditsu.freeunixhost.com/dev-cpp-faq.html#link ?
Reply