using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; // ADD using System.Xml; using System.Reflection; using System.Diagnostics; using System.Runtime.InteropServices; using System.Collections.ObjectModel; namespace PictureMenu { public partial class Form1 : Form, IMessageFilter { [DllImport("User32.dll")] private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); private XmlDocument mXML1 = new XmlDocument(); private string msBarcode = string.Empty; private string msImage = string.Empty; private Boolean mbShowingBarcode = false; private Bitmap mBMP1 = null; //private Keys mKeyCode = Keys.None; private AboutBox1 FAbout = null; //WMPLib.IWMPPlaylist mPlayList = null; private ListPicture mList = new ListPicture(); private ItemPicture mItem = null; public class ListPicture : KeyedCollection { public ListPicture() : base() { } protected override int GetKeyForItem(ItemPicture item) { return item.iID; } } public class ItemPicture { public int iID; public string sPath; public Bitmap bmp1 = null; public override string ToString() { return string.Format("{0},{1}", iID, sPath); } } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Init string s1; int i1; ControlBox = false; FormBorderStyle = FormBorderStyle.None; KeyPreview = true; MaximizeBox = false; MinimizeBox = false; WindowState = FormWindowState.Maximized; picA.Width = Width; picA.Height = Height; picA.Visible = false; tbl1.Dock = DockStyle.Fill; pic1.SizeMode = PictureBoxSizeMode.StretchImage; pic2.SizeMode = PictureBoxSizeMode.StretchImage; pic3.SizeMode = PictureBoxSizeMode.StretchImage; pic4.SizeMode = PictureBoxSizeMode.StretchImage; pic5.SizeMode = PictureBoxSizeMode.StretchImage; pic6.SizeMode = PictureBoxSizeMode.StretchImage; pic7.SizeMode = PictureBoxSizeMode.StretchImage; pic8.SizeMode = PictureBoxSizeMode.StretchImage; pic9.SizeMode = PictureBoxSizeMode.StretchImage; pic1.Dock = DockStyle.Fill; pic2.Dock = DockStyle.Fill; pic3.Dock = DockStyle.Fill; pic4.Dock = DockStyle.Fill; pic5.Dock = DockStyle.Fill; pic6.Dock = DockStyle.Fill; pic7.Dock = DockStyle.Fill; pic8.Dock = DockStyle.Fill; pic9.Dock = DockStyle.Fill; timer1.Stop(); timer1.Interval = 5000; StringBuilder sb1 = new StringBuilder(); string sFile = string.Empty; string sQry = string.Empty; mXML1.Load(@".\ProductInfo.xml"); XmlNodeList nList = mXML1.SelectNodes("/ProductList"); if ((nList != null) && (nList.Count > 0)) { i1 = Convert.ToInt32(nList[0].Attributes["PicInterval"].Value); timer1.Interval = i1; msImage = nList[0].Attributes["BackGroundImage"].Value; mBMP1 = new Bitmap(msImage); } nList = null; sFile = string.Empty; sQry = "/ProductList/Media/Item"; nList = mXML1.SelectNodes(sQry); sb1.Length = 0; if (nList != null) { for (int i = 0; i < nList.Count; i++) { s1 = nList[i].Attributes["ID"].Value; i1 = Convert.ToInt32(s1); if ((i1 <= 9) && (i1 >= 1)) { sFile = nList[i].InnerText; sb1.Append(sFile); sb1.Append("|"); mItem = new ItemPicture(); mItem.iID = i1; mItem.sPath = sFile; mItem.bmp1 = new Bitmap(sFile); mList.Add(mItem); } } if (sb1.Length > 0) sb1.Length--; } s1 = sb1.ToString(); Trace.WriteLine("MediaList = " + s1); pic1.Image = mList[1].bmp1; pic2.Image = mList[2].bmp1; pic3.Image = mList[3].bmp1; pic4.Image = mList[4].bmp1; pic5.Image = mList[5].bmp1; pic6.Image = mList[6].bmp1; pic7.Image = mList[7].bmp1; pic8.Image = mList[8].bmp1; pic9.Image = mList[9].bmp1; Application.AddMessageFilter(this); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (mBMP1 != null) { mBMP1 = null; } // 沒用in VSD. //MediaP1.close(); //MediaP1.Dispose(); Application.RemoveMessageFilter(this); } private void ShowPicture(string sFilename) { Bitmap b1 = new Bitmap(sFilename); picA.Image = b1; picA.Visible = true; } private void myKeyPress(char c1) { msBarcode += c1; } private void Form1_KeyPress(object sender, KeyPressEventArgs e) { } private void picA_Click(object sender, EventArgs e) { timer1.Stop(); picA.Image = null; picA.Visible = false; msBarcode = string.Empty; } private void Form1_Paint(object sender, PaintEventArgs e) { Rectangle r1 = new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); if (mBMP1 != null) e.Graphics.DrawImage(mBMP1, r1); } private void timer1_Tick(object sender, EventArgs e) { timer1.Stop(); msBarcode = string.Empty; mbShowingBarcode = false; ShowScreen(); } private void ShowScreen() { if (mbShowingBarcode) { tbl1.Visible = false; } else { picA.Image = null; picA.Visible = false; tbl1.Visible = true; } } private void myShowPictureFound(string sFile) { timer1.Stop(); ShowPicture(sFile); mbShowingBarcode = true; ShowScreen(); timer1.Start(); } private void myKeyDown(Keys k1) { string sQry = string.Empty; string sFile = string.Empty; switch (k1) { case Keys.Enter: Boolean bFound = false; string s1 = msBarcode.ToUpper(); Trace.WriteLine("myKeyDown(): msBarcode=" + msBarcode); if (s1 == "TEST") { bFound = true; //timer1.Stop(); //sFile = "Product-01.jpg"; //ShowPicture(sFile); //mbShowingBarcode = true; //ShowScreen(); //timer1.Start(); myShowPictureFound("Product-01.jpg"); } else { sQry = "/ProductList/Product[@ID='" + msBarcode + "']"; sFile = string.Empty; XmlNodeList nList = mXML1.SelectNodes(sQry); Boolean bExist = false; if (nList != null) { if (nList.Count > 0) { bFound = true; //timer1.Stop(); //sFile = nList[0]["Image"].InnerText; //ShowPicture(sFile); //mbShowingBarcode = true; //ShowScreen(); //timer1.Start(); myShowPictureFound(nList[0]["Image"].InnerText); } } } msBarcode = string.Empty; break; case Keys.Escape: DialogResult d1 = MessageBox.Show("Close ?", "Confirm", MessageBoxButtons.OKCancel); if (d1 == DialogResult.OK) { this.Close(); } break; case Keys.F1: MessageBox.Show(String.Format("Version {0}", Assembly.GetExecutingAssembly().GetName().Version.ToString()), "Information"); break; default: break; } } private void Form1_KeyDown(object sender, KeyEventArgs e) { } #region IMessageFilter Members private const UInt32 WM_KEYDOWN = 0x0100; // 256 //private const UInt32 WM_CHAR = 0x0102; // 258 public bool PreFilterMessage(ref Message m) { //if (MediaP1.playState == WMPLib.WMPPlayState.wmppsPlaying) //{ // if (MediaP1.fullScreen == true) // { if (m.Msg == WM_KEYDOWN) { //int iPress = (((int)m.WParam) | ((int)Control.ModifierKeys)); //if (iPress) {} //else if () {} //else if () {} //else if () {} //else if () {} //else if () {} //else {} //SendMessage(this.Handle, (int)m.Msg, (int)m.WParam, (int)m.LParam); Boolean bText = false; //Keys KeyCode1 = (Keys)(int)m.WParam & Keys.KeyCode; Keys KeyCode1 = (Keys)(int)m.WParam & Keys.KeyCode; char KeyChar = Convert.ToChar(KeyCode1); Trace.WriteLine(string.Format("PreFilterMessage(): KeyCode1={0}, KeyChar={1}, msBarcode={2}", KeyCode1, KeyChar, msBarcode)); if ((KeyCode1 >= Keys.A) && (KeyCode1 <= Keys.Z)) bText = true; if ((KeyCode1 >= Keys.D0) && (KeyCode1 <= Keys.D9)) bText = true; if (bText) myKeyPress(KeyChar); else myKeyDown(KeyCode1); //if (keyCode == Keys.Escape) //{ // this.MediaP1.fullScreen = false; //} //switch (((int)m.WParam) | ((int)Control.ModifierKeys)) //{ // case (int)(Keys.Control | Keys.Alt | Keys.K): // MessageBox.Show("You pressed ctrl + alt + k"); // break; // //This does not work. It seems you can only check single character along with CTRL and ALT. // //case (int)(Keys.Control | Keys.Alt | Keys.K | Keys.P): // // MessageBox.Show("You pressed ctrl + alt + k + p"); // // break; // case (int)(Keys.Control | Keys.C): MessageBox.Show("You pressed ctrl+c"); // break; // case (int)(Keys.Control | Keys.V): MessageBox.Show("You pressed ctrl+v"); // break; // case (int)Keys.Up: MessageBox.Show("You pressed up"); // break; // case (int) Keys.Escape: // myKeyDown(Keys.Escape); // break; //} //return true; // true = stop dispatch. return false; // false = continue dispatch. } //if (m.Msg == WM_CHAR) //{ // // 沒攔截到WM_CHAR, 無效! // Keys KeyCode1 = (Keys)(int)m.WParam & Keys.KeyCode; // Trace.Write("Keycode1 = " + KeyCode1); // char KeyChar = Convert.ToChar(KeyCode1); // Trace.WriteLine("KeyChar1 = " + KeyChar); //} // } //} return false; // false = continue dispatch. } #endregion private void pic1_Click(object sender, EventArgs e) { myShowPictureFound(mList[1].sPath); } private void pic2_Click(object sender, EventArgs e) { myShowPictureFound(mList[2].sPath); } private void pic3_Click(object sender, EventArgs e) { myShowPictureFound(mList[3].sPath); } private void pic4_Click(object sender, EventArgs e) { myShowPictureFound(mList[4].sPath); } private void pic5_Click(object sender, EventArgs e) { myShowPictureFound(mList[5].sPath); } private void pic6_Click(object sender, EventArgs e) { myShowPictureFound(mList[6].sPath); } private void pic7_Click(object sender, EventArgs e) { myShowPictureFound(mList[7].sPath); } private void pic8_Click(object sender, EventArgs e) { myShowPictureFound(mList[8].sPath); } private void pic9_Click(object sender, EventArgs e) { myShowPictureFound(mList[9].sPath); } } }