Struct of Rects can't compile

This is a discussion on Struct of Rects can't compile within the Windows Programming forums, part of the Platform Specific Boards category; I am trying to have a structure of RECTs to hold all the labels at the top of my screen. ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    26

    Struct of Rects can't compile

    I am trying to have a structure of RECTs to hold all the labels at the top of my screen. The declarations does nto give me any errors or anything but when I try to initialize the rectangles I get errors.

    The errors I get are
    Code:
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(411) : warning C4832: token '.' is illegal after UDT 'WndProc::labels'
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(411) : error C2275: 'WndProc::labels' : illegal use of this type as an expression
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(412) : warning C4832: token '.' is illegal after UDT 'WndProc::labels'
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(412) : error C2275: 'WndProc::labels' : illegal use of this type as an expression
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(413) : warning C4832: token '.' is illegal after UDT 'WndProc::labels'
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(413) : error C2275: 'WndProc::labels' : illegal use of this type as an expression
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(414) : warning C4832: token '.' is illegal after UDT 'WndProc::labels'
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(414) : error C2275: 'WndProc::labels' : illegal use of this type as an expression
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(415) : warning C4832: token '.' is illegal after UDT 'WndProc::labels'
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(415) : error C2275: 'WndProc::labels' : illegal use of this type as an expression
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(416) : warning C4832: token '.' is illegal after UDT 'WndProc::labels'
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(416) : error C2275: 'WndProc::labels' : illegal use of this type as an expression
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(417) : warning C4832: token '.' is illegal after UDT 'WndProc::labels'
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(417) : error C2275: 'WndProc::labels' : illegal use of this type as an expression
            c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(130) : see declaration of 'WndProc::labels'
    the declaration of the structure is:
    Code:
    struct	labels{
    				RECT name; 
    				RECT height; 
    				RECT weight; 
    				RECT drug1;
    				RECT drug2; 
    				RECT drug3; 
    				RECT symptoms;
    			};
    The place where I am getting the errors is the following lines
    Code:
    SetRect( &labels.name, rect.left, rect.top, a, b);
    				SetRect( &labels.height, rect.left + a, rect.top, rect.right + (2 * a), b);
    				SetRect( &labels.weight, rect.left + (2 * a), rect.top, rect.right + (3 * a), b);
    				SetRect( &labels.drug1, rect.left + (3 * a), rect.top, rect.right + (4 * a), b);
    				SetRect( &labels.drug2, rect.left + (4 * a), rect.top, rect.right + (5 * a), b);
    				SetRect( &labels.drug3, rect.left + (5 * a), rect.top, rect.right + (6 * a), b);
    				SetRect( &labels.drug1, rect.left + (6 * a), rect.top, rect.right + (7 * a), b);
    What am I doing wrong? Everything is correct according to my knowledge and MSDN. Can anyone help me?

  2. #2
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Your understanding of how structs work is off a little. "labels" is the name of the new structure datatype you've made. You use it the same way that you would use any other datatype like say "int". You would do something like this:
    Code:
    int MyInt;
    MyInt = 10;
    So similarly you would use labels like this:
    Code:
    labels MyLabels;
    SetRect(&MyLabels.name, rect.left, rect.top, a, b);
    Don't quote me on that... ...seriously

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    26
    So I should do something like this:
    Code:
    struct	labels{RECT; RECT; RECT; RECT; RECT; RECT; RECT;};
    
    labels MyLabels(RECT name, RECT height, RECT weight, RECT drug1, RECT drug2,RECT drug3, RECT symptoms);
    but this gives me the compiler errors of
    Code:
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(323) : error C2208: 'tagRECT' : no members defined using this type
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(323) : error C2208: 'tagRECT' : no members defined using this type
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(323) : error C2208: 'tagRECT' : no members defined using this type
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(323) : error C2208: 'tagRECT' : no members defined using this type
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(323) : error C2208: 'tagRECT' : no members defined using this type
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(323) : error C2208: 'tagRECT' : no members defined using this type
    c:\documents and settings\administrator\my documents\my projects\dosage\dosage.cpp(323) : error C2208: 'tagRECT' : no members defined using this type

  4. #4
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    You defined your struct correctly. I declared MyLabels correctly. All you have to do is use it like I did in the example.
    Don't quote me on that... ...seriously

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    26
    I got it working, now onto the next problem, trying to draw them with FrameRect gives me a blank screen.

    Code:
    FrameRect(hdc, &MyLabels.name,(HBRUSH)GetStockObject(BLACK_BRUSH));
    That is one of the commands I am trying to run. All of them are basically the same except the second argument is a different pointer to each rectangle for each rectangle I am trying to draw of course.
    The background is black.

    I will supply the full main source code file. There are many different source code files so if you see a un defined function its probaly in a different file.
    Attached Files Attached Files

  6. #6
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    was IDM_NEWPARTY ever called?
    Don't quote me on that... ...seriously

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    26
    IDM_NEWPARTY is a menu item. Yes I did do that and still got a blank screen.

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    26
    I found a sorta fix. It is only drawing after I make it call a WM_SIZE message(through changing the size of the window). Is there any way I can request a WM_SIZE message? I thought about SendMessage but I don't know the height and width of the window. Also it only drew a line in the middle of the screen. It appears that maybe the rectangles are gigantic but I can not figure out why they would be so big.

    Thanks for all your help.

  9. #9
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    Are you sure you need a WM_PAINT, did you try UpdateWindow()?

    http://msdn.microsoft.com/library/de...tdraw_4zef.asp

    Maybe if you show us a little more code we can help with why you only have a line. Guessing I would say look at: your 'map mode', and check your variables to see if they actually contain legit. values. Why don't you post your WM_Paint.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  10. #10
    Registered User
    Join Date
    Apr 2007
    Posts
    26
    Well all of my code is attached in the file I posted earlier but is my WM_PAINT message.


    Code:
    	case WM_PAINT:
    		RECT	rt;
    		HFONT	hfont;
    		int		y,iOffset;
    		POINT	pt[4];
    		SIZE	size;
    		int		a,b,c;
    		TEXTMETRIC tm ;
    		RECT	user1, user2, user3, user4, user5;
    		struct	labels{
    			RECT name; 
    			RECT height; 
    			RECT weight; 
    			RECT drug1;
    			RECT drug2; 
    			RECT drug3; 
    			RECT symptoms;
    		};
    		labels MyLabels; 
    
    		InvalidateRect (hWnd, NULL, TRUE) ;
    		hdc = BeginPaint(hWnd, &ps);
    		GetClientRect (hWnd, &rect) ;
    		rect.left += GetDeviceCaps (hdc, LOGPIXELSX) / 2 ;
    		rect.top += GetDeviceCaps (hdc, LOGPIXELSY) / 2 ;
    		rect.right =- GetDeviceCaps (hdc, LOGPIXELSX) / 4 ;
    		SelectObject (hdc, CreateFontIndirect (&lf)) ;
    		SetTextColor (hdc, cf.rgbColors) ;
    		DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
    
    
    		if(PartyLoaded == 0){
    			//TODO: Add drawing code for first explanation screen
    			hfont = EzCreateFont (hdc, TEXT("Brush Script MT"), 1500, 0, EZ_ATTR_BOLD, TRUE);
    			SelectObject (hdc, GetStockObject(WHITE_BRUSH));
    			GetClientRect(hWnd, &rt);
    			Rectangle (hdc, rt.left, rt.top, rt.right, rt.bottom) ;
    			SelectObject (hdc, hfont);
    			GetTextExtentPoint32 (hdc, szAppName, lstrlen (szAppName), &size) ;
    			GetClientRect(hWnd, &rt);
    			hdcWidth=GetDeviceCaps (hdc, HORZRES) ;
    			hdcHeight=GetDeviceCaps (hdc, VERTRES) ;
    
    			BeginPath (hdc);
    			TextOut (hdc, (cxArea -size.cx) /2, (cyArea - size.cy) /7 , szAppName, lstrlen (szAppName));
    			EndPath (hdc);
    
    			SelectClipPath (hdc, RGN_COPY);
    			iOffset = (cxArea + cyArea) / 4;
    			for (y=-iOffset; y < cyArea + iOffset; y++){
    				pt[0].x=0;
    				pt[0].y=y;
    
    				pt[1].x=cxArea /3;
    				pt[1].y=y+iOffset;
    
    				pt[2].x=2*cxArea/3;
    				pt[2].y=y-iOffset;
    
    				pt[3].x=cxArea;
    				pt[3].y=y;
    
    				a=rand()%256;
    				b=rand()%256;
    				c=rand()%256;
    
    				SelectObject (hdc, CreatePen (PS_SOLID, 1, RGB (a, b, c)));
    				PolyBezier(hdc, pt, 4);
    
    				DeleteObject ( SelectObject (hdc, GetStockObject(BLACK_PEN)));
    			}
    			SelectObject(hdc, GetStockObject(SYSTEM_FONT));
    			SelectObject(hdc, EzCreateFont (hdc, TEXT("Times New Roman"), 150, 0, EZ_ATTR_BOLD, TRUE));
    			rect.top=rect.bottom+20;
    			rect.bottom=rect.top+150;
    
    			DeleteObject (hfont);
    		}
    
    
    		else if(PartyLoaded==1){
    			//TODO: Add drawing code for drawing of the party information 
    
    
    			GetClientRect (hWnd, &rect) ;
    			GetTextMetrics (hdc, &tm) ;
    			a=0;
    			y=0;
    			if(iPartyMemb==0){
    				MessageBox(hWnd, TEXT("Party is loaded but with no members"), TEXT("Party is loaded with no members"),MB_OK);
    			}
    			SelectObject(hdc, GetStockObject(SYSTEM_FONT));
    			SelectObject(hdc, GetStockObject(WHITE_BRUSH));
    			SelectObject(hdc, GetStockObject(BLACK_PEN));
    			a=cxArea/7;
    			b=tm.tmHeight;
    
    			SetRect( &MyLabels.name, rect.left, rect.top, a, rect.top + b);
    			SetRect( &MyLabels.height, rect.left + a, rect.top, rect.right + (2 * a), b);
    			SetRect( &MyLabels.weight, rect.left + (2 * a), rect.top, rect.right + (3 * a), b);
    			SetRect( &MyLabels.drug1, rect.left + (3 * a), rect.top, rect.right + (4 * a), b);
    			SetRect( &MyLabels.drug2, rect.left + (4 * a), rect.top, rect.right + (5 * a), b);
    			SetRect( &MyLabels.drug3, rect.left + (5 * a), rect.top, rect.right + (6 * a), b);
    			SetRect( &MyLabels.symptoms, rect.left + (6 * a), rect.top, rect.right + (7 * a), b);
    
    			FrameRect(hdc, &MyLabels.name,(HBRUSH)GetStockObject(BLACK_BRUSH));
    			FrameRect(hdc, &MyLabels.height,(HBRUSH)GetStockObject(BLACK_BRUSH));
    			FrameRect(hdc, &MyLabels.weight,(HBRUSH)GetStockObject(BLACK_BRUSH));
    			FrameRect(hdc, &MyLabels.drug1,(HBRUSH)GetStockObject(BLACK_BRUSH));
    			FrameRect(hdc, &MyLabels.drug2,(HBRUSH)GetStockObject(BLACK_BRUSH));
    			FrameRect(hdc, &MyLabels.drug3,(HBRUSH)GetStockObject(BLACK_BRUSH));
    			FrameRect(hdc, &MyLabels.symptoms,(HBRUSH)GetStockObject(BLACK_BRUSH));
    
    			while(y<iPartyMemb){
    				if(y==0){
    					a=0;
    				}
    				else{
    					a=cyArea/y;
    				}
    				Rectangle(hdc,rect.left,rect.top+a,rect.right,rect.bottom+a);
    				y++;
    			}
    		}
    		else{
    			//TODO: Add code to deal with error
    			MessageBox(hWnd, TEXT("PartyLoaded is a number other then One or Zero"), TEXT("PartyLoaded is a number other then One or Zero"), IDOK);
    		}		
    		EndPaint(hWnd, &ps);
    		break;
    All of the Variables are getting the correct values as far as I can tell through the debugger.

    My mapping mode is still the default. I think that is MM_TEXT. Thanks for any and all help.

  11. #11
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    Sorry, didn't see the attachment.

    I still don't think you need to send an WM_SIZE. I think you need a WM_PAINT the reason a WM_SIZE works it because it falls through to the WM_PAINT.

    Anyway
    Code:
    SendMessage (hwnd, WM_SIZE, 0, 0);
    or

    Code:
    SendMessage (hwnd, WM_PAINT, 0, 0);
    Although, I still think the answer is in: InvalidateWindow and UpdateWindow.

    Code:
    InvalidateRect(hwnd, NULL, true);
    UpdateWindow(hwnd);
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 03:16 AM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  3. Concatenating in linked list
    By drater in forum C Programming
    Replies: 12
    Last Post: 05-03-2008, 12:10 AM
  4. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 03:56 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM

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