Bionicoder's Blog

Windows software development and business blog

Archive for the ‘windows development’ Category

Dynamically resize ActiveX control

Posted by bionicoder on July 9, 2009

Resize ActiveX control is like other  control resize.  After getting HWAND handle or CWnd object, you can call MoveWindow() or SetWindowPos() functions to resize and place the control in the specified size and area. It is not hard.  However resizing an hosted ActiveX control is not that easy. It requires more work to complete resize.  The issue is although MoveWindow() can place the hosted ActiveX in the expected size and area,  however it will go back to original place and size once you click it.

I found this problem in one of my projects.  I searched in Internet and found this solution provided by BitBucket.  This solution works well. Basically the idea is the size and area of the hosted ActiveX contro is controled by container not the ActiveX control.  As soon as the hosted Dialog resize, the container get the ActiveX control IOleInPlaceSite object and call OnPosRectChange() to place the control.

The drawback of above solution is obvious. It requires more code to complete resize. If you provide an ActiveX control to other developers to use, the above solution is not perfect.  The other possible solution is to implete OnPosRectChange within ActiveX control. Everytime, AcitveX control size change, it auto resize it self.  Need more research on this.

Posted in ActiveX, MFC, windows development | Tagged: , , , | 1 Comment »

IE7 Shell Window Registration in Vista

Posted by bionicoder on June 17, 2009

A Shell window is a window that has been registered by calling IShellWindows::Register or IShellWindows::RegisterPending.  Upon registration, the specified window is added to the collection of Shell windows.  The Shell windows collection includes file explorer windows and web browser windows Internet Explorer and 3rd-party web browsers.  The shell window collection can be retrieved through:

        IShellWindows *psw;
        HRESULT hr;
        hr = CoInitialize(NULL);
        if (SUCCEEDED(hr))
        {
             hr = CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_IShellWindows, (void**)&psw);

             if (SUCCEEDED(hr))
             {
                  // TODO: Use the IShellWindows instance...

                  psw->Release();
             }
         }

Before Windows Vista, all opened file explorers and Internet Explorers can be found through the above code. But this changed in Windows Vista because of UAC. The issue is when UAC is ON, sometimes the IE can not be enuermerated. This issue was also discussed in MSDN forum. Some developers thought IE can only be enumerated when UAC is OFF.

I spent a couple of hours to do some resarch and found:

  1. When UAC is ON, the IE run in Protected Mode: ON can still be enumerated through above method
  2. When UAC is ON, the IE run in Protected Mode: OFF can NOT be enumerated through above method.

This is very interesting.  I am not sure why Microsoft does not allow IE in protected off mode being enumerated when UAC is ON.  Maybe it is because of Microsoft own security consideration.  This inconsistent behavior has not been updated in Microsoft website yet.

So, in Vista (UAC on), developer needs to use two different ways to get IWebBrowser2 interface.

Posted in vista, windows development | Tagged: , , , , | 3 Comments »

What is the difference between Modal and Modeless Dialog?

Posted by bionicoder on April 3, 2009

The difference between MFC modal and model less dialog is:

A modal dialog box doesn’t allow the user to access the parent window while the dialog is open – it must be dealt with and closed before continuing. A modeless dialog can be open in the background.

Example for Model Dialog is Save, Save As Dialog in MS – Word. while it is opening you can’t do any thing in the application until you close that window. Example for Modeless Dialog is Find,Replace dialogs. You can use Find Dialog, same time you can also work in that word application.

Posted in MFC, windows development | Tagged: , | 3 Comments »