jascam / CodePlexFoo

0 stars 0 forks source link

Windows Mobile Developement ( problem with CameraApplication in Intermec CN50 windows Mobile Device) #445

Open jascam opened 6 years ago

jascam commented 6 years ago

Hi developement team ,   Please could you help me In the case of Window Mobile Application development of Camera application Below I am showing my sample Actually I had sample Application, this sample Application working fine with CN50 intermec windows Mobile and with Psion teklogix Ikon windows Mobile also.(This is without Integration)   Especially this error coming , when I am integrating with my existing Mobile Application. In this case As per debugging through my code I am getting error like Sysytem.Invalidoperation {Unknown error Occurred.}   at Microsoft.WindowsMobile.Forms.CameraCaptureDialog.LaunchCameraCaptureDialog(IntPtr
ptrStruct) at Microsoft.WindowsMobile.Forms.CameraCaptureDialog.ShowDialog() at wwMobileDevice.frmPicture.ShowCamera() at wwMobileDevice.frmPicture.btnCamera_Click(Object sender, EventArgs e) at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam) at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam) at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain) at System.Windows.Forms.Application.Run(Form fm) at wwMobileDevice.Program.Main(String[] argv)   Here two cases are there . 1) Our integrated Mobile Camera Application is working fine with Psion teklogix Ikon windows Mobile Device. 2) But Integrated Mobile Camera Application Is Not working with Intermec CN50 windows Mobile Device. 3) In this CN50 device Problem coming with DialogResult dRes = cdlg.ShowDialog();Method Of Microsoft.windowsMobile.Forms.dll through my code. 4) Any way Iam Showing my code here

       This is my Integrated code and I am trying in this way.

      using System; //using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.IO; using System.Windows.Forms; using Microsoft.WindowsMobile.Forms; using System.Runtime.InteropServices; using Microsoft.WindowsCE.Forms; namespace wwMobileDevice { public partial class frmPicture : Form { private clsData dataFMO = clsData.GetInstance(); private string sEndorsementId; private Bitmap myImager; string result = null; string filePath = null; bool Captured = false;   private System.Windows.Forms.Timer timer; hwndutils subClassUtils;   //[DllImport("coredll.dll", SetLastError = true)] //public static extern IntPtr DestroyWindow(IntPtr hWnd);   //[DllImport("coredll.dll", SetLastError = true)] //public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);     //CameraCaptureDialog cameraDialog = new CameraCaptureDialog(); //string windowTitle = "";   public frmPicture() { InitializeComponent(); }   private void frmPicture_Load(object sender, EventArgs e) {   } public void RefreshScreen() { //InitializeComponent(); sEndorsementId = clsCommon.Instance.getUniqueId(); viewPictureBox.Image = null; cmbIssueType.Items.Clear(); txtComments.Text = string.Empty; cmbIssueType.Items.Add("X"); cmbIssueType.Items.Add("Y"); cmbIssueType.Items.Add("Z");   } private void ShowCamera() { CameraCaptureDialog cdlg = new CameraCaptureDialog(); cdlg.DefaultFileName = "picture.jpg"; cdlg.InitialDirectory = "\My Documents"; cdlg.Mode = CameraCaptureMode.Still; cdlg.Owner = this.viewPictureBox; cdlg.StillQuality = CameraCaptureStillQuality.High; cdlg.Title = "Take a picture and Select"; cdlg.Resolution = new Size(240, 320); GC.Collect();   //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();//exactly my error coming at this statement like Unkown error occurred in intermec CN50 windows Mobile But in another device PsionTeklogix Ikon windows Mobile this Statement executing successfully. Iam Unable Hanlding this Problem   filePath = cdlg.FileName.ToString(); if (string.IsNullOrEmpty(filePath)) { return; } //if (dRes == DialogResult.OK) //{ // //load image // try // { // filePath = cdlg.FileName.ToString(); // if (filePath == null) // { // return; // } // } // catch (SystemException sx) // { // System.Diagnostics.Debug.WriteLine(sx.Message); // } //} cdlg.Dispose();     viewPictureBox.Image = new Bitmap(filePath); this.Show(); cdlg.Dispose(); //return result;   }   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; }       public class hwndutils : IDisposable { private string _winClassName = "HHTaskbar"; public string winClassName { get { return _winClassName; } set { if (this.oldWndProc == IntPtr.Zero) //only allow change before subclassing _winClassName = value; } } private bool _mIsStartButtonDisabled = false; private bool _mIsCloseButtonDisabled = false; private IntPtr _mHwnd = IntPtr.Zero; public bool StartButtonDisabled { set { this._mIsStartButtonDisabled = value; if (this._mIsStartButtonDisabled) { if (this.oldWndProc == IntPtr.Zero) //already hooked? { this.hookWindow(); } } else { if (this._mIsCloseButtonDisabled == false)//we will not unhook if hook is installed for StartButton { this.unhookWindow(); } } } get { return this._mIsStartButtonDisabled; } }   public bool CloseButtonDisabled { set { this._mIsCloseButtonDisabled = value; if (this._mIsCloseButtonDisabled) { if (this.oldWndProc == IntPtr.Zero) //already hooked? { this.hookWindow(); } } else { if (this._mIsStartButtonDisabled == false)//we will not unhook if hook is installed for StartButton { this.unhookWindow(); } } } get { return this._mIsCloseButtonDisabled; } } public hwndutils() { }   //dispose public void Dispose() {   unhookWindow(); }   private void unhookWindow() { if (this.oldWndProc != IntPtr.Zero && this._mHwnd != IntPtr.Zero) { SetWindowLong(this._mHwnd, GWL_WNDPROC, this.oldWndProc); //restore old wndproc! this._mIsStartButtonDisabled = false; this.oldWndProc = IntPtr.Zero; this._mHwnd = IntPtr.Zero; } } /// /// SubClassing: Install the wndproc hook /// /// 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; }

region PINVOKES

        // Win32 API needed
        [DllImport("coredll.dll", SetLastError = true)]
        public static extern System.UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
        public enum GWL
        {
            GWL_WNDPROC = (-4),
            GWL_HINSTANCE = (-6),
            GWL_HWNDPARENT = (-8),
            GWL_STYLE = (-16),
            GWL_EXSTYLE = (-20),
            GWL_USERDATA = (-21),
            GWL_ID = (-12)
        }
        [DllImport("coredll.dll", SetLastError = true)]
        static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd);

  enum GetWindow_Cmd : uint { GW_HWNDFIRST = 0, GW_HWNDLAST = 1, GW_HWNDNEXT = 2, GW_HWNDPREV = 3, GW_OWNER = 4, GW_CHILD = 5, GW_ENABLEDPOPUP = 6 } [DllImport("coredll.dll", EntryPoint = "FindWindow", SetLastError = true)] public static extern IntPtr FindWindow(string lpClassName, IntPtr lpWindowName); [DllImport("coredll.dll")] public static extern bool EnableWindow(IntPtr hWnd, bool bEnable);   [DllImport("coredll")] private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, Win32WndProc newProc); [DllImport("coredll")] private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr newProc); [DllImport("coredll")] private static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, int wParam, int lParam); [DllImport("coredll.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect); [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; // x position of upper-left corner public int Top; // y position of upper-left corner public int Right; // x position of lower-right corner public int Bottom; // y position of lower-right corner }

endregion

  // A delegate that matches Win32 WNDPROC: private delegate IntPtr Win32WndProc(IntPtr hWnd, int Msg, int wParam, int lParam);   // from winuser.h: private const int GWL_WNDPROC = -4; private const int WM_LBUTTONDOWN = 0x0201; private const int WM_LBUTTONUP = 0x0202;   // program variables private IntPtr oldWndProc = IntPtr.Zero; private Win32WndProc newWndProc;// = IntPtr.Zero; //null;   private void SubclassHWnd(IntPtr hWnd) { // hWnd is the window you want to subclass..., create a new // delegate for the new wndproc newWndProc = new Win32WndProc(MyWndProc); // subclass oldWndProc = SetWindowLong(hWnd, GWL_WNDPROC, newWndProc); }   // this is the new wndproc, just show a messagebox on left button down: private IntPtr MyWndProc(IntPtr hWnd, int msg, int wParam, int lParam) { //is this a message for us? if ((msg == (int)WM_LBUTTONDOWN) || (msg == (int)WM_LBUTTONUP)) { int x = ((int)lParam) & 0xFFFF; int y = ((int)lParam) >> 16; System.Diagnostics.Debug.WriteLine("MyWndProc got lClick at " + x.ToString() + "/" + y.ToString());   if (this._mIsStartButtonDisabled || this._mIsCloseButtonDisabled) { bool isVGA; bool isQVGA; using (System.Windows.Forms.Control detector = new System.Windows.Forms.Control()) { using (System.Drawing.Graphics gr = detector.CreateGraphics()) { isVGA = gr.DpiY == 192; isQVGA = gr.DpiY == 96; } }   RECT rect; GetWindowRect(hWnd, out rect); //get the rectangle of the menu_bar   int width = Math.Max(rect.Left, rect.Right) - Math.Min(rect.Left, rect.Right); int height = Math.Max(rect.Bottom, rect.Top) - Math.Min(rect.Bottom, rect.Top);   //width values are assumed int buttonWidth = (isQVGA | isVGA) ? 92 : 46; int buttonHeight = height; //(isQVGA | isVGA) ? 72 : 36;   System.Drawing.Rectangle rectStartButton = new System.Drawing.Rectangle(0, 0, buttonWidth, buttonHeight); System.Drawing.Rectangle rectCloseButton = new System.Drawing.Rectangle(width - buttonWidth, 0, buttonWidth, buttonHeight);   //check if enabled and click is inside the start or close button rectangle if (this._mIsStartButtonDisabled && rectStartButton.Contains(x, y)) return IntPtr.Zero; if (this._mIsCloseButtonDisabled && rectCloseButton.Contains(x, y)) return IntPtr.Zero;   //if both are false, we have to provide the click to windows return CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam); } else return CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam); } else return CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam); } }

  private void btnCamera_Click(object sender, EventArgs e) {

        ShowCamera();
    }

  }}       Thank you. With Regards, sripalb

Attachments

WM5ImageProc1.zip

Migrated CodePlex Work Item Details

CodePlex Work Item ID: '9836' Vote count: '1'

jascam commented 6 years ago

Here I attached Camera Sample Application. I t will work Fine but Once we Integrating DialogResult dRes = cdlg.ShowDialog();//exactly my error coming at this statement like Unkown error occurred in intermec CN50 windows Mobile But in another device PsionTeklogix Ikon windows Mobile this Statement executing successfully. Iam Unable Hanlding this Problem

This comment was posted by sripalb on 11/17/2011

jascam commented 6 years ago

This comment was posted by on 11/17/2011

jascam commented 6 years ago

This comment was posted by on 11/17/2011

jascam commented 6 years ago

Hello sripalb, did you get any solution? We have the same issue and we've been trying some workarounds without success.

I'll appreciate any information.

Thank you!

This comment was posted by elvinmeza on 7/4/2012

jascam commented 6 years ago

hi elvinmeza,

I think you guys have been trying some workarounds camera application error. here I am also trying to solve that problem.But I am not sure ,I can give you some Information, this Information i got from forums ,they are saying like we can't use Barcode scaning,emdi,camera at the sametime.In this case May be camera application raising that problem. for example especially with emdi ,once you capture image after capturing the image you need to disable the property of the document Image(EMDI). In this way we need to check.

This comment was posted by sripalb on 7/18/2012

jascam commented 6 years ago

This comment was posted by on 2/21/2013

jascam commented 6 years ago

How can someone even read this garbled text? Am I missing some setting or? Thanks,

This comment was posted by mypascal2000 on 9/18/2013