ObjectARX

Reply
Distinguished Contributor
maisoui
Posts: 131
Registered: ‎12-07-2009
Message 1 of 8 (361 Views)
Accepted Solution

How to display page setup dialog?

361 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
ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 8 (348 Views)

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
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 3 of 8 (338 Views)

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

Distinguished Contributor
maisoui
Posts: 131
Registered: ‎12-07-2009
Message 4 of 8 (331 Views)

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
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 5 of 8 (319 Views)

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
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 6 of 8 (318 Views)

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

Distinguished Contributor
maisoui
Posts: 131
Registered: ‎12-07-2009
Message 7 of 8 (308 Views)

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
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 8 of 8 (304 Views)

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community