跳转到路径导航栏
跳转到正文内容

VS 2010 开发Windows Mobile程序

http://www.sina.com.cn  2009年10月29日 07:16  IT168.com

文本Tag: Visual Studio Visual C# Windows Mobile

  【IT168 技术】先说说用VS 2010开发WM程序的好处吧。说到好处这里就不得不提提,最近Windows 7 的正式发售和Visual Studio 2010 Beta2的上线了。这些都是微软微软即将发布的系列产品的一部分。这些新的产品将拥有更高是集成度和更紧密的相互支持。对于开发人员来说,统一的开发标准带来的不仅仅是方便,更是效率的提高。

  拿“Hello World”程序来举个例子吧。只需要将Win32版下,程序里的PSTR改为LPTSTR就可以编译运行了。

  代码:



Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPTSTR lpCmdLine,
int nShowCmd)
{
     MessageBox(NULL, TEXT(
"Hello, Windows Mobile!"), TEXT("HelloMsg"), 0);
    
return 0;
}

  这表示,Windows Mobile 的开发与一般的Windows程序开发基本是一样的。不需要很复杂的学习过程大家就可以上手了。并且可以使用自己熟悉的语言来进行编写。

  伴随着智能手机的普及,加上3G时代的到来,编写手机应用程序的需求必将迎来一个爆炸式的增长。

  下面来看一段windows mobile中用C#实现的cmnet链接的代码:



Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

public bool Connectcmnetmethod(Guid destGuid, bool exclusive, bool mode)
        {
            {
                connInfo.cbSize
= (uint)Marshal.SizeOf(connInfo);
                connInfo.dwParams
= 0x1;//CONNMGR_PARAM_GUIDDESTNET;
                connInfo.dwPriority = 0x08000;
                connInfo.dwFlags
= 0x1 | 0x2 | 0x4 | 0x8;//0;
                connInfo.bExclusive = 0;// exclusive;
                connInfo.bDisabled = 0;// false;
                connInfo.guidDestNet = destGuid;
                connInfo.hWnd
= this.Handle;
                
if (mode == true)
                {
                    result
= ConnMgrEstablishConnectionSync(ref connInfo, ref hConnection, 10000, out dwStatus);
                    
if (result != 0) MessageBox.Show(result.ToString("X"), dwStatus.ToString("X"));
                    
return result == 0;
                }
                
return false;
            }
        }
        
public struct CONNMGR_CONNECTIONINFO
        {
            
public uint cbSize;
            
public uint dwParams;
            
public uint dwFlags;
            
public uint dwPriority;
            
public int bExclusive;
            
public int bDisabled;
            
public Guid guidDestNet;
            
public IntPtr hWnd;
            
public uint uMsg;
            
public uint lParam;
            
public uint ulMaxCost;
            
public uint ulMinRcvBw;
            
public uint ulMaxConnLatency;
        }
        [DllImport(
"cellcore.dll", EntryPoint = "ConnMgrEstablishConnectionSync", SetLastError = true)]
        
internal static extern int ConnMgrEstablishConnectionSync(ref CONNMGR_CONNECTIONINFO pConnInfo, ref IntPtr phConnection, int dwTimeout, out int dwStatus);

        [DllImport(
"cellcore.dll", EntryPoint = "ConnMgrEstablishConnection", SetLastError = true)]
        
internal static extern int ConnMgrEstablishConnection(ref CONNMGR_CONNECTIONINFO pConnInfo, ref IntPtr phConnection);

        [DllImport(
"cellcore.dll", EntryPoint = "ConnMgrReleaseConnection", SetLastError = true)]
        
internal static extern int ConnMgrReleaseConnection(IntPtr hConnection, int lCache);

        [DllImport(
"coredll.dll")]
        
private static extern int CloseHandle(IntPtr hObject);

        [DllImport(
"Coredll.dll", EntryPoint = "GetLastError", SetLastError = true)]
        
internal static extern int GetLastError();

private void menuItem1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(Connect(
new Guid("7022E968-5A97-4051-BC1C-C578E2FBA5D9"), false, true).ToString());
        }

  编写的思路:判断connInfo.guidDestNet = destGuid,导入cellcore.dll使用它的三个方法,最后异常处理Coredll.dll,GetLastError.

  在Visual Studio 2010下很容易的实现了简单,易用,稳定,高效的程序要求。但是也有一些问题存在,比如:手机资源消耗大,要安装移动版的Framework程序。 市场上windows mobile的占有率很低,短时间内不会有很多撰写程序的需求。

  不过,微软拓展手机市场的决心和力度还是可以看到的。新版的WM 7 也有了长足的进步。相信前景是光明的。

  

缂傚倸鍊搁崐椋庢媼閺屻儱纾婚柟鍓х帛閻撴瑦銇勯弽褎顥滈柛鐔告綑閳绘捇鏁撻敓锟�|Android闂傚倸鍊烽懗鍓佸垝椤栫偛鏄ラ柛顐犲劚閻鏌涢幇鈺佸婵炴垯鍩勯弫鍡涙煃瑜滈崜鐔镐繆閹绢喖绠虫俊銈傚亾鐎瑰憡绻傞埞鎴︽偐閹绘巻鍋撶紒妯碱洸闁绘劗鍎ら埛鎴︽煕濞戞﹫榫氬瑙勶耿閺岋絽螖娴g懓纰嶉梺宕囩帛濡啴寮幘缁樻櫢闁跨噦鎷� 闂傚倸鍊烽懗鍫曞磿閻㈢ǹ鐤炬繝濠傚暟楠炴捇鏌涜椤ㄥ懐澹曠紒妯镐簻闁靛牆娲﹂悘纰糳闂傚倸鍊烽懗鍓佸垝椤栫偛鏄ラ柛顐犲劚閻鏌涢幇鈺佸婵炴垯鍩勯弫鍡涙煕閺囥劌澧ù鐘虫そ濮婂宕掑鍗烆杸缂備礁顑嗛崹鍧楀Υ閸愵喗鏅搁柨鐕傛嫹 濠电姷鏁告慨浼村垂瑜版帗鍊堕柛顐犲劚閻ょ偓绻濋棃娑卞剰闁哄绶氶弻鐔煎礈瑜忕敮娑㈡煕鐎n亶妯€鐎殿喖鐖煎畷鐓庘槈濡警鐎抽梻浣告啞閹哥兘宕¢幎钘夎摕闁挎繂鎳夐弸搴㈢箾閸℃ê濮囨い蹇ユ嫹 闂傚倷娴囧畷鍨叏瀹ュ绀冩い鎾跺剱娴煎啴姊绘担铏瑰笡闁圭ǹ鎽滈埀顒佺濠㈡﹢鎮鹃悜钘夐唶闁哄洨鍠庨埀顒傚厴閺屻倗鍠婇崡鐐差潾闂佷紮绲块弫濠氬箖瀹勬壋鍫柛鎰╁妿閻╁酣姊洪悷鏉挎闁瑰嚖鎷�

转发此文至微博

Powered By Google

新浪简介About Sina广告服务联系我们招聘信息网站律师SINA English会员注册产品答疑┊Copyright © 1996-2010 SINA Corporation, All Rights Reserved

新浪公司 版权所有