Monday, January 3, 2011

Get list of all open windows using X++ Code

static void xppGetAllWindowsOpen(Args _args)
{       
        hWnd Parent;
        hWnd handle;

        hWnd mdi;
        #WinApi

        dialog d = new Dialog();
        DialogTabPage dt;

        str text;
        ;

        d.caption("All the windows");
        d.windowType(FormWindowType::PopUp);

        Parent = infolog.hWnd();
        mdi = WinApi::getWindow(Parent, #GW_CHILD);

        handle = WinApi::getWindow(mdi, #GW_CHILD);
        text = WinApi::getWindowText(handle);

        if(text)        
       {               
                dt = d.addTabPage(text);
                d.addText(text);
        }
        if(handle)       
       {               
                  while(handle)               
                  {                       
                        handle = WinApi::getWindow(handle, #GW_HWNDNEXT);
                        text = WinApi::getWindowText(handle);

                        if(text)                       
                       {                               
                                dt = d.addTabPage(text);
                                d.addText(text);
                        }               
               }
        }
        d.run();
}

1 comment:

  1. Nice,just what i was looking for!

    ReplyDelete