Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Search Results for "DEVMODE" in [All]

comdlg32

.

        _pdex.hDevMode = prnsettings.GetHdevmode()

.

    Public hDevMode As IntPtr

.

    Public Const PD_USEDEVMODECOPIES As Int32 = 262144

.

    Public Const PD_USEDEVMODECOPIESANDCOLLATE As Int32 = 262144

.

        _pdex.hDevMode = prnsettings.GetHdevmode()

.

    Public hDevMode As IntPtr

.

    Public Const PD_USEDEVMODECOPIES As Int32 = 262144

.

    Public Const PD_USEDEVMODECOPIESANDCOLLATE As Int32 = 262144

user32

.

static extern DISP_CHANGE ChangeDisplaySettingsEx(string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, ChangeDisplaySettingsFlags dwflags, IntPtr lParam);

.

Private Shared Function ChangeDisplaySettingsEx(ByVal lpszDeviceName As String, ByRef lpDevMode As DEVMODE, ByVal hwnd As IntPtr, ByVal dwflags As UInteger, ByVal lParam As IntPtr) As DISP_CHANGE

.

DEVMODE

.

To change the postion of a secondary device it is very important to use dmPositionX and dmPositionY from DEVMODE (see structs).

.

DEVMODE dm = new DEVMODE();

.

static extern bool EnumDisplaySettingsEx(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode, uint dwFlags);

.

Private Shared Function EnumDisplaySettingsEx(ByVal lpszDeviceName As String, ByVal iModeNum As UInteger, ByRef lpDevMode As DEVMODE, ByVal dwFlags As UInteger) As Boolean

.

DEVMODE

.

static extern bool EnumDisplaySettingsEx(string lpszDeviceName, uint iModeNum, out DEVMODE lpDevMode, uint dwFlags);

.

Private Shared Function EnumDisplaySettingsEx(ByVal lpszDeviceName As String, ByVal iModeNum As UInteger, ByRef lpDevMode As DEVMODE, ByVal dwFlags As UInteger) As Boolean

.

DEVMODE

winspool

.

static extern int DocumentProperties(IntPtr hwnd, IntPtr hPrinter, [MarshalAs(UnmanagedType.LPWStr)] string pDeviceName, IntPtr pDevModeOutput, IntPtr pDevModeInput, int fMode);

.

static extern int DocumentProperties(IntPtr hWnd, IntPtr hPrinter, string pDeviceName, IntPtr pDevModeOutput, IntPtr pDevModeInput, fModes fMode);

.

    Private Shared Function DocumentProperties(ByVal hwnd As IntPtr, ByVal hPrinter As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal pDeviceName As String, ByVal pDevModeOutput As IntPtr, ByVal pDevModeInput As IntPtr, ByVal fMode As Integer) As Integer

.

Doesn't work on a x64 system. (i.e. this declaration is wrong for x64, I'm just not quite sure why.). MH:I tested the code extensivly and I think the param "IntPtr pDevModeInput" must not have the "ref" flag. If it has the initial state of the dialog is wrong. EP: Yup, you're right! Thanks!!! I've been trying to figure out why it doesn't work on some drivers for a few weeks now! "ref" removed.

.

"DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, pDevMode, pDevMode, 0);" returns -1 and error code 183 under x64 however i dnt knw y!

.

in order to get it working use "DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, IntPtr.Zero, pDevMode, 0);"

.

Obtain a pointer to the DEVMODE struct (either printerHandle or printerName can be NULL | IntPtr.ZERO):

.

public IntPtr GetDevMode(IntPtr printerHandle, string printerName)

.

   IntPtr pdevmode = Marshal.AllocHGlobal(sizeNeeded);

.

   int result = DocumentProperties(IntPtr.Zero, printerHandle, printerName, pdevmode, IntPtr.Zero, fModes.DM_OUT_BUFFER);

.

   return pdevmode;

.

        IntPtr hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);

.

        IntPtr pDevMode = GlobalLock(hDevMode);

.

        int sizeNeeded = DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, pDevMode, pDevMode, 0);

.

        IntPtr devModeData = Marshal.AllocHGlobal(sizeNeeded);

.

        DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, devModeData, pDevMode, 14);

.

        GlobalUnlock(hDevMode);

.

        printerSettings.SetHdevmode(devModeData);

.

        printerSettings.DefaultPageSettings.SetHdevmode(devModeData);

.

        GlobalFree(hDevMode);

.

        Marshal.FreeHGlobal(devModeData);

.

        IntPtr hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);

.

        IntPtr pDevMode = GlobalLock(hDevMode);

.

        int sizeNeeded = DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, pDevMode, pDevMode, 0);

.

        IntPtr devModeData = Marshal.AllocHGlobal(sizeNeeded);

.

        DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, IntPtr.Zero, pDevMode, 14);

.

        GlobalUnlock(hDevMode);

.

        printerSettings.SetHdevmode(devModeData);

.

        printerSettings.DefaultPageSettings.SetHdevmode(devModeData);

.

        GlobalFree(hDevMode);

.

        Marshal.FreeHGlobal(devModeData);

.

        IntPtr hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);

.

        IntPtr pDevMode = GlobalLock(hDevMode);

.

        int sizeNeeded = DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, IntPtr.Zero, pDevMode, 0);

.

        IntPtr devModeData = Marshal.AllocHGlobal(sizeNeeded);

.

        DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, IntPtr.Zero, pDevMode, 14);

.

        GlobalUnlock(hDevMode);

.

        printerSettings.SetHdevmode(devModeData);

.

        printerSettings.DefaultPageSettings.SetHdevmode(devModeData);

.

        GlobalFree(hDevMode);

.

        Marshal.FreeHGlobal(devModeData);

.

I had to fixed Matthias solution, because it doesn't work well for me. Exception is no more occurs, but when some setting is changed in printer properties it isn't used by printer. I've changed second call of DocumentProperties method. The third-from-last paramter MUST be in this case devModeData.

.

        IntPtr hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);

.

        IntPtr pDevMode = GlobalLock(hDevMode);

.

        int sizeNeeded = DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, IntPtr.Zero, pDevMode, 0);

.

        IntPtr devModeData = Marshal.AllocHGlobal(sizeNeeded);

.

        DocumentProperties(this.Handle, IntPtr.Zero, printerSettings.PrinterName, devModeData, pDevMode, 14);

.

        GlobalUnlock(hDevMode);

.

        printerSettings.SetHdevmode(devModeData);

.

        printerSettings.DefaultPageSettings.SetHdevmode(devModeData);

.

        GlobalFree(hDevMode);

.

        Marshal.FreeHGlobal(devModeData);

.

I believe the issue(s) discussed re:x64 is actually an odd idiosyncracy under Windows Server 2008 R2 x64, but is not a x86/x64 problem per se. At least testing this under Win7 x64, I have no issues. However, under W2K8 x64, the OutBuffer and InBuffer must NOT be the same (in Win7 x64 this works OK). ALSO, the call to set doc properties with fMode = 14 (Prompt | In | Out) and OutBuffer = IntPtr.Zero CANNOT possibly correct, as in this case there is no place to put the resulting Devmode. Good code shouldn't use "magic numbers" anyway. The following values from WinSpool.h should be used instead of "14" or "0" for the last parameter in this call:

.

Agreed that the use of a IntPrt.Zero where a recipient data structure is expected looks wrong, but it should be ok in this case: that first call to DocumentProperties does not attempt to save any data to the DevMode structure, it just returns the size of memory necessary to hold all the devModeData held by the printer driver, nothing else.

.

     Defaults.pDevMode = 0;

gdi32

.

    private static extern IntPtr CreateDC(string lpszDriver, string lpszDeviceName, string lpszOutput, IntPtr devMode);

.

in Pointer to a DEVMODE structure containing device-specific initialization data for the device driver. The DocumentProperties function retrieves this structure filled in for a specified device. The lpdvmInit parameter must be NULL if the device driver is to use the default initialization (if any) specified by the user.

Constants

10: WM
.
WM_DEVMODECHANGE 0x1B The WM_DEVMODECHANGE message is sent to all top-level windows whenever the user changes device-mode settings.
.

private const UInt32 WM_DEVMODECHANGE      = 0x001B;

.

   WM_DEVMODECHANGE = &H1B

.

WM_DEVMODECHANGE      equ 01Bh

coredll

.

static extern int ChangeDisplaySettingsEx(string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, int dwflags, IntPtr lParam);

.

public struct DEVMODE

.

Declare Function ChangeDisplaySettingsEx Lib "coredll.dll" (ByVal lpszDeviceName As String, ByVal lpDevMode As Byte(), ByVal hwnd As IntPtr, ByVal dwflags As CDSFlags, ByVal lParam As IntPtr) As CDSRet

.

        ref DEVMODE lpDevMode, IntPtr hwnd, int dwflags, IntPtr lParam);

.

    private struct DEVMODE

.

        DEVMODE devmode = new DEVMODE();

.

        devmode.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));

.

        DEVMODE DevM2 = new DEVMODE();

.

        devmode.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));

.

        devmode.dmFields = 0x00800000; // query/set actual rotation modes

.

        ChangeDisplaySettingsEx(null, ref devmode, IntPtr.Zero, 2, IntPtr.Zero); // 2 = test

.

        MessageBox.Show("Current: " + devmode.dmDisplayOrientation.ToString());

.

        devmode.dmFields = 0x00800000; // query/set actual rotation modes

.

        devmode.dmDisplayOrientation = (devmode.dmDisplayOrientation == 0) ? 1 : 0; //switch between 0, 90 rotation

.

        ChangeDisplaySettingsEx(null, ref devmode, IntPtr.Zero, 0, IntPtr.Zero); // 0 = set

.

    Friend Shared Function ChangeDisplaySettingsEx(ByVal lpszDeviceName As String, ByVal lpDevMode As Byte(), ByVal hwnd As IntPtr, ByVal dwflags As CDSFlags, ByVal lParam As IntPtr) As CDSRet

.

        Dim devMode As New devicemodeW()

.

        devMode.dmFields = DM_Fields.DM_DISPLAYORIENTATION

.

        devMode.dmDisplayOrientation = DMD.DMDO_0

.

        devMode.dmDisplayOrientation = DMD.DMDO_90

.

        devMode.dmDisplayOrientation = DMD.DMDO_180

.

        devMode.dmDisplayOrientation = DMD.DMDO_270

.

        Dim ret As CDSRet = ChangeDisplaySettingsEx(Nothing, devMode.Data, IntPtr.Zero, 0, IntPtr.Zero)

Structures

.

struct DEVMODE

.

Public Structure DEVMODE

.

Since the DEVMODE members beyond dmDisplayFrequency do not have to be declared, the structure can vary in size. You should set dmSize to effective size of your implemetation before calling API functions:

.

DEVMODE d = new DEVMODE();

.

d.dmSize = Marshal.SizeOf(typeof(DEVMODE));

.

This way the API is informed of the version of DEVMODE used.

.

As of .net 3.5 the DEVMODE structure is declared incorrectly causing incorrect values to be returned after dmBitsPerPel. The structures above have been updated to reflect the correct implementation.

.

This code (taken from .NET source code) is working with System.Drawing.Printing.PrinterSettings.Gethdevmode, where default structure doesn't work for me.

.

  devMode = (DEVMODE)Marshal.PtrToStructure(pDevMode, typeof(DEVMODE));

.

  devMode.dmSize = (short)Marshal.SizeOf(devMode);

.

  int isize = GlobalSize(hDevMode).ToInt32() - (int)devMode.dmSize;

.

  devMode.dmDriverExtra = Convert.ToInt16(isize);

.
Documentation
[DEVMODE] on MSDN
.

   public short tdExtDevmodeOffset;

.

   public IntPtr hDevMode;

.

    Public hDevMode As IntPtr

.

    public IntPtr hDevMode;

.

   public IntPtr pDevMode;

.

   /// Pointer to a DEVMODE structure that identifies the

.

   public IntPtr pDevMode;

.

   Public pDevMode As IntPtr

.

        public IntPtr pDevMode;

.

        Public pDevMode As IntPtr

.

If you only want to get or set the DEVMODE struct, you can use the PRINTER_INFO_9 struct instead.

.
Summary
.

   /// A pointer to a DEVMODE structure that defines the per-user

.

   /// The DEVMODE is stored in the user's registry.

.

   public IntPtr pDevMode;

Enums

.

        /// Returns the dmFields member of the printer driver's DEVMODE structure. The dmFields member indicates which members in the device-independent portion of the structure are supported by the printer driver.

.

        /// Retrieves a list of supported paper sizes. The pOutput buffer receives an array of WORD values that indicate the available paper sizes for the printer. The return value indicates the number of entries in the array. For a list of the possible array values, see the description of the dmPaperSize member of the DEVMODE structure. If pOutput is NULL, the return value indicates the required number of entries in the array.

.

        /// Returns the minimum paper size that the dmPaperLength and dmPaperWidth members of the printer driver's DEVMODE structure can specify. The LOWORD of the return value contains the minimum dmPaperWidth value, and the HIWORD contains the minimum dmPaperLength value.

.

        /// Returns the maximum paper size that the dmPaperLength and dmPaperWidth members of the printer driver's DEVMODE structure can specify. The LOWORD of the return value contains the maximum dmPaperWidth value, and the HIWORD contains the maximum dmPaperLength value.

.

        /// Retrieves a list of available paper bins. The pOutput buffer receives an array of WORD values that indicate the available paper sources for the printer. The return value indicates the number of entries in the array. For a list of the possible array values, see the description of the dmDefaultSource member of the DEVMODE structure. If pOutput is NULL, the return value indicates the required number of entries in the array.

.

        /// Returns the dmSize member of the printer driver's DEVMODE structure.

.

        /// Returns the number of bytes required for the device-specific portion of the DEVMODE structure for the printer driver.

.

        /// Retrieves a list of supported media types. The pOutput buffer receives an array of DWORD values that indicate the supported media types. The return value indicates the number of entries in the array. For a list of possible array values, see the description of the dmMediaType member of the DEVMODE structure. If pOutput is NULL, the return value indicates the required number of entries in the array. Windows 2000:  This flag is not supported.

20: DM
.
Summary
.
Summary
.
Summary
23: DMDUP
.
Summary
24: fModes
.

   /// of bytes required by the printer driver's DEVMODE data structure.

.

   /// including private data, to the DEVMODE data structure specified by the

.

   /// pDevModeOutput parameter. The caller must allocate a buffer sufficiently large

.

   /// If the bit DM_OUT_BUFFER sets is clear, the pDevModeOutput parameter can be NULL.

.

   /// sheet and then changes the settings in the printer's DEVMODE data structure

.

   /// the printer driver's current print settings with the settings in the DEVMODE

.

   /// structure specified by the pDevModeInput parameter.

.

   /// DEVMODE structure's dmFields member.

.

   /// In cases of conflict during the merge, the settings in the DEVMODE structure

.

   /// specified by pDevModeInput override the printer driver's current print settings.

.

    /// The WM_DEVMODECHANGE message is sent to all top-level windows whenever the user changes device-mode settings.

.

    DEVMODECHANGE = 0x001B,

.

    '''The WM_DEVMODECHANGE message is sent to all top-level windows whenever the user changes device-mode settings.

.

    WM_DEVMODECHANGE = &H1B

.

    WmDevmodeChange = &H1B


 
Access PInvoke.net directly from VS: