Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Modal and Modeless dialog


Recommended Posts

Hello, all.

 

Using VS C++ 2008 and X5.

 

It was a good timing after I learned "Shapes", I had a chance to make a real *.dll at work.

So, I made a small C-hook program based on the sample program "Shapes", and "modeless" dialog sample

program generated by C-hook Wizard.

 

What it does is to create the midpoint between 2 points, any existing points such as endpoints,

center points, etc., selected by mouse on screen.

 

I used functions "get_point", "make_center", "make_line" and "compute_axis_vectors" from

"Shapes", and made 6 edit controls as readouts (that's why I need the dialog to be displayed

while operation is on), for the first, second and midpoint of X & Y coordinate.

 

Also put a check box for "make a line" as an option if a user wants to see a line connected

two points selected by mouse.

Compile/link were successful, and made "create_midpoint.dll."

 

When executed, the dialog is displayed and "get_point" asks the first point, and the second point,

then makes a midpoint finally. Check box on/off works, too.

It works as I expected.

 

However, when I press OK button in the dialog, the dialog is gone, but "get_point" still keeps

asking the first point. It even works without the dialog.

If I hit "ESC" key, then "get_point" is gone. (Yes, I understand it is made that way.)

 

In other words, if I press ESC key twice, both "get_point" and the dialog will be gone.

Seems I don't need OK and CANCEL button in the dialog...

 

Two questions.

(1) Is there any way to finish both the dialog and "get_point" function at the same time?

(If one of two is gone, then the other should also be gone, doesn't matter which one is first.)

Maybe, I can put some routine near "TODO", but I don't know how to do it.

 

-->This code snippet is from sample program Modeless dialog / Tracking mouse

	// Okay button command
		else if (event.m_type == EM_Command && event.m_command == IDOK)
			{
			// TODO: OnOk handling
			done = true;
			}

		// Cancel button command
		else if (event.m_type == EM_Command && event.m_command == IDCANCEL)
			{
			// TODO: OnCancel handling
			done = true;
			}

 

(2) For X, Y coordinate readout, can I set the format? All I need is 5 places after decimal.

Right now, number is too long.

 

-->from MyModelessDialog.h

enum { IDD = IDD_MyModelessDialog };
double	m_p1_x;
double	m_p1_y;
double	m_p2_x;
double	m_p2_y;
double	m_mdp_x;
double	m_mdp_y;
BOOL	m_make_line;


-->from MyModelessDialog.cpp

DDX_Text(pDX, IDC_P1_X, m_p1_x);
DDX_Text(pDX, IDC_P1_Y, m_p1_y);
DDX_Text(pDX, IDC_P2_X, m_p2_x);
DDX_Text(pDX, IDC_P2_Y, m_p2_y);
DDX_Text(pDX, IDC_MDP_X, m_mdp_x);
DDX_Text(pDX, IDC_MDP_Y, m_mdp_y);
DDX_Check(pDX, IDC_MAKE_LINE, m_make_line);

 

Any advice will be appreciated.

 

Thank you.

Link to comment
Share on other sites
(1) Is there any ways to finish both the dialog and "get_point" function at the same time?

I assume that “get_point" refers to the “point_proc” function?

All I can guess from your description is that you are calling it from inside

of a loop and have hidden the dialog without ending the loop.

*This is just a wild guess!

 

 

 

(2) For X, Y coordinate readout, can I set the format? All I need is 5 places after decimal.

You are using just “plain” Windows textboxes. They are not “smart” controls.

For Integer and Decimal point numbers you probably want to use some of Mastercam’s special functionality here -> McInt and McReal along with their associated DataExchange functions ->

 

The best way to see these in action is to take a close look at ModelesssDialog (or Modal) sample CHook projects that the CHookWizard can create for you.

 

Note in the DoDataExchange function in the .cpp file of the Dialog ->

 

DDX_ProcessEditReal(pDX, IDC_W_EDIT, m_w_edit);

DDX_ProcessEditReal(pDX, IDC_H_EDIT, m_h_edit);

 

IDC_W_EDIT is still an EDITTEXT in (the .rc file) definition of the dialog,

but we are using the special functionality of DDX_ProcessEditReal which associates to a McReal (m_w_edit) variable.

(m_w_edit is not just a variable, but really a McReal Class).

*See the Dialog Class constructor where these McReal are initialized.

You can set the default value, the min/max allowed values and more.

These also give you the calculator functionality

and the right-mouse click “Select something on the screen to get a value” functionality. ;)

 

There is also a DDX_ProcessEditInt and more…

*These are all defined in the MCEDIT_ch.h file.

Link to comment
Share on other sites

Roger,

 

Hello.

 

As for "MCReal", I think you meant was this, right?

 

CMyModelessDialog::CMyModelessDialog(CWnd* pParent /*=NULL*/)
: MCDialog(CMyModelessDialog::IDD, pParent)

  //,m_p1_x (0.0, 0.0, MAXREAL, -1) --> @param[in] nDec Number of decimal places, -1 = use system default / from "MCREAL_CH.H"
   or--> //,m_p1_x (1.0, 0.0, MAXREAL, 5)
   or--> ,m_p1_x (1.0, MINREAL, MAXREAL, FALSE, FALSE, 5)
         ,m_p1_y (1.0, MINREAL, MAXREAL, FALSE, FALSE, 5)
  ,m_p2_x (2.0, MINREAL, MAXREAL, FALSE, FALSE, 5)
  ,m_p2_y (2.0, MINREAL, MAXREAL, FALSE, FALSE, 5)
  ,m_mdp_x (3.0, MINREAL, MAXREAL, FALSE, FALSE, 5)
  ,m_mdp_y (3.0, MINREAL, MAXREAL, FALSE, FALSE, 5)

  ,m_make_line (FALSE)
{
//{{AFX_DATA_INIT(CMyModelessDialog)

	m_p1_x.modeless = TRUE;
m_p1_y.modeless = TRUE;
m_p2_x.modeless = TRUE; 
m_p2_y.modeless = TRUE;
m_mdp_x.modeless = TRUE; 
m_mdp_y.modeless = TRUE; 

// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}

 

Now, displayed number is much shorter than before, but it still shows 6 places after decimal point

even though I put 5 for "nDec".

I have to look at my program again. Maybe, read/write PRM file is doing something...?

 

 

(1) Is there any ways to finish both the dialog and "get_point" function at the same time?

 

      // Data members
00076 public:
00083      BOOL   modeless;              ///< Is parent window modeless

 

When I was checking "MCREAL_CH.H", I found this.

For a try out, put "m_p1_x.modeless = TRUE;" and applied the same for the rest of valuables.

I was not sure this was OK or not..., but it worked.

Press ESC key once, not twice, will get me out of this C-hook program.

 

I still need to add a routine to get out "get_point" mode when "OK" and "CANCEL" button were pressed.

Well, it's little better than last week.

 

Thank you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...