Posts tagged ‘Subclassing’

Mobile Development – subclassing the Camera View (CameraCaptureDialog, SHCameraCapture)

If you are running a kiosk mode app but need to provide the camercapture dialog on Windows Mobile 5 or later, you may need to disable the one or other click in the CameraCapture dialog.

This article uses a technique known as subclassing as already used and decribed in my StartButtonHookWM65 article. For the CameraCapture dialog the code has been revised and you can now subclass any known window class and disable clicks within the Windows Mobile menu bar.

        private string _winClassName = "HHTaskbar";
        public string winClassName
        {
            get { return _winClassName; }
            set {
                if (this.oldWndProc == IntPtr.Zero) //only allow change before subclassing
                    _winClassName = value;
            }
        }
...
        /// <summary>
        /// SubClassing: Install the wndproc hook
        /// </summary>
        /// <returns></returns>
        private bool hookWindow()
        {
            //find the window to hook
            IntPtr hWndHooked = FindWindow(_winClassName, IntPtr.Zero);
            if (hWndHooked == IntPtr.Zero)
                return false;
            //enable the taskbar, not realy necessary
            EnableWindow(hWndHooked, true);
            //already installed?
            if (oldWndProc == IntPtr.Zero)
            {
                //find the menu_worker window
                IntPtr hwndMenu_Worker = FindWindow("menu_worker", IntPtr.Zero);
                if (hwndMenu_Worker != IntPtr.Zero)
                {
                    //get the child window which has the buttons on it
                    IntPtr hwndToolbar = GetWindow(hwndMenu_Worker, GetWindow_Cmd.GW_CHILD);
                    if (hwndToolbar != IntPtr.Zero)
                    {
                        _mHwnd = hwndToolbar;       //store to remember
                        SubclassHWnd(hwndToolbar);  //subclass the wndproc
                    }
                }
            }
            return true;
        }

As the call to CameraCaptureDialog will block and you can not subclass it before it is launched, I use a timer that will subclass the dialog assuming it will show after the call to .ShowDialog().

        private System.Windows.Forms.Timer timer;
        hwndutils subClassUtils;
        private void ShowCamera()
        {
            CameraCaptureDialog cdlg = new CameraCaptureDialog();
            cdlg.DefaultFileName="picture.jpg";
            cdlg.InitialDirectory = "\\My Documents";
            cdlg.Mode = CameraCaptureMode.Still;
            cdlg.Owner = this.pictureBox1;
            cdlg.StillQuality = CameraCaptureStillQuality.High;
            cdlg.Title = "Take a picture and Select";
            cdlg.Resolution = new Size(240, 320);
            cdlg.VideoTypes = CameraCaptureVideoTypes.All;

            //subclass main window with delay
            subClassUtils = new hwndutils();
            timer = new Timer();
            timer.Interval = 1000;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Enabled = true;

            DialogResult dRes = cdlg.ShowDialog();
...
        void timer_Tick(object sender, EventArgs e)
        {
            subClassUtils.winClassName = "Camera View";
            subClassUtils.CloseButtonDisabled = true;
            System.Threading.Thread.Sleep(500);
            if(subClassUtils.CloseButtonDisabled)
                timer.Enabled = false;

        }

In the line “subClassUtils.CloseButtonDisabled = true;” the subclassing (or the hook) will be activated and clicks on (OK) will not be accepted.

Code subclassing.cs download: [Download not found]

Mobile Development: Disable Windows Mobile 6.5 Start and Close Button

Hello

here is one other way to write a kios mode .NET application using a technique called SubClassing. The idea was born by a comment of redwolf2222 on this blog about how to Hide Start and Close buttons on Windows Mobile 6.5 devices. Redwolf2222 also provided a code snippet. Unfortunately it was incomplete and so I wrote my own class.

Disable clicks on Start and Close button

The demo project shows one dialog with two check boxes and you can easily test the function. If “StartButton Disabled” or “Close Button disabled” is checked, you cannot ‘click’ the corresponding button any more:

You still ‘click’ the buttons but the subclassed window will not ‘execute’ your click. The buttons are part of the toolbar32 window which is a child of the menu_worker window. So first we have to follow the window tree.

Find the right window

/// <summary>
/// SubClassing: Install the wndproc hook
/// </summary>
/// <returns></returns>
private bool hookWindow()
{
    //find taskbar
    IntPtr hWndTaskbar = FindWindow("HHTaskbar", IntPtr.Zero);
    if (hWndTaskbar == IntPtr.Zero)
        return false;
    //enable the taskbar, not realy necessary
    EnableWindow(hWndTaskbar, true);
    //already installed?
    if (oldWndProc == IntPtr.Zero)
    {
        //find the menu_worker window
        IntPtr hwndMenu_Worker = FindWindow("menu_worker", IntPtr.Zero);
        if (hwndMenu_Worker != IntPtr.Zero)
        {
            //get the child window which has the buttons on it
            IntPtr hwndToolbar = GetWindow(hwndMenu_Worker, GetWindow_Cmd.GW_CHILD);
            if (hwndToolbar != IntPtr.Zero)
            {
                _mHwnd = hwndToolbar;       //store to remember
                SubclassHWnd(hwndToolbar);  //subclass the wndproc
            }
        }
    }
    return true;
}

Subclassing

Now, as we have the window handle, the subclassing can be started:
Continue reading ‘Mobile Development: Disable Windows Mobile 6.5 Start and Close Button’ »