Home > Software engineering >  Use MFC to write a small program, a great god, please have a look
Use MFC to write a small program, a great god, please have a look

Time:09-19

Use MFC to write a simple small program, when clicking on a button, the button will randomly change the location, and then click again to change the position, after the completion of the write also can realize the function, is the point several times in a row, sometimes found among several times he did not change the position, also don't know why, the trouble great god to Chou Chou,

Void CMFCFunnyDlg: : OnBnClicked ()
{
//TODO: add the control notification handler code


Srand ((int) time (0));
Int x=rand () % 400;
Int y=rand () % 200;
GetDlgItem (IDCANCEL) - & gt; SetWindowPos (NULL, x, y, 0, 0,
SWP_NOZORDER | SWP_NOSIZE);

//CDialogEx: : OnCancel ();
}
Insert a few times a breakpoint, nor because of two random Numbers produced by the same cause,,,,

CodePudding user response:

Novice,
Just a guess,
May need to obtain first dialog high and wide, before moving to judge whether will exceed the dialog,

CodePudding user response:

Covered by other controls?

CodePudding user response:

Sure is a random number is not the same? One random number print display
  • Related