private string title = "dwProperty"; // The title of the property page #endregion Fields #region Constructors public SheetControl() { InitializeComponent(); dlgProc = new DialogProc(PropPageDialogProc); callback = new PropSheetCallback(PropSheetPageProc); }
public SheetControl() { InitializeComponent(); dlgProc = new DialogProc(PropPageDialogProc); callback = new PropSheetCallback(PropSheetPageProc); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyPageProxy"/> class. /// </summary> /// <param name="parent">The parent.</param> /// <param name="propertyPage">The target property page.</param> internal PropertyPageProxy(SharpPropertySheet parent, SharpPropertyPage propertyPage) { // Set the target. Parent = parent; Target = propertyPage; // set the proxy reference in the property page. propertyPage.PropertyPageProxy = this; // Create the dialog proc delegate (as a class member so it won't be garbage collected). dialogProc = new DialogProc(WindowProc); callbackProc = new PropSheetCallback(CallbackProc); }
/// <summary> /// From Raymond Chen blog : https://blogs.msdn.microsoft.com/oldnewthing/20050329-00/?p=36043 /// </summary> private static IntPtr CreateDialogParam( SafeLibraryHandle hinst, int iTemplate, IntPtr hwndParent, DialogProc lpDlgProc, IntPtr dwInitParam) { var hrsrc = FindResource(hinst, MAKEINTRESOURCE(iTemplate), RT_DIALOG).Win32ThrowIfZero(); var hglob = LoadResource(hinst, hrsrc).Win32ThrowIfZero(); var pTemplate = LockResource(hglob); if (pTemplate == null) { throw new Win32Exception(); } return(CreateDialogIndirectParam(hinst, (DLGTEMPLATE *)pTemplate, hwndParent, lpDlgProc, dwInitParam)); }
//------------------------------------------------- // CPropPage - Constructor // // Initialize all our member variables to invalid // values. We'll expect anybody that inherits us // to actually put good values in here. //------------------------------------------------- internal CPropPage() { m_sTitle = "Title-less"; m_hWnd = (IntPtr)0; m_hIcon = (IntPtr)(-1); m_sHeaderTitle = null; m_sHeaderSubTitle = null; m_iCookie = -1; m_dlgHook = null; m_dlgProc = new DialogProc(PropPageDialogProc); m_fChanges = false; m_uc = null; m_pDlgTemplate = (IntPtr)0; System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CPropPage)); m_Size = ((System.Drawing.Size)(resources.GetObject("$this.Size"))); // There's the possiblity that our helper DLL is not going to be on the // path, so when the runtime tries to do a loadlibrary for some P/Invoke calls, // we will fail. We'll get around this by loading the DLL into memory // (since we'll know where it is) and then when the runtime calls LoadLibrary, // windows will return the one we've already loaded if (!ms_fLoadedHelper) { String sLocation = Assembly.GetAssembly(typeof(object)).Location; // This will return the location of mscorlib.dll. We are going to // be setup so mscortim.dll is in the same directory as mscorlib.dll. // We'll load that DLL now String sHelperLocation = sLocation.Replace("mscorlib.dll", "mscortim.dll"); // Now we'll load that DLL if (LoadLibrary(sHelperLocation) != (IntPtr)0) { ms_fLoadedHelper = true; } // Else... it failed. What should we do? This is not good... we'll just try // again sometime } }// CPropPage
public static extern unsafe IntPtr CreateDialogIndirectParam( SafeLibraryHandle hInstance, DLGTEMPLATE* lpTemplate, IntPtr hWndParent, DialogProc lpDialogFunc, IntPtr lParamInit);
public static extern IntPtr CreateDialogParam(IntPtr hInstance, int idResource, IntPtr hwndParent, DialogProc lpDialogFunc, IntPtr dwInitParam);
public static extern IntPtr CreateDialogParam(IntPtr hInstance, string lpTemplateName, IntPtr hwndParent, DialogProc lpDialogFunc, IntPtr dwInitParam);
public ProcessPropertySheetPage() { _dialogProc = this.DialogProc; _pagePageProc = this.PropPageProc; }
public static extern IntPtr CreateDialogIndirectParam(IntPtr instance, IntPtr template, IntPtr parentWindow, DialogProc callback, IntPtr lParam);
public static extern IntPtr CreateDialogIndirectParam( SafeLibraryHandle hInstance, DLGTEMPLATE *lpTemplate, IntPtr hWndParent, DialogProc lpDialogFunc, IntPtr lParamInit);
static private extern IntPtr CreateDialogIndirectParam(IntPtr hInstance, // handle to module IntPtr lpTemplate, // dialog box template name IntPtr hWndParent, // handle to owner window DialogProc lpDialogFunc, IntPtr dwInitParam); // dialog box procedure
void FindGoodSizes() { IntPtr hwndDlg = IntPtr.Zero; try { // Ok, so here's the deal. // To convert from pixels to dialog units, we use the following formula // // DUx = (4 * Pixelx) / (Average Character Width of System Font) // DUy = (8 * Pixely) / (Average Character Height of System Font) // // So, figuring out the Average Character Width and Height of the System Font // seems to be almost an impossibity. You'll see people do crud like // width of "abcdefghi..." / 26. That works all fine and dandy with a Latin-based // character set, but once we get those nice Chinese and other Asia symbols, we // get messed up. // // So, what do we do? // // If we have a dialog created, there is a Win32 API that will convert from dialog // units to pixels. Not quite what we need, but close enough... // // What we'll do is create a dummy dialog that we'll never show. Then we'll ask // Windows to compute some Pixel widths for us from some dialog units. That will // allow us to 'reverse engineer' the above equations and figure out what the // average width and height of the system font really is. Once we get those numbers, // we can to the translations. RECT r = new RECT(); IntPtr hInst = LoadLibrary("COMCTL32"); DialogProc dp = new DialogProc(myProc); // Find the dialog resource for a property sheet or wizard page. // // These constants can be found at \\index2\w2krtm\private\shell\comctl32\rcids.h // // They correspond to DLG_WIZARD and DLG_PROPSHEET IntPtr nTemplate = (this is CWizardPage)?(IntPtr)1020:(IntPtr)1006; // Get the Template from COMCTL32 IntPtr hresinfo = FindResource(hInst, nTemplate, 5); IntPtr h = LoadResource(hInst, hresinfo); int nSize = SizeofResource(hInst, hresinfo); IntPtr pstr = LockResource(h); Byte[] nResource = new Byte[nSize]; Marshal.Copy(pstr, nResource, 0, nSize); // Remove the WS_VISIBLE from the styles attribute byte WS_VISIBLE = 0x10; nResource[3] &= (byte)(~WS_VISIBLE); IntPtr pResource = Marshal.AllocHGlobal(nSize); Marshal.Copy(nResource, 0, pResource, nSize); hwndDlg = CreateDialogIndirectParam(hInst, pResource, CNodeManager.MMChWnd, dp, IntPtr.Zero); r.left = 0; r.top = 0; r.right = 100; r.bottom = 100; MapDialogRect(hwndDlg, ref r); double nMagicXNumber = 4.0 * r.right / 100.0; double nMagicYNumber = 8.0 * r.bottom / 100.0; // Add the 1 to round up DlgWidth = (int)((4.0 * PageSize.Width / nMagicXNumber) + 1); DlgHeight = (int)((8.0 * PageSize.Height / nMagicYNumber) + 1); } catch (Exception) {} if (hwndDlg != IntPtr.Zero) { DestroyWindow(hwndDlg); } }// FindGoodSizes