office 365 - detecting function wizard

46 views
Skip to first unread message

fat_tail

unread,
Aug 25, 2021, 2:42:09 PM8/25/21
to Excel-DNA
Hi - apologies in advance as this is not related to excel-dna directly. I have some code which detects when a xll function is being edited in function wizard in excel using the dreaded bosa_sdm_xl lookup. I recently started porting my addin (not excel-dna) to Office 365 and noticed that this is not working. when I debug the code the windows class names that passed are something like "OfficeGripperWnd" and "IME". anyone here know how I can use this to detect that the function is in the wizard ? Or is there a better way ?
thanks

Govert van Drimmelen

unread,
Aug 25, 2021, 3:07:37 PM8/25/21
to exce...@googlegroups.com

Interesting – are you in on a Beta channel or similar for Office 365?

What is the exact Excel version you’re seeing this in?

 

My Current Channel Excel v 16.0.14228.20216 still works with bosa_sdm_xl.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/a9b8de1b-dcc6-4910-8617-cb8bb7f5b2dfn%40googlegroups.com.

fat_tail

unread,
Aug 25, 2021, 5:44:15 PM8/25/21
to Excel-DNA
Hi not as far as I know. I am running (16.0.14228.20216) 64-bit

fat_tail

unread,
Aug 25, 2021, 5:45:34 PM8/25/21
to Excel-DNA
this is the code that i have used

static BOOL CALLBACK EnumProc(HWND hwnd, EnumStruct* enm)
{
// Check if the parent window is Excel.
// Note: Because of the change from MDI (Excel 2010)
// to SDI (Excel 2013), comment out this step in Excel 2013.
if ((DWORD)GetParent(hwnd) == enm->hwndXLMain)
{
const int CLASS_NAME_BUFFSIZE = 512;
WCHAR class_name[CLASS_NAME_BUFFSIZE + 1];
//  Ensure that class_name is always null terminated for safety.
class_name[CLASS_NAME_BUFFSIZE] = 0;
GetClassNameW(hwnd, class_name, CLASS_NAME_BUFFSIZE);
//  Do a case-insensitve comparison for the Excel dialog window
//  class name with the Excel version number truncated.
if (_wcsnicmp(class_name, L"bosa_sdm_xl", 11) == 0)
{
enm->funcwiz = true;
return FALSE; // Tells Windows to stop iterating.
}
}
return TRUE; // Tells Windows to continue iterating.
}
static BOOL isCalledByFuncWizard()
{
XLOPER12 hwndMain;
if (Excel12(xlGetHwnd, &hwndMain, 0) != xlretSuccess)
{
return FALSE;
}
EnumStruct enm = { FALSE, hwndMain.val.w };
EnumWindows((WNDENUMPROC)EnumProc, (LPARAM)((EnumStruct*)&enm));
return enm.funcwiz;
}


Govert van Drimmelen

unread,
Aug 25, 2021, 5:52:27 PM8/25/21
to exce...@googlegroups.com

This is the Excel-DNA code (in C#) that works fine for me with the same Excel version:

 

       // CONSIDER: Might this be better?

        // return !XlCall.Excel(XlCall.xlfGetTool, 4, "Standard", 1);

        // (I think not - apparently it doesn't work right under Excel 2013,

        //  but it can easily be called by the user in their helper)

        // We enumerate these by getting the (native) thread id, from any WindowHandle,

        // then enumerating non-child windows for this thread.

        public static bool IsInFunctionWizard()

        {

            // TODO: Handle the Find and Replace dialog

            //       for international versions.

            StringBuilder buffer = new StringBuilder(256);

            bool inFunctionWizard = false;

            EnumThreadWindows(_mainNativeThreadId, delegate(IntPtr hWndEnum, IntPtr param)

            {

                if (IsFunctionWizardWindow(hWndEnum, buffer))

                {

                    inFunctionWizard = true;

                    return false; // Stop enumerating

                }

                return true;      // Continue enumerating

            }, IntPtr.Zero);

            return inFunctionWizard;

        }

 

        struct FuncWizChild {

            public int ScrollBar;

            public int EDTBX;

        };

 

        static bool IsFunctionWizardWindow(IntPtr hWnd, StringBuilder buffer)

        {

            buffer.Length = 0;

            // Check the window class

            if (GetClassNameW(hWnd, buffer, buffer.Capacity) == 0)

              return false;

            if (!buffer.ToString().StartsWith("bosa_sdm_XL"))

                return false;

 

            FuncWizChild child = new FuncWizChild { ScrollBar = 0, EDTBX = 0 };

            EnumChildWindows(hWnd, delegate (IntPtr hWndEnum, IntPtr param)

            {

                buffer.Length = 0;

                if (GetClassNameW(hWndEnum, buffer, buffer.Capacity) == 0)

                    return false;

 

                string title = buffer.ToString();

                if (title.Equals("EDTBX"))

                    child.EDTBX++;

                else if (title.Equals("ScrollBar"))

                    child.ScrollBar++;

                else

                    return false;

 

                return true;

            }, IntPtr.Zero);

 

            if (child.ScrollBar == 1 && child.EDTBX == 5)

              return true;

 

            return false;

fat_tail

unread,
Aug 26, 2021, 8:55:25 AM8/26/21
to Excel-DNA
thank you - this is so bizarre. I can't figure it out at all. it's as if I am running very bizarre version of excel. I just can seem to get class name "bosa" etc.

fat_tail

unread,
Aug 26, 2021, 9:03:29 AM8/26/21
to Excel-DNA
finally figured it out - I should've read the comment in the code. Basically I removed the 
 //HWND parent = GetParent(hwnd); //if ((DWORD)parent == enm->hwndXLMain) //{

and its fine !!

thanks for your help !
Reply all
Reply to author
Forward
0 new messages