当前位置: 首页>>代码示例>>C#>>正文


C# PrinterSettings.GetHdevmode方法代码示例

本文整理汇总了C#中System.Drawing.Printing.PrinterSettings.GetHdevmode方法的典型用法代码示例。如果您正苦于以下问题:C# PrinterSettings.GetHdevmode方法的具体用法?C# PrinterSettings.GetHdevmode怎么用?C# PrinterSettings.GetHdevmode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Printing.PrinterSettings的用法示例。


在下文中一共展示了PrinterSettings.GetHdevmode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveDevmode

        //Grabs the devmode data in memory and stores in arraylist
        /// <summary>
        /// Сохранение в файл или в массив байт (mode = 1 - в файл/ mode=2 - в массив)
        /// </summary>
        /// <param name="printerSettings"></param>
        /// <param name="mode"></param>
        /// <param name="Filename"></param>
        public byte[] SaveDevmode(PrinterSettings printerSettings, int mode, String Filename)
        {
            ///int mode
            ///1 = Save devmode structure to file
            ///2 = Save devmode structure to Byte array and arraylist
            IntPtr hDevMode = IntPtr.Zero;                        // handle to the DEVMODE
            IntPtr pDevMode = IntPtr.Zero;                          // pointer to the DEVMODE
            IntPtr hwnd = ((Form)_controller).Handle;

            byte[] DevModeArray = null;

            try
            {
                // Get a handle to a DEVMODE for the default printer settings
                hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);
                // Obtain a lock on the handle and get an actual pointer so Windows won't
                // move it around while we're futzing with it
                pDevMode = GlobalLock(hDevMode);
                int sizeNeeded = DocumentProperties(hwnd, IntPtr.Zero, printerSettings.PrinterName, IntPtr.Zero, pDevMode, 0);
                if (sizeNeeded <= 0)
                {
                    MessageBox.Show("Devmode Bummer, Cant get size of devmode structure");
                    GlobalUnlock(hDevMode);
                    GlobalFree(hDevMode);
                    return null;
                }

                DevModeArray = new byte[sizeNeeded];    //Copies the buffer into a byte array
                if (mode == 1)  //Save devmode structure to file
                {
                    FileStream fs = new FileStream(Filename, FileMode.Create);
                    for (int i = 0; i < sizeNeeded; ++i)
                    {
                        fs.WriteByte(Marshal.ReadByte(pDevMode, i));
                    }
                    fs.Close();
                    fs.Dispose();
                }
                if (mode == 2)  //Save devmode structure to Byte array and arraylist
                {
                    for (int i = 0; i < sizeNeeded; ++i)
                    {
                        DevModeArray[i] = (byte)(Marshal.ReadByte(pDevMode, i));
                        //Copies the array to an arraylist where it can be recalled
                    }
                }
                // Unlock the handle, we're done futzing around with memory
                GlobalUnlock(hDevMode);
                // And to boot, we don't need that DEVMODE anymore, either
                GlobalFree(hDevMode);
                hDevMode = IntPtr.Zero;
            }
            catch (Exception ex)
            {
                if (hDevMode != IntPtr.Zero)
                {
                    MessageBox.Show("BUGGER");
                    GlobalUnlock(hDevMode);
                    // And to boot, we don't need that DEVMODE anymore, either
                    GlobalFree(hDevMode);
                    hDevMode = IntPtr.Zero;
                }
            }

            return DevModeArray;
        }
开发者ID:scherbinin,项目名称:Photo-Room,代码行数:73,代码来源:PrintService.cs

示例2: OpenPrinterPropertiesDialog

			public static void OpenPrinterPropertiesDialog(PrinterSettings printerSettings, IntPtr handle)
			{
				IntPtr hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);
				IntPtr pDevMode = GlobalLock(hDevMode);
				int sizeNeeded = DocumentProperties(handle, IntPtr.Zero, printerSettings.PrinterName, IntPtr.Zero, pDevMode, 0);
				if (sizeNeeded < 0)
				{
					GlobalUnlock(hDevMode);
					return;
				}
				IntPtr devModeData = Marshal.AllocHGlobal(sizeNeeded);
				DocumentProperties(handle, IntPtr.Zero, printerSettings.PrinterName, devModeData, pDevMode, DM_IN_BUFFER | DM_OUT_BUFFER | DM_PROMPT);
				GlobalUnlock(hDevMode);
				printerSettings.SetHdevmode(devModeData);
				printerSettings.DefaultPageSettings.SetHdevmode(devModeData);
				GlobalFree(hDevMode);
				Marshal.FreeHGlobal(devModeData);
			}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:18,代码来源:PrintingControl.xaml.cs

示例3: SetDevmode

 //Grabs the data in arraylist and chucks it back into memory "Crank the suckers out"
 /// <summary>
 /// Применение настроек принтера полученных из файла или из массива байт (mode=1 - загрузка из файла/ mode=2 - загрузка из переданного массива)
 /// </summary>
 /// <param name="printerSettings"></param>
 /// <param name="Filename"></param>
 /// /// <param name="Filename"></param>
 public void SetDevmode(PrinterSettings printerSettings, int mode, String Filename, byte[] devmodearray)
 {
     ///int mode
     ///1 = Load devmode structure from file
     ///2 = Load devmode structure from arraylist
     IntPtr hDevMode = IntPtr.Zero;                        // a handle to our current DEVMODE
     IntPtr pDevMode = IntPtr.Zero;                          // a pointer to our current DEVMODE
     Byte[] Temparray;
     try
     {
         var DevModeArray = devmodearray;
         // Obtain the current DEVMODE position in memory
         hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);
         // Obtain a lock on the handle and get an actual pointer so Windows won't move
         // it around while we're futzing with it
         pDevMode = GlobalLock(hDevMode);
         // Overwrite our current DEVMODE in memory with the one we saved.
         // They should be the same size since we haven't like upgraded the OS
         // or anything.
         if (mode == 1)  //Load devmode structure from file
         {
             FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read);
             Temparray = new byte[fs.Length];
             fs.Read(Temparray, 0, Temparray.Length);
             fs.Close();
             fs.Dispose();
             for (int i = 0; i < Temparray.Length; ++i)
             {
                 Marshal.WriteByte(pDevMode, i, Temparray[i]);
             }
         }
         if (mode == 2)  //Load devmode structure from arraylist
         {
             for (int i = 0; i < DevModeArray.Length; ++i)
             {
                 Marshal.WriteByte(pDevMode, i, DevModeArray[i]);
             }
         }
         // We're done futzing
         GlobalUnlock(hDevMode);
         // Tell our printer settings to use the one we just overwrote
         printerSettings.SetHdevmode(hDevMode);
         printerSettings.DefaultPageSettings.SetHdevmode(hDevMode);
         // It's copied to our printer settings, so we can free the OS-level one
         GlobalFree(hDevMode);
     }
     catch (Exception ex)
     {
         if (hDevMode != IntPtr.Zero)
         {
             MessageBox.Show("BUGGER");
             GlobalUnlock(hDevMode);
             // And to boot, we don't need that DEVMODE anymore, either
             GlobalFree(hDevMode);
             hDevMode = IntPtr.Zero;
         }
     }
 }
开发者ID:scherbinin,项目名称:Photo-Room,代码行数:65,代码来源:PrintService.cs


注:本文中的System.Drawing.Printing.PrinterSettings.GetHdevmode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。