Z
zengou
MSDN:
BOOL EnumDisplaySettings(
LPCTSTR lpszDeviceName, // display device
DWORD iModeNum, // graphics mode
LPDEVMODE lpDevMode // graphics mode settings
);
typedef struct _devicemode {
BCHAR dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
union {
struct {
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
};
POINTL dmPosition;
DWORD dmDisplayOrientation;
DWORD dmDisplayFixedOutput;
};
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
BYTE dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
union {
DWORD dmDisplayFlags;
DWORD dmNup;
}
DWORD dmDisplayFrequency;
#if(WINVER >= 0x0400)
DWORD dmICMMethod;
DWORD dmICMIntent;
DWORD dmMediaType;
DWORD dmDitherType;
DWORD dmReserved1;
DWORD dmReserved2;
#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
DWORD dmPanningWidth;
DWORD dmPanningHeight;
#endif
#endif /* WINVER >= 0x0400 */
} DEVMODE;
I Have this C# code:
[DllImport("user32.dll",
EntryPoint="EnumDisplaySettingsA")]
public static extern bool EnumDisplaySettings (
string lpszDeviceName,
Int32 iModeNum,
ref DEVMODE lpDevMode);
[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE
{
//[ MarshalAs( UnmanagedType.LPStr)]
public string dmDeviceName;
public int dmSpecVersion;
public int dmDriverVersion;
public int dmSize;
public int dmDriverExtra;
public int dmFields;
public int dmOrientation;
public int dmPaperSize;
public int dmPaperLength;
public int dmPaperWidth;
public int dmScale;
public int dmCopies;
public int dmDefaultSource;
public int dmPrintQuality;
public int dmColor;
public int dmDuplex;
public int dmYResolution;
public int dmTTOption;
public int dmCollate;
//[ MarshalAs( UnmanagedType.LPStr)]
public string dmFormName;
public int dmUnusedPadding;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
}
private void button1_Click(object sender,
System.EventArgs e)
{
DEVMODE DevM=new DEVMODE();
bool mybool;
mybool=EnumDisplaySettings("", 0,ref DevM);
MessageBox.Show(result.ToString()
+DevM.dmPelsWidth.ToString()+DevM.dmPelsHeight.ToString
());
}
But the MessageBox return mybool=false!!
I don't know where I make mistake???
BOOL EnumDisplaySettings(
LPCTSTR lpszDeviceName, // display device
DWORD iModeNum, // graphics mode
LPDEVMODE lpDevMode // graphics mode settings
);
typedef struct _devicemode {
BCHAR dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
union {
struct {
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
};
POINTL dmPosition;
DWORD dmDisplayOrientation;
DWORD dmDisplayFixedOutput;
};
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
BYTE dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
union {
DWORD dmDisplayFlags;
DWORD dmNup;
}
DWORD dmDisplayFrequency;
#if(WINVER >= 0x0400)
DWORD dmICMMethod;
DWORD dmICMIntent;
DWORD dmMediaType;
DWORD dmDitherType;
DWORD dmReserved1;
DWORD dmReserved2;
#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
DWORD dmPanningWidth;
DWORD dmPanningHeight;
#endif
#endif /* WINVER >= 0x0400 */
} DEVMODE;
I Have this C# code:
[DllImport("user32.dll",
EntryPoint="EnumDisplaySettingsA")]
public static extern bool EnumDisplaySettings (
string lpszDeviceName,
Int32 iModeNum,
ref DEVMODE lpDevMode);
[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE
{
//[ MarshalAs( UnmanagedType.LPStr)]
public string dmDeviceName;
public int dmSpecVersion;
public int dmDriverVersion;
public int dmSize;
public int dmDriverExtra;
public int dmFields;
public int dmOrientation;
public int dmPaperSize;
public int dmPaperLength;
public int dmPaperWidth;
public int dmScale;
public int dmCopies;
public int dmDefaultSource;
public int dmPrintQuality;
public int dmColor;
public int dmDuplex;
public int dmYResolution;
public int dmTTOption;
public int dmCollate;
//[ MarshalAs( UnmanagedType.LPStr)]
public string dmFormName;
public int dmUnusedPadding;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
}
private void button1_Click(object sender,
System.EventArgs e)
{
DEVMODE DevM=new DEVMODE();
bool mybool;
mybool=EnumDisplaySettings("", 0,ref DevM);
MessageBox.Show(result.ToString()
+DevM.dmPelsWidth.ToString()+DevM.dmPelsHeight.ToString
());
}
But the MessageBox return mybool=false!!
I don't know where I make mistake???