Thread: Polygon 2

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    Polygon 2

    It compiles but it wont executes, it goes in debug mode VC++ 2008.
    I dont understand whats wrong.
    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         static TCHAR szAppName[] = TEXT ("AltWind") ;
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASS     wndclass ;
         
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;
         
         hwnd = CreateWindow (szAppName, TEXT ("Alternate and Winding Fill Modes"),
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              NULL, NULL, hInstance, NULL) ;
         
         ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         static int   cxClient, cyClient ;
         HDC          hdc ;
         PAINTSTRUCT  ps ;
         static POINT        points [7] = { {20,50}, {180,50}, {180,20}, {230,70}, {180,120}, {180,90}, {20,90} } ;
         
         switch (message)
         {
         case WM_SIZE:
              cxClient = LOWORD (lParam) ;
              cyClient = HIWORD (lParam) ;
              return 0 ;
    
         case WM_PAINT:
              hdc = BeginPaint (hwnd, &ps) ;
    
              SelectObject (hdc, GetStockObject (GRAY_BRUSH)) ;
              Polygon(hdc, points, 7) ;
              
              EndPaint (hwnd, &ps) ;
              return 0 ;
              
         case WM_DESTROY:
              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    Last edited by Ducky; 09-02-2008 at 02:22 AM.
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Before you CreateWindow you need to RegisterClass. You should also check the return value of CreateWindow to make sure the window is valid.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Thanks, i added RegisterClass but still the same.
    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         static TCHAR szAppName[] = TEXT ("AltWind") ;
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASS     wndclass ;
         
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;
         
    	 if (!RegisterClass (&wndclass))
         {
              MessageBox (NULL, TEXT ("Program requires Windows NT!"), 
                          szAppName, MB_ICONERROR) ;
              return 0 ;
         }
         
         hwnd = CreateWindow (szAppName, TEXT ("Polygon"),
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              NULL, NULL, hInstance, NULL) ;
         
         ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         static int   cxClient, cyClient ;
         HDC          hdc ;
         PAINTSTRUCT  ps ;
    	 static POINT        points [7] = { {20,50}, {180,50}, {180,20}, {230,70}, {180,120}, {180,90}, {20,90} } ;
         
         switch (message)
         {
         case WM_SIZE:
              cxClient = LOWORD (lParam) ;
              cyClient = HIWORD (lParam) ;
              return 0 ;
    
         case WM_PAINT:
              hdc = BeginPaint (hwnd, &ps) ;
    
    		  SelectObject (hdc, GetStockObject (GRAY_BRUSH)) ;
    		  Polygon(hdc, points, 7) ;
              
              EndPaint (hwnd, &ps) ;
              return 0 ;
              
         case WM_DESTROY:
              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    Last edited by Ducky; 09-02-2008 at 10:22 AM.
    Using Windows 10 with Code Blocks and MingW.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    I don't know what to tell you then. I used the exact code as above, in Visual Studio 2008 and it runs.

    Does anything display for you? Are you getting the error message if RegisterClass fails? Are you checking the window handle after CreateWindow?

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Thanks, thats all i needed to know. If it runs for you i got a bug in my system.

    No error message whatsoever btw.
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polygon
    By Ducky in forum Windows Programming
    Replies: 7
    Last Post: 09-01-2008, 05:53 AM
  2. Point in polygon test - spherical coords
    By bhdz in forum C Programming
    Replies: 1
    Last Post: 11-07-2007, 01:25 PM
  3. help how to make polygon
    By gamett711221 in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2005, 08:33 PM
  4. my polygon class
    By ichijoji in forum Game Programming
    Replies: 5
    Last Post: 08-02-2004, 08:42 AM
  5. IDEA: Polygon unions and intersections
    By Magos in forum Contests Board
    Replies: 3
    Last Post: 05-21-2003, 07:16 PM