예제 #1
0
        public WindowHook(TodayScreenItem item, Control control)
        {
            this.item = item;
              this.control = control;

              // Subclass the window procedure associated with this control, so that
              // we can hook the requests to paint it's background
              newWindowProc = new WindowProcCallback(WndProc);
              realWindowProc = SetWindowLong(control.Handle, GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(newWindowProc));
        }
예제 #2
0
        static void Main()
        {
            TodayScreenItem form = new TodayScreenItem(FindNativeHandle());

              // For each DLL in the same folder as the ManagedTodayScreenItemHost executable
              string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

              foreach (string dll in Directory.GetFiles(path, "*.dll"))
              {
            try
            {
              Assembly assembly = Assembly.LoadFrom(dll);

              // Check each type defined within it
              foreach (Type type in assembly.GetTypes())
              {
            // To see if it has been marked with the TodayScreenItem attribute
            TodayScreenItemAttribute[] attrs = (TodayScreenItemAttribute[])type.GetCustomAttributes(typeof(TodayScreenItemAttribute), false);
            if (attrs != null && attrs.Length == 1)
            {
              // If it has create an instance of the class (it should be a control of some type)
              // and place it onto the form.
              Control ctrl = (Control)Activator.CreateInstance(type);

              form.AddControl(ctrl);
            }
              }
            }
            catch (IOException)
            {
              // Safely ignore this, it's probably us attempting to load
              // a native DLL via Assembly.LoadFrom()
            }
              }

              // Finally display the form
              Application.Run(form);
        }