Visual 2008 proffesional acting up??

This is a discussion on Visual 2008 proffesional acting up?? within the C++ Programming forums, part of the General Programming Boards category; Hello I dont know why my Microsoft visual 2008 gives me errors in code that has no errors, code given ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    8

    Visual 2008 proffesional acting up??

    Hello

    I dont know why my Microsoft visual 2008 gives me errors in code that has no errors, code given by my professor that he tested, various codes from website that should work is giving me errors from visual.


    such code like this , is a windows program
    Code:
    #include <windows.h>
    
    const wchar_t g_szClassName[] = L"myWindowClass";
    
    // You can write your own graphic functions 
    void twoColorLine(HDC & hDC,int x1,int y1,int x2,int y2,int red1,int green1,int blue1,int red2,int green2,int blue2)
    {
    	HPEN	hPen1,hPen2;
    	
    	// Find the midpoint
    	int mx=(x1+x2)/2;
    	int my=(y1+y2)/2;
    
    	//draw the first half
    	hPen1 = CreatePen(PS_SOLID, 3, RGB(red1,green1,blue1));
        SelectObject(hDC, hPen1);
    	MoveToEx(hDC, x1,y1,0);
    	LineTo(hDC, mx,my);
    	DeleteObject( hPen1 );
    
    	//draw the second half
    	hPen2 = CreatePen(PS_SOLID, 3, RGB(red2,green2,blue2));
        SelectObject(hDC, hPen2);
    	MoveToEx(hDC, mx,my,0);
    	LineTo(hDC, x2,y2);
    	DeleteObject( hPen2 );
    }
    
    // Recursively define a circle as being made of a circle and 4 more recursive circles
    // Have fun with this!
    void rCircle(HDC & hDC,int x,int y,int r,int red1,int green1,int blue1)
    {
    	HPEN	hPen1;
    	int x1=x-r;
    	int y1=y-r;
    	int x2=x+r;
    	int y2=y+r;
    	int thickness=r/5;
    	if(thickness<1)thickness=1;
    	hPen1 = CreatePen(PS_SOLID,thickness, RGB(red1,green1,blue1));
        SelectObject(hDC, hPen1);
    	Ellipse(hDC,x1,y1,x2,y2);
    	DeleteObject( hPen1 );
    
    	// if the radius is less than 2 pixels we dont recurse (base case)
    	if(r>2)
    	{
    		int nux,nuy,nur,nuRed,nuGreen,nuBlue;
    		nuy=r-y/2;		// there's a bug on this line, but serendipity is the mother of art 
    		//nuy=y-r/2;	// this is the corrected line 
    		nux=x;
    		nur=r/2;
    		nuRed=(red1*9)/10;
    		nuGreen=(green1*9)/10;
    		nuBlue=(blue1*9)/10;
    		rCircle(hDC,nux,nuy,nur,nuRed,nuGreen,nuBlue);
    		nuy=y+r/2;
    		rCircle(hDC,nux,nuy,nur,nuRed,nuGreen,nuBlue);
    		nuy=y;
    		nux=x-r/2;
    		rCircle(hDC,nux,nuy,nur,nuRed,nuGreen,nuBlue);
    		nux=x+r/2;
    		rCircle(hDC,nux,nuy,nur,nuRed,nuGreen,nuBlue);
    	}
    }
    
    // The Callback function is where the logic of a Windows program resides.
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	HDC hDC;
    	PAINTSTRUCT Ps;
    	HPEN hPen;
    	HBRUSH hBrush;
    	HFONT hFont;
    	RECT rect;
    	int fHeight=25;
    
    	int red=120;
    	int green=200;
    	int blue =255;
    
    	// static variables can be used to save the state of your window
    	static bool is_a_rectangle=false;
        switch(msg)
        {
    		case WM_PAINT:
    			// all "drawing" is done here
    			hDC=BeginPaint(hwnd,&Ps);
    			// pens draw lines
    			hPen=CreatePen(PS_SOLID,10,RGB(20,20,200));
    
    			SelectObject(hDC,hPen);
    
    			if(is_a_rectangle)
    			{
    				Rectangle(hDC,100,100,300,200);
    			}
    			else
    			{
    				Ellipse(hDC,100,100,300,200);
    			}
    
    			DeleteObject(hPen);
    
    			// brushes draw areas
    			hBrush=CreateSolidBrush(RGB(230,45,67));
    			
    			rect.bottom=320;
    			rect.top=120;
    			rect.right=100;
    			rect.left=300;
    
    			FillRect(hDC,&rect,hBrush);
    
    			DeleteObject(hBrush);
    
    			// fonts draw words
    			hFont=CreateFont(fHeight,0,0,0,0,TRUE,0,0,0,0,0,0,0,L"Times New Roman");
    
    			SelectObject(hDC,hFont);
    
    			rect.bottom=555;
    			rect.top=480;
    			rect.right=625;
    			rect.left=65;
    
    			DrawText(hDC,L"(c)Copyright 2008, Dr. Thomas Fernandez\n           All rights reserved.",-1,&rect,DT_WORDBREAK);
    
    			DeleteObject(hFont);
    
    			//call your own functions
    			twoColorLine(hDC,95,75,200,350,50,50,50,205,205,205);
    
    			//Uncomment the following block for a fractal drawing.
    			/*
    			hBrush = CreateSolidBrush(RGB(red,green,blue)); 
    			SelectObject(hDC, hBrush);
    			rCircle(hDC,233,230,210,25,25,250);
    			rCircle(hDC,233,230,140,250,25,250);
    			DeleteObject(hBrush);
    			*/
    
    			EndPaint(hwnd,&Ps);
    			break;
    		case WM_CHAR:
    			if(wParam=='r')
    			{
    				is_a_rectangle=true;
    			}
    			else if(wParam=='e')
    			{
    				is_a_rectangle=false;
    			}
    			// this line forces the window to be redrawn
    			InvalidateRect(hwnd,NULL,true);
    		break;
            case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    You need WinMain().

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    8
    Quote Originally Posted by robwhit View Post
    You need WinMain().

    where would that go??

    sry im a noob

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    It goes wherever you want it to go. (In other words, this is only half the program -- you need the other half too.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21