平时收获,供需及取(PPC)


  1作者:ah, 2007-06-08
  91.初始化转90度:
 10//Sets the screen orientation to portrait.
 11Microsoft.WindowsCE.Forms.SystemSettings.ScreenOrientation = Microsoft.WindowsCE.Forms.ScreenOrientation.Angle90;
 12
 132.
 14// Removes Minimize (X) and Close(OK) buttons.
 15            // Caution: Only way to close the application
 16            // is with the Running Programs memory options under Settings. 
 17           this.ControlBox = false;
 18
 193.背景
 20      protected override void OnPaint(PaintEventArgs e)
 21        {
 22            //Get image compiled as an embedded resource.
 23            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
 24
 25            // Note that the name for the embedded resource
 26            // is case sensitive and must match the file name.
 27            Bitmap backgroundImage = new Bitmap(asm.GetManifestResourceStream("MySnippets.images.wallpaper.bmp"));
 28            //backgroundImage = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("AYMove.images.indexbg.jpg"));
 29
 30            e.Graphics.DrawImage(backgroundImage, this.ClientRectangle, new Rectangle(00, backgroundImage.Width, backgroundImage.Height), GraphicsUnit.Pixel);
 31        }

 32
 335.取得平台:
 34private string GetDeviceName()
 35        {
 36            return System.Net.Dns.GetHostName();//ppc or smtphone
 37        }

 38
 396.取到程序路径
 40        private string GetApplicationDirectory()
 41        {
 42            return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
 43        }

 44
 457.Set CenterForm
 46 private void CenterForm()
 47        {
 48            //Set the desired form size.  
 49            this.FormBorderStyle = FormBorderStyle.None;
 50            this.Size = new Size(200200);
 51            this.BackColor = Color.Wheat;
 52            this.FormBorderStyle = FormBorderStyle.None;
 53            //Get the size of the screen for centering the form.
 54            Rectangle rectS = Screen.PrimaryScreen.Bounds;
 55            this.Location = new Point(Convert.ToInt32((rectS.Width - this.Width) / 2), Convert.ToInt32((rectS.Height - this.Height) / 2));
 56        }

 57
 588.
 59 private void SetInputMethod()
 60        {
 61            // Sets the input method to Letter Recognizer.
 62            foreach (Microsoft.WindowsCE.Forms.InputMethod method in inputPanel1.InputMethods)
 63            {
 64                if (method.Name == "Letter Recognizer")
 65                {
 66                    inputPanel1.CurrentInputMethod = method;
 67                    break;
 68                }

 69            }

 70        }

 71
 729.
 73        //Set up file extension filters for a
 74        //DocumentList and set the initial folder
 75        void SetupDocList()
 76        {
 77            documentList1.Parent = this;
 78            documentList1.Filter = " |*.*| |*.txt;*.xml| |*.pwi;*.pdt| |*.pxl; *.psw| |*.jpg;*.gif;*.bmp| |*.wav;*.wmv;*.mpg;";
 79            documentList1.FilterIndex = 0;
 80            documentList1.SelectedDirectory = "Program Files";
 81        }

 82
 83        private void DocList_DocumentActivated(Object sender, Microsoft.WindowsCE.Forms.DocumentListEventArgs docevent)
 84        {
 85            // Add code to open the selected file.
 86
 87        }

 88
 89        private void DocList_DeletingDocument(object sender, Microsoft.WindowsCE.Forms.DocumentListEventArgs docevent)
 90        {
 91            // Add code to close any instances of the file.
 92        }

 93
 94        private void DocList_SelectedDirectoryChanged(object sender, System.EventArgs e)
 95        {
 96            // Add code to access the selected folder to open and close files.
 97        }

 98
 9910.private void SendNotification(string message)
100        {
101            // Set the Text property to the HTML string.
102            notification1.Text = message;
103
104            // Get the icon as an embedded resource.
105            // Note that the icon must be added to the project as an embedded resource.
106            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
107
108
109            // Note that the name for the embedded resource
110            // is case sensitive and must match the file name.
111            System.IO.Stream stream = asm.GetManifestResourceStream("PocketPCApplication1.notify.ico");
112            notification1.Icon = new Icon(stream, 1616);
113
114            // If the notification is canceled, its icon remains
115            // available for later activating the notification.
116            notification1.InitialDuration = 10;
117            notification1.Visible = true;
118        }

119
12011.
121 private void LoadPicture()
122        {
123            Bitmap bmpSource;
124            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
125
126            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
127            try
128            {
129                bmpSource = new Bitmap(asm.GetManifestResourceStream("DeviceApplication1.mypicture.bmp"));
130                pictureBox1.Image = bmpSource;
131            }

132            catch (NullReferenceException ex)
133            {
134            }

135        }

136
13712.
138  public int CTL_CODE(int DeviceType, int Func, int Method, int Access)
139        {
140            return (DeviceType << 16| (Access << 14| (Func << 2| Method;
141        }

142
143        [System.Runtime.InteropServices.DllImport("Coredll.dll")]
144        static extern int KernelIoControl(int dwIoControlCode, IntPtr lpInBuf, int nInBufSize, IntPtr lpOutBuf, int nOutBufSize, ref int lpBytesReturned);
145
146        private int ResetPocketPC()
147        {
148            const int FILE_DEVICE_HAL = 257;
149            const int METHOD_BUFFERED = 0;
150            const int FILE_ANY_ACCESS = 0;
151
152            int bytesReturned = 0;
153            int IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS);
154
155            return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0ref bytesReturned);
156        }

157
15813.
159
160        // Shortens the height of a ListBox when the SIP
161        // (Soft Input Panel) is displayed so that the vertical
162        // scroll bar of the ListBox is not obscured by the SIP.
163
164        // Size the ListBox to about the height of the form.
165        // Put the TextBox to the upper right or left of the list box.
166
167        // When the TextBox receives focus, the SIP is enabled.
168        //  When the ListBox receives focus, the SIP is disabled.
169
170        int ListBoxFullHeight = 0;
171        // Call this method from the constructor, 
172        // or Form_Load event, of your form
173
174        private void SetListBoxFullHeight()
175        {
176            // Determine the original height of the list box.
177            ListBoxFullHeight = listBox1.Height;
178        }

179
180        // The InputPanel.EnabledChanged event
181        // occurs whenever the SIP is enabled or disabled.
182        private void inputPanel1_EnabledChanged(Object sender, System.EventArgs e)
183        {
184            Rectangle VisibleRect;
185
186            if (inputPanel1.Enabled == false)
187            {
188                // The SIP is disabled, so the height of the ListBox
189                // is set to its original full height (ListBoxFullHeight).
190                listBox1.Height = ListBoxFullHeight;
191            }

192            else
193            {
194                // The SIP is enabled, so the height of the ListBox
195                // is set to the height of the visible desktop area,
196                // minus 10 pixels for padding.
197                VisibleRect = inputPanel1.VisibleDesktop;
198                listBox1.Height = VisibleRect.Height - 20;
199            }

200        }

201        private void textBox1_GotFocus(Object sender, System.EventArgs e)
202        {
203            // Display the SIP for entering text.
204            inputPanel1.Enabled = true;
205        }

206
207        private void listBox1_GotFocus(Object sender, System.EventArgs e)
208        {
209            // Hide the SIP.
210            inputPanel1.Enabled = false;
211        }

212
21314.
214public class Sound
215        {
216            byte[] sbytes;
217            string fn;
218            private enum Flags
219            {
220                SND_SYNC = 0,
221                SND_ASYNC = 1,
222                SND_NODEFAULT = 2,
223                SND_MEMORY = 4,
224                SND_LOOP = 8,
225                SND_NOSTOP = 16,
226                SND_NOWAIT = 8192,
227                SND_ALIAS = 65536,
228                SND_ALIAS_ID = 1114112,
229                SND_FILENAME = 131072,
230                SND_RESOURCE = 262148
231            }

232
233            [System.Runtime.InteropServices.DllImport("CoreDll.dll", EntryPoint = "PlaySound")]
234            public static extern int WCE_PlaySound(string szSound, IntPtr hMod, int flags);
235
236            [System.Runtime.InteropServices.DllImport("CoreDll.dll", EntryPoint = "PlaySound")]
237            public static extern int WCE_PlaySoundBytes(byte[] szSound, IntPtr hMod, int flags);
238
239            // This class has two overloads. You can either  
240            // pass a file name or a stream of the sound file.
241
242            // Construct the Sound object to play sound data from the specified file.  
243            public Sound(string fileName)
244            {
245                fn = fileName;
246            }

247
248            // Construct the Sound object to play sound data from the specified stream.
249            public Sound(System.IO.Stream stream)
250            {
251                // read the data from the stream
252                sbytes = new byte[System.Convert.ToInt32(stream.Length)];
253                stream.Read(sbytes, 0, (Convert.ToInt32(stream.Length)));
254            }

255            // Play the sound
256            public void Play()
257            {
258                // If a file name has been registered, call WCE_PlaySound,
259                // otherwise call WCE_PlaySoundBytes.
260                if (!((fn) == null))
261                {
262                    WCE_PlaySound(fn, IntPtr.Zero, Convert.ToInt32(Flags.SND_ASYNC | Flags.SND_FILENAME));
263                }

264                else
265                {
266                    WCE_PlaySoundBytes(sbytes, IntPtr.Zero, Convert.ToInt32(Flags.SND_ASYNC | Flags.SND_MEMORY));
267                }

268            }

269        }

270
27115.
272 public enum HashMethod { MD5, SHA1, SHA384 }
273
274        public string GenerateHashDigest(string source, HashMethod algorithm)
275        {
276            HashAlgorithm hashClass = null;
277            switch (algorithm)
278            {
279                case HashMethod.MD5:
280                    hashClass = new MD5CryptoServiceProvider();
281                    break;
282                case HashMethod.SHA1:
283                    hashClass = new SHA1CryptoServiceProvider();
284                    break;
285                case HashMethod.SHA384:
286                    hashClass = new System.Security.Cryptography.SHA384Managed();
287                    break;
288                default:
289                    // Error case.
290                    break;
291            }

292
293            byte[] byteValue = Encoding.UTF8.GetBytes(source);
294            byte[] hashValue = hashClass.ComputeHash(byteValue);
295
296            return Convert.ToBase64String(hashValue);
297        }
 116.
 2/// <summary>
 3        /// This structure represents a date and time using individual members for
 4        /// the month, day, year, weekday, hour, minute, second, and millisecond. 
 5        /// </summary>

 6        public struct SYSTEMTIME 
 7        {
 8            /// <summary>
 9            /// Specifies the current year.
10            /// </summary>

11            public ushort wYear; 
12            /// <summary>
13            /// Specifies the current month; January = 1, February = 2, and so on.
14            /// </summary>

15            public ushort wMonth; 
16            /// <summary>
17            /// Specifies the current day of the week; Sunday = 0, Monday = 1, and so on.
18            /// </summary>

19            public ushort wDayOfWeek; 
20            /// <summary>
21            /// Specifies the current day of the month.
22            /// </summary>

23            public ushort wDay; 
24            /// <summary>
25            /// Specifies the current hour.
26            /// </summary>

27            public ushort wHour;
28            /// <summary>
29            /// Specifies the current minute.
30            /// </summary>

31            public ushort wMinute;
32            /// <summary>
33            /// Specifies the current second.
34            /// </summary>

35            public ushort wSecond;
36            /// <summary>
37            /// Specifies the current millisecond.
38            /// </summary>

39            public ushort wMilliseconds;
40        }

41
42        /// <summary>
43        /// This function retrieves the current system date and time. The system time
44        /// is expressed in Coordinated Universal Time (UTC).
45        /// </summary>
46        /// <param name="lpSystemTime">[out] Pointer to a SYSTEMTIME structure to
47        /// receive the current system date and time.</param>

48        [DllImport("coredll.dll")]
49        public extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);
50
51        /// <summary>
52        /// This function sets the current system time and date. The system time is
53        /// expressed in Coordinated Universal Time (UTC).
54        /// </summary>
55        /// <param name="lpSystemTime">[in] Pointer to a SYSTEMTIME structure that
56        /// contains the current system date and time.</param>
57        /// <returns></returns>

58        [DllImport("coredll.dll")]
59        public extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);
60
61
posted @ 2007-12-17 15:40  突破666  阅读(1788)  评论(3编辑  收藏  举报
郴州东江湖农家乐联盟:www.djhnjllm.com 郴州东江湖农家乐联盟