ObjectARX

ObjectARX

Reply
Mentor
158 Posts
10 Kudos
Registered: ‎12-07-2009
Post 1 of 8
Accepted Solution

How to display page setup dialog?

374 Views, 7 Replies
02-11-2013 04:59 AM

Hi,

 

I'd like to launch the page setup dialog to directly modify properties for a particlar download. I tried the following code:

 

((AcApLayoutManager *)acdbHostApplicationServices()->layoutManager())->pageSetup(...);

It launches the dialog "Page Setup Manager" and it is necessary to click on button "Modify" to show page setup dialog. How to get rid of this click and directly show the second dialog?

 

Regards,

Jonathan

 

--
Jonathan

Another hook-function. Does not depend on the localization AutoCADTake it "as is", without any guarantees. :-)

// AutoCAD 2008...2013 has identical IDMODIFY number
#define IDMODIFY (4705)
HHOOK hMsgBoxHook = NULL;
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
HWND hwnd;
HWND hwndButton;
if(nCode < 0)
return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
switch(nCode)
{
case HCBT_CREATEWND:
{
// Get handle to the message box!
hwnd = (HWND)wParam;
break;
}
case HCBT_ACTIVATE:
{
// Get handle to the message box!
hwnd = (HWND)wParam;
hwndButton = GetDlgItem(hwnd, IDMODIFY);
if (hwndButton != NULL) {
::UnhookWindowsHookEx(hMsgBoxHook); hMsgBoxHook = NULL;
::SendMessage(hwndButton,WM_LBUTTONDOWN,0,0);
::SendMessage(hwndButton,WM_LBUTTONUP,0,0);
}
}
}
return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
}

 

 

ADN Support Specialist
352 Posts
27 Kudos
Registered: ‎07-24-2007
Post 2 of 8

Re: How to display page setup dialog?

02-11-2013 05:44 PM in reply to: maisoui

I don't think it's possible - Isn't it just a case of using acedCommand() with the PLOT command?





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Moderator
1,464 Posts
277 Kudos
Registered: ‎04-09-2008
Post 3 of 8

Re: How to display page setup dialog?

02-11-2013 10:40 PM in reply to: maisoui

It is look like possible only with Windows hook.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Mentor
158 Posts
10 Kudos
Registered: ‎12-07-2009
Post 4 of 8

Re: How to display page setup dialog?

02-12-2013 01:05 AM in reply to: Alexander.Rivilis

Thank you for your answer. I don't understand how to use such a hook. Your idea is to manually simulate click on Modify button?

--
Jonathan
Moderator
1,464 Posts
277 Kudos
Registered: ‎04-09-2008
Post 5 of 8

Re: How to display page setup dialog?

02-12-2013 03:17 AM in reply to: maisoui

Yes. Simple sample without any error checking and adopted for English and Russian localization of AutoCAD:

HHOOK hMsgBoxHook = NULL;
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    HWND hwnd;
    HWND hwndButton;
    if(nCode < 0)
        return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
    switch(nCode)
    {
    case HCBT_CREATEWND:
        {
            // Get handle to the message box!
            hwnd = (HWND)wParam;
            break;
        }
    case HCBT_ACTIVATE:
        {
            // Get handle to the message box!
            hwnd = (HWND)wParam;
            HWND hwndfirst = GetNextDlgTabItem(hwnd,NULL,FALSE);
            hwndButton = hwndfirst;
            do {
                CWnd *w = CWnd::FromHandle(hwndButton);
                CString name;
                if (w && w->IsKindOf(RUNTIME_CLASS(CButton))) {
                    w->GetWindowText(name);
                    // Name of button can be localized
                    if (name == _T("&Modify...") || name == _T("&Редактировать...")) {
                        UnhookWindowsHookEx(hMsgBoxHook); hMsgBoxHook = NULL;
                        w->SendMessage(WM_LBUTTONDOWN,0,0);
                        w->SendMessage(WM_LBUTTONUP,0,0);
                        break;
                    }
                }
            } while ((hwndButton = GetNextDlgTabItem(hwnd,hwndButton,FALSE)) != NULL && hwndButton != hwndfirst);
        }
    }
    return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
}


static void ArxPageSetup(void)
{
    AcApLayoutManager *pLayMan = reinterpret_cast<AcApLayoutManager *>(acdbHostApplicationServices()->layoutManager());
    AcDbObjectId idlay = pLayMan->getActiveLayoutBTRId();
    hMsgBoxHook = ::SetWindowsHookEx(WH_CBT,CBTProc,NULL,GetCurrentThreadId());
    pLayMan->pageSetup(idlay,NULL,TRUE);
    if (hMsgBoxHook != NULL) UnhookWindowsHookEx(hMsgBoxHook);
}

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Moderator
1,464 Posts
277 Kudos
Registered: ‎04-09-2008
Post 6 of 8

Re: How to display page setup dialog?

02-12-2013 03:37 AM in reply to: Alexander.Rivilis

Another hook-function. Does not depend on the localization AutoCADTake it "as is", without any guarantees. :-)

// AutoCAD 2008...2013 has identical IDMODIFY number
#define IDMODIFY (4705)

HHOOK hMsgBoxHook = NULL;
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    HWND hwnd;
    HWND hwndButton;
    if(nCode < 0)
        return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
    switch(nCode)
    {
    case HCBT_CREATEWND:
        {
            // Get handle to the message box!
            hwnd = (HWND)wParam;
            break;
        }
    case HCBT_ACTIVATE:
        {
            // Get handle to the message box!
            hwnd = (HWND)wParam;
            hwndButton = GetDlgItem(hwnd, IDMODIFY);
            if (hwndButton != NULL) {
                ::UnhookWindowsHookEx(hMsgBoxHook); hMsgBoxHook = NULL;
                ::SendMessage(hwndButton,WM_LBUTTONDOWN,0,0);
                ::SendMessage(hwndButton,WM_LBUTTONUP,0,0);
            }
        }
    }
    return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
}

 

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Mentor
158 Posts
10 Kudos
Registered: ‎12-07-2009
Post 7 of 8

Re: How to display page setup dialog?

02-12-2013 04:49 AM in reply to: Alexander.Rivilis

Your solution works like a charm. But I don't know if I will implement it in release version of my software, because it's not the most proper code. :smileyhappy:

 

Regards,

Jonathan

 

--
Jonathan
Moderator
1,464 Posts
277 Kudos
Registered: ‎04-09-2008
Post 8 of 8

Re: How to display page setup dialog?

02-12-2013 04:57 AM in reply to: maisoui

maisoui wrote:

Your solution works like a charm. But I don't know if I will implement it in release version of my software, because it's not the most proper code. :smileyhappy:

 

Regards,

Jonathan

 


... but look like there is no another solution (not using hooks)...


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post