Click here to Skip to main content
13,250,883 members (51,958 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 8 Mar 2011

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

, 8 Mar 2011
Rate this:
Please Sign up or sign in to vote.
This article uses a technique known as subclassing.

If you are running a kiosk mode app but need to provide the CameraCapture dialog on Windows Mobile 5 or later, you may need to disable clicks 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 cannot 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.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 = <strong>cdlg.ShowDialog();</strong>
void timer_Tick(object sender, EventArgs e)
    subClassUtils.winClassName = "Camera View";
    <strong>subClassUtils.CloseButtonDisabled = true;</strong>
        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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Germany Germany
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionUsage example Pin
BraveTart27-Mar-12 5:13
memberBraveTart27-Mar-12 5:13 
AnswerRe: Usage example Pin
hjgode27-Mar-12 8:05
memberhjgode27-Mar-12 8:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 8 Mar 2011
Article Copyright 2011 by hjgode
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid