0

다양한 장치와 에뮬레이터를 서로 다른 해상도로 작업 할 수있는 응용 프로그램을 개발 중이므로 실제 장치인지 에뮬레이터인지 알 수있는 코드가 있습니다. 올바른 해상도로 응용 프로그램을 표시하기 위해 어떤 에뮬레이터 (모델, 유형)가 실행되고 있는지 확인하십시오.사용중인 에뮬레이터의 모델을 프로그래밍 방식으로 얻는 방법

사실 나는 "에뮬레이터"값 또는 장치 모델의 문자열을 반환하는 코드 메서드 GetOemInfo()를 사용하고 있습니다.이 코드에서는 에뮬레이터가 무엇인지 알지 못합니다.

private static string GetOemInfo() 
    { 
     string oemInfo = new string(' ', 50); 
     int result = SystemParametersInfo(SPI_GETOEMINFO, 50, oemInfo, 0); 
     oemInfo = oemInfo.Substring(0, oemInfo.IndexOf('\0')); 
     return oemInfo; 
    } 

답변

0

화면 크기를 얻을 수있는 방법은 몇 가지가 있습니다.

가장 완벽한 방법은 SystemMetrics이며 "coredll.dll"에서 P/호출해야합니다.

[DllImport("coredll.dll")] 
public static extern int GetSystemMetrics(SYSTEM_METRICS nIndex); 

다음과 같이 열거 형식을 만들려면 다음 다음과 같이이 프레임 워크와

public enum SYSTEM_METRICS : int 
{ 
    SM_CXSCREEN = 0, 
    SM_CYSCREEN = 1, 
    SM_CXVSCROLL = 2, 
    SM_CYHSCROLL = 3, 
    SM_CYCAPTION = 4, 
    SM_CXBORDER = 5, 
    SM_CYBORDER = 6, 
    SM_CXDLGFRAME = 7, 
    SM_CYDLGFRAME = 8, 
    SM_CXICON = 11, 
    SM_CYICON = 12, 
    SM_CYMENU = 15, 
    SM_CXFULLSCREEN = 16, 
    SM_CYFULLSCREEN = 17, 
    SM_MOUSEPRESENT = 19, 
    SM_CYVSCROLL = 20, 
    SM_CXHSCROLL = 21, 
    SM_DEBUG = 22, 
    SM_CXDOUBLECLK = 36, 
    SM_CYDOUBLECLK = 37, 
    SM_CXICONSPACING = 38, 
    SM_CYICONSPACING = 39, 
    SM_CXEDGE = 45, 
    SM_CYEDGE = 46, 
    SM_CXSMICON = 49, 
    SM_CYSMICON = 50, 
    SM_XVIRTUALSCREEN = 76, 
    SM_YVIRTUALSCREEN = 77, 
    SM_CXVIRTUALSCREEN = 78, 
    SM_CYVIRTUALSCREEN = 79, 
    SM_CMONITORS = 80, 
    SM_SAMEDISPLAYFORMAT = 81, 
    SM_CXFIXEDFRAME = 7, 
    SM_CYFIXEDFRAME = 8 
} 

모든 설정하면, 당신은 단순히 예를 들어 폭을 얻을 수 있습니다 :

int screenWidth = GetSystemMetrics(SYSTEM_METRICS.SM_CXSCREEN); 
Console.WriteLine(String.Format("Screen X-res is {0}", screenWidth)); 

게으르 길 원한다면, 프로젝트가로드되었을 때 메인 폼의 너비와 높이를 읽는 것만 큼 간단한 해결책이 될 것입니다.

물론 폼을 조정하기 전에 너비와 높이를 읽는 것이 분명히 화면에 깜박일 것입니다.

+0

고마워요 @ jp2code, 그게 내가 왜 게으름에 의해 :) 필요하지만 솔루션의 단순함 덕분에! – igarcia

0

에뮬레이터에는 특히 내가 원하는 것을 제공하는 "OEM 정보"가 없습니다. OS 버전, 화면 해상도 및 일부 API의 가용성 여부를 확인하여 추론해야합니다 (Pro 대 Standard 타겟을 차별화하려는 경우).

+0

@ctacke에 답해 주셔서 감사합니다. 화면 해상도 나 이와 유사한 내용을 확인하는 데 사용할 수있는 항목이 있습니까? – igarcia

0

화면 크기가 전부가 아니라면, 여기에 내가 장치 정보를 얻는 데 사용하는 방법이 있습니다. 그것은 레지스트리에서 일부 데이터를 읽고 일부 데이터는 ... 글쎄, 당신은 볼 수 있습니다.

private static string getName() { 
    string name = null; 
    using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Ident", true)) { 
    var name = key.GetValue("Name", [Unnamed]) as string; 
    } 
    if (String.IsNullOrEmpty(name)) { 
    name = getDeviceID(); 
    } 
    return name; 
} 

그래서, 지금 당신은 내 getDeviceID()이 필요합니다. 응. 승인.

private const string COREDLL = "coredll.dll"; 
[DllImport(COREDLL)] 
private static extern bool KernelIoControl(Int32 IoControlCode, IntPtr InputBuffer, Int32 InputBufferSize, byte[] OutputBuffer, Int32 OutputBufferSize, ref Int32 BytesReturned); 

private static string getDeviceID() { 
    // Reference: http://msdn.microsoft.com/en-us/library/aa446562.aspx 
    byte[] data = new byte[256]; 
    Int32 OutputBufferSize = data.Length; 
    Int32 BytesReturned = 0; 
    // Call KernelIoControl passing the previously defined IOCTL_HAL_GET_DEVICEID parameter 
    // We don’t need to pass any input buffers to this call 
    // so InputBuffer and InputBufferSize are set to their null values 
    bool retVal = KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, data, OutputBufferSize, ref BytesReturned); 
    // If the request failed, exit the method now 
    if (retVal) { 
    // Examine the OutputBuffer byte array to find the start of the 
    // Preset ID and Platform ID, as well as the size of the PlatformID. 
    // PresetIDOffset – The number of bytes the preset ID is offset from the beginning of the structure 
    // PlatformIDOffset - The number of bytes the platform ID is offset from the beginning of the structure 
    // PlatformIDSize - The number of bytes used to store the platform ID 
    // Use BitConverter.ToInt32() to convert from byte[] to int 
    Int32 PresetIDOffset = BitConverter.ToInt32(data, 4); 
    Int32 PlatformIDOffset = BitConverter.ToInt32(data, 0xc); 
    Int32 PlatformIDSize = BitConverter.ToInt32(data, 0x10); 

    // Convert the Preset ID segments into a string so they can be 
    // displayed easily. 
    StringBuilder sb = new StringBuilder(); 
    sb.Append(String.Format("{0:X8}-{1:X4}-{2:X4}-{3:X4}-", 
     BitConverter.ToInt32(data, PresetIDOffset), 
     BitConverter.ToInt16(data, PresetIDOffset + 4), 
     BitConverter.ToInt16(data, PresetIDOffset + 6), 
     BitConverter.ToInt16(data, PresetIDOffset + 8))); 

    // Break the Platform ID down into 2-digit hexadecimal numbers 
    // and append them to the Preset ID. This will result in a 
    // string-formatted Device ID 
    for (int i = PlatformIDOffset; i < PlatformIDOffset + PlatformIDSize; i++) { 
     sb.Append(String.Format("{0:X2}", data[i])); 
    } 
    // return the Device ID string 
    return sb.ToString(); 
    } 
    return null; 
}