473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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.
Oct 30 '09 #1
4 4111
Banfa
9,065 Expert Mod 8TB
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.
Oct 30 '09 #2
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.
Oct 30 '09 #3
Banfa
9,065 Expert Mod 8TB
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.
Oct 30 '09 #4
newb16
687 512MB
What is linker's command line?
http://aditsu.freeunixhost.com/dev-cpp-faq.html#link ?
Oct 30 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: erebus- | last post by:
When learning the C programing languages, i have had and still am having the problem of not being able to find answers to many questions. Is their an overall guide/reference that someone knows?
8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
3
by: Nathan Alden | last post by:
I've already searched Google. I've already asked people in IRC. I have still not found a solution that works for me for this extremely discouraging apparent bug in the SmtpMail class. ...
1
by: Eric Keij | last post by:
Hi, I've installed Windows XP Service Pack 2 and the latest .NET framework service pack. The .NET framework version running is 1.1.4322.573. After these updates we experience problems running...
6
by: dhnriverside | last post by:
Hi peeps Ok, I've got a web application running (lets call it MyApp, so its namespace is MyApp). I've created a subdirectory within this application called "secure", and made than an Application...
1
by: Asha | last post by:
hello attach is a problem i'm having after deploying to the production server. can someone please identify whats wrng with it? all the required dll which was running on the development server was...
14
by: Gianfranco | last post by:
Hi everybody, First of all, sorry for my english if it isn't perfect ;-p I have an error in an asp.net application. I have win2003 server, with iis 6. I'm developping with visual studio...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
12
by: Tom | last post by:
First, my thanks in advance to those who can help explain away this mystery line of code. Petzold is a great teacher and I appreciate his work; however, his explanation about an extra line of...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.