Given the hacked knowledge as described in the series (I) and (II), now it is trivial to devise an approach to programmatically get the active PMP page. The desired way of using the code is like this:
And the class is designed like this:
These two classes encapsulates the unmanaged api calls using such functions as
And using these two classes, one can enumerate all the child windows with specific caption or classes, and all the matched child window handles are archived into MatchedHandles field.
- By first enumerate all the child windows of SolidWorks Mainframe window, we can get all the windows whose title is "Dve sheet";
- Given a list of Windows handles derived from step 1, for each window handle, we check if the window has a child window whose caption is "Properties"
- If yes, this is the default PMP page generated by SolidWorks;
- Otherwise, this window should have a child window, whose type is "Button", and in addition, this button is the 1st child of the window under inspection.
- The button, if exists, has the same caption as the PMP page’s title.
A basic test shows its efficacy:
Any comments are welcome.