Generated by MFC single document template, in the view window draw some squares
1. The whole Draw_Rectangle function didn't assignment operators, why variable m_Width and m_Height becomes zero?
2. The drawing of the lattice graphics, such as how to stretches as the window than column change?
Thank you very much!
The code is as follows:
Add variables to the View class
Public: //than column factor Double m_Factor; //width Int m_Width; //height Int m_Height; Cx, void Draw_Rectangle (CDC * pDC, int int Cy, int m_Width2, int m_Height2); Ontouch function, assignment
Void CExampleView: : ontouch * pDC (CDC) { CExampleDoc * pDoc=GetDocument (); ASSERT_VALID (pDoc); if (! PDoc) return; //TODO: here is the machine data add rendering code CRect m_Rect; GetClientRect (m_Rect); Double m_ViewHeight=m_Rect. Bottom - m_Rect. Top; M_Factor=m_ViewHeight/120000; M_Width=(int) (m_Width * m_Factor); M_Height=(int) (m_Height * m_Factor); Int Center_X=(int) (m_ViewHeight/2); Int Center_Y=(int) (m_ViewHeight/2); Draw_Rectangle (pDC, Center_X Center_Y m_Width, m_Height); } Function:
Void CExampleView: : Draw_Rectangle (CDC * pDC, Cx, int int Cy, int m_Width2, int m_Height2) { Int LeftTop_X LeftTop_Y; For (int I=2; I & lt; 2; I++) { For (int j=3; J<3; J++) { LeftTop_X=Cx + I * m_Width2; LeftTop_Y=Cy + j * m_Height2; PDC - & gt; A Rectangle (LeftTop_X LeftTop_Y, LeftTop_X + m_Width2, LeftTop_Y + m_Height2); } } Cstrings STR. STR. The Format (L "% d, % d", m_Width2, m_Height2); MessageBox (STR, L "m_Width and m_Height"); } CodePudding user response:
Estimation is m_Factor force caused by integer
Why want to divided by 120000, it's too big
CodePudding user response:
To set breakpoints single-step debugging
CodePudding user response:
//width
Int m_Width;
//height
Int m_Height;
Uninitialized?
CodePudding user response:
Don't like the assignment
CodePudding user response:
Thank you for your attention!
Int m_Width and int m_Height; All initialization, in the constructor for the member variable assignment.
CExampleView: : CExampleView () : m_Factor (0) , m_Width (0) , m_Height (0) { //TODO: add construction code here M_Height=7000; M_Width=5500; } CodePudding user response:
reference 1st floor yeah2000 response: estimation is m_Factor force caused by integer Why want to divided by 120000, it's too big. Certainly not compulsory integer, divided by 120000, with a breakpoint debugging, can see, the m_Height=45 m_Width =35? With the two values in the client area draw rectangle is not small Thank you, haven't solve, bother everybody to help! CodePudding user response:
The presence of a variable is not much, you search, all add breakpoint debugging, see what has changed CodePudding user response:
M_Width=(int) (m_Width * m_Factor); 7000 * 120000=840000000; Not in the int CodePudding user response:
The rectangle is no picture in the window? CodePudding user response:
Normal, I debug, data is not shown, CodePudding user response:
Thank you As Iberia said, on both a breakpoint debugging and how to use monitoring, is no image display, Graphics is in the client area, just don't know how the m_Width and value in the operation of the m_Height suddenly became a 0 In addition, m_Factor is a scaling factor between 0 ~ 1, m_Width=(int) (m_Width * m_Factor) must be within the scope of the int Now I think of some way to avoid the hole, but still can't figure why is this so, welcome to discuss! CodePudding user response:
GetClientRect (& amp; M_Rect); CodePudding user response:
No problem! Void CExampleView: : Draw_Rectangle (CDC * pDC, Cx, int int Cy, int m_Width2, int m_Height2) { Int LeftTop_X LeftTop_Y; For (int I=2; I & lt; 2; I++) { For (int j=3; J<3; J++) { LeftTop_X=Cx + I * m_Width2; LeftTop_Y=Cy + j * m_Height2; PDC - & gt; A Rectangle (LeftTop_X LeftTop_Y, LeftTop_X + m_Width2, LeftTop_Y + m_Height2); } } Cstrings STR. STR. The Format (" % d, % d=m_Width=m_Height \ n ", m_Width2, m_Height2); AfxDump & lt; } Debugging code: AfxDump & lt; The MessageBox (STR, L "m_Width and m_Height"); Cover your picture! CodePudding user response:
Find the problem! Void CExampleView: : ontouch * pDC (CDC) { CExampleDoc * pDoc=GetDocument (); ASSERT_VALID (pDoc); //TODO: add the draw code for native data here if (! PDoc) return; //TODO: here is the machine data add rendering code CRect m_Rect; GetClientRect (m_Rect); Double m_ViewHeight=m_Rect. Bottom - m_Rect. Top; M_Factor=m_ViewHeight/120000; //m_Height=7000; //m_Width=5500; # define WIN_HEIGHT 7000 # define WIN_WIDTH 5500 M_Width=(int) (WIN_WIDTH * m_Factor);//not m_Width * M_Height=(int) (WIN_HEIGHT * m_Factor);//not m_Height * //otherwise second redraw m_Height=0. Int Center_X=(int) (m_ViewHeight/2); Int Center_Y=(int) (m_ViewHeight/2); Draw_Rectangle (pDC, Center_X Center_Y m_Width, m_Height); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull