태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.


[ESP / SimConnect SDK][.NET / C#]
Microsoft ESP - SimConnect SDK 개발의 시작
The Start to Develop the Microsoft ESP - SimConnect SDK

본 문서에서는 Microsoft 사의 최신 시뮬레이터 엔진인 ESP 기반의 소프트웨어개발키트(S.D.K. ;Software Development Kit)를 이용한 Flight Simulator X 확장 소프트웨어 개발, SimConnect (심커넥트)에 대한 설명을 제공합니다.

 

SimConnect란 무엇이며 어떠한 것을 구현할 수 있는가?
What is SimConnect? What can i do with SimConnect?

SimConnect는 Microsoft 사에서 개발한 비행 시뮬레이터 소프트웨어인 Flight Simulator X와 연동, 확장시켜주는 소프트웨어 개발 인터페이스입니다.
소프트웨어 개발자는 SimConnect를 이용하여 Flight Simulator X와 상호 작용하는 별도의 소프트웨어를 개발할 수 있으며 쉽게 시뮬레이터 엔진에 접근하고 제어할 수 있습니다.
즉, SimConnect는 Flight Simulator와 별도의 독립된 애플리케이션 간의 다리(bridge 브릿지) 역할을 하는 API (Application Programming Interface)이라고 할 수 있습니다.

[그림 1] SimConnect API

SimConnect를 통하여 Flight Simulator 소프트웨어 개발자는 다음과 같은 목적을 구현할 수 있습니다.
- Flight Simulator에 새로운 항공기 계기(Gauge)를 제작하고 작동시킬 수 있습니다.
- 새로운 비행 이벤트 (Flight Event)를 발생시키고 상황(situation, flight state)을 적용하고 새로운 비행 시나리오를 제작할 수 있습니다.
- Flight Simulator 조종사의 비행을 실시간으로 모니터링(monitoring)하고 기록(record)할 수 있습니다.
- Flight Simulator 내부에서 작동하는 인공지능 비행 트래픽 (A.I. flight traffic)을 구현할 수 있습니다.
- 새로운 기상 상태 (weather condition)를 적용하고 구현할 수 있습니다.
- Flight Simulator와 호환되는 새로운 비행 장치(flight device)나 하드웨어를 작동시키게 할 수 있습니다.
- 비행 시점 (visual camera on flight simulator)을 새로 구현하거나 사용자 정의(customize)할 수 있습니다.

  SimConnect SDK를 이용하여 개발이 가능한 언어는 네이티브 코드(native code)(또는 비관리 코드 Un-managed code) 언어인 C++과 관리 코드(managed code) 언어인 .NET 기반의 C#, Visual Basic .NET 언어입니다.
본 문서에서는 관리 코드 언어인 C# .NET을 기반으로 개발에 대해 설명합니다.

 

 

SimConnect 인터페이스 참조
Add SimConnect Namespace to your Reference

본 문서에서는 개발 도구 및 언어로서, Microsoft Visual Studio 2005와 C# 언어를 사용합니다.
SimConnect SDK에서 제공하는 SimConnect 클래스 라이브러리에 접근하기 위해 관리 코드로 컴파일된 SimConnect DLL 파일에 대한 참조(Reference)를 추가합니다.
이 참조에 대한 전체 네임스페이스 이름은 Microsoft.FlightSimulator.SimConnect 입니다.

[예시 2] Visual Studio 2005에 SimConnect 참조 추가


 
using System.Runtime.InteropServices;
using Microsoft.FlightSimulator.SimConnect;

SimConnect 네임스페이스에 접근하기 위해 SimConnect 네임스페이스에 대한 using 지시문을 추가합니다.
Flight Simulator는 네이티브 코드 기반으로 개발되었기 때문에 Windows API에 대한 참조도 필요합니다.
따라서, 관리 코드인 .NET과 비관리 코드 간의 상호 운용성이 필요하기 때문에 System.Runtime.InteropServices 네임스페이스에 대한 참조도 추가하였습니다.
  
[예시 3] Flight Simulator X 비행을 실시간으로 모니터링하는 프로그램, FSX Simulator Monitor


 
필자는 위와 같은 인터페이스를 가진 모니터링 프로그램을 구현해보았습니다.
[Connect FSX] 버튼을 클릭함으로서, SimConnect와 모니터링 프로그램은 서로 연결되며 SimConnect는 Flight Simulator X로부터 받아온 각 비행 데이터를 모니터링 프로그램에 전달해줍니다.
모니터링하는 항공기의 위치를 실시간으로 지도에 표시하기 위하여 Google 지도 AJAX (Asynchronous Javascript and XML) API를 이용하여 Windows Form 내부 컨트롤인 webBrowser 컨트롤에 해당 지도 페이지를 표시합니다.

[예시 4] SimConnect 클래스 인스턴스 구현 및 초기화, 사용


 
SimConnect 객체를 사용하는 방법은 위와 같은 순서로 구현합니다.
먼저, SimConnect에 대한 각 단계별 이벤트 핸들러를 구현하고 필요한 메서드들을 정의합니다.
SimConnect를 통해 받게 될 데이터 항목(예 : 항공기 위치 좌표, 고도, 속도, 방향 등)들은 이러한 항목들의 이름과 데이터 형식(data type)을 마치 하나의 데이터 세트(set)로 정의한 듯한 'DataDefinition'이라는 이름의 구조체(Structure ;struct)로 묶어모아 미리 정의한 후 이 구조체를 SimConnect에 등록하고 한 번의 연결 동안 각 데이터 항목들에 대한 데이터를 한꺼번에 수신받게 되는 원리입니다.
SimConnect 객체에 대한 인스턴스 생성 자체가 SimConnect에 대한 연결 시작 요청을 의미합니다.
따라서, 연결 시작 요청 이벤트 (SimConnect.OnRecvOpen) 핸들러 메서드에서는 SimConnect에 연결되었을 때 동작할 로직을 구현하면 됩니다.
데이터 요청 이벤트 (SimConnect.OnRecvSimobjectDataBytype) 핸들러 메서드에서는 SimConnect로부터 데이터를 수신받았을 때 동작할 로직을 구현합니다.
예를 들어, 데이터를 가시적으로 출력(디스플레이 display)하는 로직을 구현하면 됩니다.
연결 종료 요청 이벤트 (SimConnect.OnRecvClose) 핸들러 메서드에서는 SimConnect와의 연결을 종료하였을 때 동작할 로직을 구현합니다.
예외 발생 이벤트 (SimConnect.OnRecvException) 핸들러 메서드에서는 SimConnect와의 상호 작용 과정 중에서 발생되는 예외에 대한 처리 로직을 구현합니다.

[예시 5] FSX Simulator Monitor 프로그램의 전체 코드

    1 using System;

    2 using System.Collections.Generic;

    3 using System.ComponentModel;

    4 using System.Data;

    5 using System.Drawing;

    6 using System.Text;

    7 using System.Windows.Forms;

    8 

    9 using System.Runtime.InteropServices;

   10 using System.Threading;

   11 using Microsoft.FlightSimulator.SimConnect;

   12 

   13 namespace WinFSX

   14 {

   15     public partial class frmMonitor : Form

   16     {

   17         SimConnect sc = null;

   18         const int WM_USER_SIMCONNECT = 0x0402;

   19 

   20         int ResponseNo = 0;

   21         string Output = "\n\n\n\n\n\n\n\n\n\n";

   22         const string URLMap = "http://localhost:53003/GoogleMapsAjax.aspx";

   23         bool IsFirstMap = true;

   24         bool IsMapInitialized = false;

   25         int MapUpdateInterval = 5000;

   26 

   27         Thread thBrowser = null;

   28 

   29         DataDefinition1 dd1;

   30         TimeSpan tsETA;

   31 

   32         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]

   33         struct DataDefinition1

   34         {

   35             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]

   36             public string ATCID;

   37 

   38             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]

   39             public string AircraftTitle;

   40 

   41             public double Latitude;

   42             public double Longitude;

   43             public double Altitude;

   44             public double Airspeed;

   45             public double Heading;

   46             public double TotalFuelLBS;

   47             public double ETESeconds;

   48             public int WindsDirection;

   49             public int WindsVelocity;

   50             public int Temperature;

   51             public int RealismPercent;

   52         };

   53 

   54         enum DATA_DEFINITION

   55         {

   56             DataDefinition1

   57         };

   58 

   59         enum DATA_REQUESTS

   60         {

   61             REQUEST_WINFSX

   62         };

   63 

   64 

   65 

   66         #region EVENT HANDLERS

   67 

   68 

   69         void sc_OnRecvException(SimConnect sender, SIMCONNECT_RECV_EXCEPTION data)

   70         {

   71             this.DisplaySimObjectMessage("Error occured! - " + data.dwException.ToString());

   72             this.CloseConnection();

   73         }

   74 

   75         void sc_OnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data)

   76         {

   77             lblStatus.Text = "Connected";

   78             string Message = "Flight Simulator has connected. Version " + data.dwApplicationVersionMajor.ToString() + "." + data.dwApplicationVersionMinor.ToString();

   79             this.DisplaySimObjectMessage(Message);

   80         }

   81 

   82         void sc_OnRecvQuit(SimConnect sender, SIMCONNECT_RECV data)

   83         {           

   84             if (sc != null)

   85             {

   86                 sc.Dispose();

   87                 sc = null;

   88             }

   89 

   90             IsFirstMap = true;

   91 

   92             timerDisplayInfo.Enabled = false;

   93             timerStatus.Enabled = false;

   94             timerDisplayMap.Enabled = false;

   95 

   96             SetButtons(false);

   97 

   98             if (thBrowser != null)

   99             {

  100                 thBrowser.Interrupt();

  101                 thBrowser = null;

  102             }

  103 

  104             lblStatus.Text = "Not Connected";

  105             this.DisplaySimObjectMessage("Flight Simulator has disconnected.");

  106         }

  107 

  108         void sc_OnRecvSimobjectDataBytype(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)

  109         {

  110             switch ((DATA_REQUESTS)data.dwRequestID)

  111             {

  112                 case DATA_REQUESTS.REQUEST_WINFSX :

  113                     if (timerStatus.Enabled == false)

  114                     {

  115                         timerStatus.Enabled = true;

  116                     }

  117 

  118                     if (timerDisplayMap.Enabled == false)

  119                     {

  120                         timerDisplayMap.Enabled = true;

  121                     }

  122 

  123                     dd1 = (DataDefinition1)data.dwData[0];

  124 

  125                     lblTitleData.Text = "[" + dd1.ATCID + "] " + dd1.AircraftTitle;

  126                     lblLatitudeData.Text = dd1.Latitude.ToString() + " `";

  127                     lblLongitudeData.Text = dd1.Longitude.ToString() + " `";

  128                     lblAltitudeData.Text = ((int)dd1.Altitude).ToString() + " Feet / " + ((int)(dd1.Altitude * 0.3048)).ToString() + " Meter";

  129                     lblTASData.Text = ((int)dd1.Airspeed).ToString("D3") + " Knots / " + ((int)(dd1.Airspeed * 1.8)).ToString("D3") + " KM/H";

  130                     lblHDGData.Text = ((int)dd1.Heading).ToString("D3") + " `";

  131                     lblTotalFuelLBSData.Text = dd1.TotalFuelLBS.ToString("N4") + " Pounds";

  132                     lblWindsData.Text = dd1.WindsDirection.ToString() + " @ " + dd1.WindsVelocity.ToString() + " Knots";

  133                     lblTemperatureData.Text = dd1.Temperature.ToString() + " `C / " + (((dd1.Temperature) * 9 / 5) + 32).ToString() + " `F";

  134                     lblRealismData.Text = dd1.RealismPercent.ToString() + " %";

  135 

  136                     tsETA = TimeSpan.FromSeconds(dd1.ETESeconds);

  137                     lblETEData.Text = tsETA.Hours.ToString() + " H " + tsETA.Minutes.ToString() + " M";

  138 

  139                     if (IsFirstMap == true)

  140                     {

  141                         DisplayMap();

  142                         IsFirstMap = false;

  143                     }

  144 

  145                     break;

  146 

  147                 default :

  148                     this.DisplaySimObjectMessage("Unknown Request ID - " + data.dwRequestID.ToString());

  149                     break;

  150             }

  151         }

  152 

  153 

  154 

  155         #endregion

  156 

  157 

  158 

  159         public frmMonitor()

  160         {

  161             InitializeComponent();

  162         }

  163 

  164 

  165 

  166         protected override void DefWndProc(ref Message m)

  167         {

  168             if (m.Msg == WM_USER_SIMCONNECT)

  169             {

  170                 if (sc != null)

  171                 {

  172                     sc.ReceiveMessage();

  173                 }

  174             }

  175             else

  176             {

  177                 base.DefWndProc(ref m);

  178             }

  179         }

  180 

  181         private void InitializeBrowserThread()

  182         {

  183             if (thBrowser != null)

  184             {

  185                 thBrowser.Interrupt();

  186                 thBrowser = null;

  187             }

  188 

  189             thBrowser = new Thread(new ThreadStart(DisplayMap));

  190             thBrowser.Name = "MapBrowserWorker";

  191             thBrowser.IsBackground = true;

  192             thBrowser.Priority = ThreadPriority.Highest;

  193         }

  194 

  195         private void InitializeDataRequest()

  196         {

  197             if (sc == null)

  198             {

  199                 if (this.OpenConnection() == false)

  200                 {

  201                     MessageBox.Show("[ERROR] Sorry, the Monitor couldn't connect your FSX. Please retry next time.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);

  202                     return;

  203                 }

  204             }

  205 

  206             try

  207             {

  208                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "ATC ID", null, SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  209                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "Title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  210                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  211                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  212                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  213                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "Airspeed True", "knots", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  214                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "Plane Heading Degrees Magnetic", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  215                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "FUEL TOTAL QUANTITY WEIGHT", "pounds", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  216                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "GPS ETE", "seconds", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  217                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "AMBIENT WIND DIRECTION", "degrees", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  218                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "AMBIENT WIND VELOCITY", "knots", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  219                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "AMBIENT TEMPERATURE", "Celsius", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  220                 sc.AddToDataDefinition(DATA_DEFINITION.DataDefinition1, "Realism", "percent", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);

  221 

  222                 sc.RegisterDataDefineStruct<DataDefinition1>(DATA_DEFINITION.DataDefinition1);

  223             }

  224             catch (Exception ex)

  225             {

  226                 this.DisplaySimObjectMessage("[ERROR] An error occured while initializing data request in SimConnect. Please retry next time. - " + ex.Message);

  227             }

  228 

  229             timerDisplayInfo.Enabled = true;

  230         }

  231 

  232         private void CloseConnection()

  233         {

  234             this.sc_OnRecvQuit(sc, null);

  235         }

  236 

  237         private DialogResult ConfirmFormClosing()

  238         {

  239             DialogResult UserAnswer = MessageBox.Show("Would you really quit the Flight Simulator System Monitor?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

  240 

  241             return UserAnswer;

  242         }

  243 

  244         private void DisplayInformation()

  245         {

  246             if (sc != null)

  247             {

  248                 try

  249                 {

  250                     sc.RequestDataOnSimObjectType(DATA_REQUESTS.REQUEST_WINFSX, DATA_DEFINITION.DataDefinition1, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);

  251                 }

  252                 catch (Exception ex)

  253                 {

  254                     this.CloseConnection();

  255                     DisplaySimObjectMessage("[ERROR] " + ex.Message);

  256                     MessageBox.Show("Error occured!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);

  257                     return;

  258                 }

  259             }

  260         }

  261 

  262         private void DisplayMap()

  263         {

  264             if (sc == null)

  265             {

  266                 webBrowser1.Navigate(URLMap);               

  267                 return;

  268             }

  269             else

  270             {  

  271                 string AircraftInformation = "<font face=Verdana size=2><b>" + dd1.ATCID + "</b></font><br /><font face=Arial size=1>Altitude " + ((int)dd1.Altitude).ToString("N0") + " (Feet)<br />Airspeed " + ((int)dd1.Airspeed).ToString() + " (Knots) / Heading " + ((int)dd1.Heading).ToString("D3") + " `<br />Estimated Time to Enroute  " + lblETEData.Text + "</font>";               

  272                 webBrowser1.Navigate("javascript:SetPosition(" + dd1.Latitude.ToString("N6") + "," + dd1.Longitude.ToString("N6") + ");");

  273             }

  274         }

  275 

  276         private void DisplaySimObjectMessage(string Message)

  277         {

  278             ResponseNo = ResponseNo + 1;

  279             Output = Output.Substring(Output.IndexOf("\n") + 1);

  280             Output = Output + "\n" + ResponseNo.ToString() + " : [" + DateTime.Now.ToUniversalTime().ToString() + "] " + Message + "\n";

  281             txtSimConnectMessage.Text = Output;

  282             txtSimConnectMessage.Focus();

  283         }

  284 

  285         private void ClearDisplayedData()

  286         {

  287             lblTitleData.Text = "";

  288             lblLatitudeData.Text = "";

  289             lblLongitudeData.Text = "";

  290             lblAltitudeData.Text = "";

  291             lblTASData.Text = "";

  292             lblHDGData.Text = "";

  293             lblTotalFuelLBSData.Text = "";

  294             lblETEData.Text = "";

  295             lblWindsData.Text = "";

  296             lblTemperatureData.Text = "";

  297             lblRealismData.Text = "";

  298 

  299             if (webBrowser1.Url != null && webBrowser1.Url.AbsoluteUri == URLMap)

  300             {

  301                 webBrowser1.Stop();

  302                 webBrowser1.Navigate("javascript:ClearOverlays();");

  303             }

  304         }

  305 

  306         private bool OpenConnection()

  307         {

  308             bool blResult = false;

  309 

  310             if (sc == null)

  311             {

  312                 try

  313                 {

  314                     sc = new SimConnect(Application.ProductName + " - " + this.Text, this.Handle, WM_USER_SIMCONNECT, null, 0);

  315 

  316                     if (sc != null)

  317                     {

  318                         blResult = true;

  319 

  320                         sc.OnRecvException += new SimConnect.RecvExceptionEventHandler(sc_OnRecvException);

  321                         sc.OnRecvOpen += new SimConnect.RecvOpenEventHandler(sc_OnRecvOpen);

  322                         sc.OnRecvQuit += new SimConnect.RecvQuitEventHandler(sc_OnRecvQuit);

  323                         sc.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(sc_OnRecvSimobjectDataBytype);

  324                     }

  325                     else

  326                     {

  327                         blResult = false;

  328                     }

  329                 }

  330                 catch (COMException exCom)

  331                 {

  332                     this.DisplaySimObjectMessage("[ERROR] The Monitor couldn't find any Flight Simulator X process. Please confirm your Flight Simulator X is running or not.\n - " + exCom.Message);

  333                     blResult = false;

  334                 }

  335                 catch (Exception ex)

  336                 {

  337                     this.DisplaySimObjectMessage("[ERROR] " + ex.Message);

  338                     blResult = false;

  339                 }

  340             }

  341             else

  342             {

  343                 blResult = true;

  344             }

  345 

  346             this.SetButtons(blResult);

  347 

  348             return blResult;

  349         }

  350 

  351         private void SetButtons(bool IsConnected)

  352         {

  353             if (IsConnected == true)

  354             {

  355                 btnConnect.Enabled = false;

  356                 btnDisconnect.Enabled = true;

  357             }

  358             else

  359             {

  360                 btnConnect.Enabled = true;

  361                 btnDisconnect.Enabled = false;

  362 

  363                 this.ClearDisplayedData();

  364             }

  365         }

  366 

  367 

  368 

  369         private void frmMonitor_FormClosed(object sender, FormClosedEventArgs e)

  370         {

  371             if (sc != null)

  372             {

  373                 this.CloseConnection();

  374             }

  375         }

  376 

  377         private void frmMonitor_FormClosing(object sender, FormClosingEventArgs e)

  378         {

  379             if (this.ConfirmFormClosing() == DialogResult.Yes)

  380             {

  381                 this.CloseConnection();

  382                 return;

  383             }

  384             else

  385             {

  386                 e.Cancel = true;

  387             }

  388         }

  389 

  390         private void frmMonitor_Load(object sender, EventArgs e)

  391         {

  392             this.DisplaySimObjectMessage("Welcome to Flight Simulator System Monitor [Beta Test]");

  393 

  394             btnConnect.Enabled = true;

  395             btnDisconnect.Enabled = false;

  396             txtMapUpdateInterval.Text = timerDisplayMap.Interval.ToString();

  397 

  398             this.ClearDisplayedData();

  399 

  400             this.timer3_Tick(this, e);

  401         }

  402 

  403         private void frmMonitor_Resize(object sender, EventArgs e)

  404         {

  405             if (this.Width < 800)

  406             {

  407                 this.Width = 800;

  408             }

  409 

  410             if (this.Height < 600)

  411             {

  412                 this.Height = 600;

  413             }

  414 

  415             webBrowser1.Width = this.Width - 495;

  416             webBrowser1.Height = this.Height - 98;

  417             txtSimConnectMessage.Height = this.Height - 377;

  418 

  419             if (this.Width >= Screen.PrimaryScreen.WorkingArea.Width)

  420             {

  421                 this.frmMonitor_ResizeEnd(sender, e);

  422             }

  423         }

  424 

  425         private void frmMonitor_ResizeEnd(object sender, EventArgs e)

  426         {

  427             if (IsMapInitialized == true)

  428             {

  429                 webBrowser1.Navigate("javascript:SetMapSize(" + (webBrowser1.Width - 30).ToString() + "," + (webBrowser1.Height - 30).ToString() + ");");

  430             }

  431         }

  432 

  433         private void timer1_Tick(object sender, EventArgs e)

  434         {

  435             if (sc != null)

  436             {

  437                 this.DisplayInformation();

  438             }

  439         }

  440 

  441         private void timer2_Tick(object sender, EventArgs e)

  442         {

  443             if (lblStatus.Text == "")

  444             {

  445                 lblStatus.Text = "Receiving...";

  446             }

  447             else

  448             {

  449                 lblStatus.Text = "";

  450             }

  451 

  452             if (txtMapUpdateInterval.Focused == false)

  453             {

  454                 txtMapUpdateInterval.Text = timerDisplayMap.Interval.ToString();

  455             }

  456         }

  457 

  458         private void timer3_Tick(object sender, EventArgs e)

  459         {

  460             InitializeBrowserThread();

  461             thBrowser.Start();

  462         }

  463 

  464         private void timer4_Tick(object sender, EventArgs e)

  465         {

  466             lblGMT.Text = DateTime.Now.ToUniversalTime().Hour.ToString("D2") + ":" + DateTime.Now.ToUniversalTime().Minute.ToString("D2") + "." + DateTime.Now.ToUniversalTime().Second.ToString("D2");

  467         }

  468 

  469         private void btnConnect_Click(object sender, EventArgs e)

  470         {

  471             this.InitializeDataRequest();

  472         }

  473 

  474         private void btnDisconnect_Click(object sender, EventArgs e)

  475         {

  476             DialogResult UserAnswer = MessageBox.Show("Would you really disconnect?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

  477 

  478             if (UserAnswer == DialogResult.Yes)

  479             {

  480                 this.CloseConnection();

  481             }

  482 

  483             return;

  484         }

  485 

  486         private void btnClose_Click(object sender, EventArgs e)

  487         {

  488             this.Close();

  489         }

  490 

  491         private void btnClear_Click(object sender, EventArgs e)

  492         {

  493             txtSimConnectMessage.Clear();

  494         }

  495 

  496         private void chkAlwaysOnTop_CheckedChanged(object sender, EventArgs e)

  497         {

  498             if (chkAlwaysOnTop.Checked == true)

  499             {

  500                 this.TopMost = true;

  501             }

  502             else

  503             {

  504                 this.TopMost = false;

  505             }

  506         }

  507 

  508         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

  509         {           

  510             if (IsFirstMap == true)

  511             {

  512                 if (webBrowser1.ReadyState == WebBrowserReadyState.Complete && webBrowser1.Url.AbsoluteUri == URLMap)

  513                 {

  514                     IsMapInitialized = true;

  515                     btnConnect.Enabled = true;

  516 

  517                     webBrowser1.Navigate("javascript:SetMapSize(" + (webBrowser1.Width - 30).ToString() + "," + (webBrowser1.Height - 30).ToString() + ");");

  518                 }

  519                 else

  520                 {

  521                     IsFirstMap = true;

  522                     IsMapInitialized = false;

  523                     btnConnect.Enabled = false;

  524 

  525                     this.DisplaySimObjectMessage("[MAP BROWSER] Unable to initialize the map. Please exit and run this application again or retry. - " + webBrowser1.ReadyState.ToString() + " : " + webBrowser1.Url.ToString() + " :: " + webBrowser1.StatusText);

  526                 }

  527             }

  528 

  529             this.DisplaySimObjectMessage("[MAP BROWSER] " + webBrowser1.ReadyState.ToString() + " : " + webBrowser1.Url.ToString() + " :: " + webBrowser1.StatusText);

  530         }

  531 

  532         private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)

  533         {

  534             this.DisplaySimObjectMessage("[MAP BROWSER] " + webBrowser1.ReadyState.ToString() + " : " + webBrowser1.Url.ToString() + " :: " + webBrowser1.StatusText);           

  535         }

  536 

  537         private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)

  538         {

  539             if (IsFirstMap == true)

  540             {

  541                 if (IsMapInitialized == false)

  542                 {

  543                     btnConnect.Enabled = false;

  544                 }

  545                 else

  546                 {

  547                     btnConnect.Enabled = true;

  548                 }

  549             }

  550 

  551             // this.DisplaySimObjectMessage("[MAP BROWSER] " + webBrowser1.ReadyState.ToString() + " : " + webBrowser1.Url.ToString() + " :: " + webBrowser1.StatusText);

  552         }

  553 

  554         private void txtMapUpdateInterval_Enter(object sender, EventArgs e)

  555         {

  556             btnSetInterval_Click(sender, e);

  557         }  

  558 

  559         private void txtMapUpdateInterval_Leave(object sender, EventArgs e)

  560         {

  561             txtMapUpdateInterval_Enter(sender, e);

  562         }

  563 

  564         private void txtMapUpdateInterval_TextChanged(object sender, EventArgs e)

  565         {

  566 

  567         }

  568 

  569         private void btnSetInterval_Click(object sender, EventArgs e)

  570         {

  571             if (int.TryParse(txtMapUpdateInterval.Text, out MapUpdateInterval) == true)

  572             {

  573                 if (MapUpdateInterval < 1000)

  574                 {

  575                     MapUpdateInterval = 1000;

  576                 }

  577                 else

  578                 {

  579                     MapUpdateInterval = int.Parse(txtMapUpdateInterval.Text);

  580                 }

  581             }

  582             else

  583             {

  584                 MapUpdateInterval = 10000;

  585             }

  586 

  587             timerDisplayMap.Interval = MapUpdateInterval;

  588 

  589             txtMapUpdateInterval.Text = MapUpdateInterval.ToString();

  590         }

  591     }

  592 }

 

 


 

문서 키워드
Keywords for this Document
Microsoft .NET, C#, Windows Form, Microsoft ESP, Flight Simulator X, SimConnect, SDK (Software Development Kit), Visual Studio, Google Maps API, AJAX, API, 닷넷, 윈도우 프로그래밍, 윈폼, 플라이트 시뮬레이터, 개발, 소프트웨어개발키트, 비주얼스튜디오, 구글 지도 (구글 맵) API
  • 작성자 / 게시자 주소 Publisher URL : Essayer (http://www.essayer7.com)
  • 문서언어 Language : 한국어 Korean
  • 문서일자 : 2009년 03월 25일 (대한민국 표준시 GMT+09:00)
  • 문서버전 : 1.0.1556
  • 적용범위 : Microsoft ESP SDK / Flight Simulator X SimConnect SDK를 이용한 개발, Microsoft .NET C#, Microsoft Visual Studio 2005
  • 저작권 정보 :
    - 본 문서의 작성 권한 및 저작권은 작성자에게 있습니다.
    - 본 문서의 일부 내용은 미국 Microsoft 사에서 제공한 자료를 참고하여 작성되었습니다.
    - 본 문서에 일부 사용, 인용된 기술적, 문헌적 내용에 대한 저작권은 미국 Microsoft Corporation에게 있습니다.
  • 본 문서에 대한 의견 및 잘못된 정보에 대한 이의 제기 사항 등 여러분의 의견을 제안해주시기 바랍니다.
    게시자는 여러분의 의견을 소중하게 생각합니다.
    이의 제기를 할 경우에는 보다 정확한 정보 제공을 위해 객관적 근거 자료를 제시하면서 제기하여 주실 것을 권장합니다.
  • 본 문서에 사용된 일부 요소(이미지, 사운드, 동영상, 기타 첨부 문서 등)의 저작권은 해당 저작권자가 소유하고 있습니다.
    따라서, 문서의 무단 복제 및 전제, 변형 게시를 금지하며 이런 행위로 인해 발생되는 모든 법적 불이익 및 사건에 대한 모든 책임은 무단 행위자 본인에게 있음을 알려드립니다.

Copyright© 2008-2009 Some rights reserved. 일부 권한 소유. 무단 복사 및 수정 금지 / 출처 명시 없는 재배포 금지

Posted by Essayer

Trackback URL :: http://www.essayer7.com/trackback/123 관련글 쓰기