本文整理汇总了C#中System.Windows.Forms.Hwnd类的典型用法代码示例。如果您正苦于以下问题:C# Hwnd类的具体用法?C# Hwnd怎么用?C# Hwnd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Hwnd类属于System.Windows.Forms命名空间,在下文中一共展示了Hwnd类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Hwnd
public Hwnd() {
x = 0;
y = 0;
width = 0;
height = 0;
visible = false;
menu = null;
border_style = FormBorderStyle.None;
client_window = IntPtr.Zero;
whole_window = IntPtr.Zero;
cursor = IntPtr.Zero;
handle = IntPtr.Zero;
parent = null;
invalid_list = new ArrayList();
expose_pending = false;
nc_expose_pending = false;
enabled = true;
reparented = false;
client_rectangle = Rectangle.Empty;
marshal_free_list = new ArrayList(2);
opacity = 0xffffffff;
fixed_size = false;
drawing_stack = new Stack ();
children = new ArrayList ();
resizing_or_moving = false;
whacky_wm = false;
topmost = false;
}
示例2: TranslateClientRectangleToXClientRectangle
internal static Rectangle TranslateClientRectangleToXClientRectangle (Hwnd hwnd, Control ctrl)
{
/*
* If this is a form with no window manager, X is handling all the border and caption painting
* so remove that from the area (since the area we set of the window here is the part of the window
* we're painting in only)
*/
Rectangle rect = hwnd.ClientRect;
Form form = ctrl as Form;
CreateParams cp = null;
if (form != null)
cp = form.GetCreateParams ();
if (form != null && (form.window_manager == null && !cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
Rectangle xrect = rect;
xrect.Y -= borders.top;
xrect.X -= borders.left;
xrect.Width += borders.left + borders.right;
xrect.Height += borders.top + borders.bottom;
rect = xrect;
}
if (rect.Width < 1 || rect.Height < 1) {
rect.Width = 1;
rect.Height = 1;
rect.X = -5;
rect.Y = -5;
}
return rect;
}
示例3: CreateWindow
internal override IntPtr CreateWindow(CreateParams cp) {
IntPtr WindowHandle;
IntPtr ParentHandle;
Hwnd hwnd;
hwnd = new Hwnd();
ParentHandle=cp.Parent;
if ((ParentHandle==IntPtr.Zero) && (cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
// We need to use our foster parent window until this poor child gets it's parent assigned
ParentHandle = GetFosterParent();
}
if ( ((cp.Style & (int)(WindowStyles.WS_CHILD | WindowStyles.WS_POPUP))==0) && ((cp.ExStyle & (int)WindowExStyles.WS_EX_APPWINDOW) == 0)) {
// If we want to be hidden from the taskbar we need to be 'owned' by
// something not on the taskbar. FosterParent is just that
ParentHandle = GetFosterParent();
}
Point location;
if (cp.HasWindowManager) {
location = Hwnd.GetNextStackedFormLocation (cp, Hwnd.ObjectFromHandle (cp.Parent));
} else {
location = new Point (cp.X, cp.Y);
}
string class_name = RegisterWindowClass (cp.ClassStyle);
HwndCreating = hwnd;
// We cannot actually send the WS_EX_MDICHILD flag to Windows because we
// are faking MDI, not uses Windows' version.
if ((cp.WindowExStyle & WindowExStyles.WS_EX_MDICHILD) == WindowExStyles.WS_EX_MDICHILD)
cp.WindowExStyle ^= WindowExStyles.WS_EX_MDICHILD;
WindowHandle = Win32CreateWindow (cp.WindowExStyle, class_name, cp.Caption, cp.WindowStyle, location.X, location.Y, cp.Width, cp.Height, ParentHandle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
HwndCreating = null;
if (WindowHandle==IntPtr.Zero) {
int error = Marshal.GetLastWin32Error ();
Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window, class '"+cp.ClassName+"'", 0);
}
hwnd.ClientWindow = WindowHandle;
hwnd.Mapped = true;
Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (uint)ThemeEngine.Current.DefaultControlBackColor.ToArgb());
return WindowHandle;
}
示例4: SetDisplay
internal void SetDisplay(IntPtr display_handle)
{
if (display_handle != IntPtr.Zero) {
Hwnd hwnd;
if ((DisplayHandle != IntPtr.Zero) && (FosterParent != IntPtr.Zero)) {
hwnd = Hwnd.ObjectFromHandle(FosterParent);
XDestroyWindow(DisplayHandle, FosterParent);
hwnd.Dispose();
}
if (DisplayHandle != IntPtr.Zero) {
XCloseDisplay(DisplayHandle);
}
DisplayHandle=display_handle;
// We need to tell System.Drawing our DisplayHandle. FromHdcInternal has
// been hacked to do this for us.
Graphics.FromHdcInternal (DisplayHandle);
// query for the render extension so
// we can ignore the spurious
// BadPicture errors that are
// generated by cairo/render.
XQueryExtension (DisplayHandle, "RENDER",
ref render_major_opcode, ref render_first_event, ref render_first_error);
// Debugging support
if (Environment.GetEnvironmentVariable ("MONO_XSYNC") != null) {
XSynchronize(DisplayHandle, true);
}
if (Environment.GetEnvironmentVariable ("MONO_XEXCEPTIONS") != null) {
ErrorExceptions = true;
}
// Generic X11 setup
ScreenNo = XDefaultScreen(DisplayHandle);
RootWindow = XRootWindow(DisplayHandle, ScreenNo);
DefaultColormap = XDefaultColormap(DisplayHandle, ScreenNo);
// Create the foster parent
// it is important that border_width is kept in synch with the other XCreateWindow calls
FosterParent=XCreateSimpleWindow(DisplayHandle, RootWindow, 0, 0, 1, 1, 0, UIntPtr.Zero, UIntPtr.Zero);
if (FosterParent==IntPtr.Zero) {
Console.WriteLine("XplatUIX11 Constructor failed to create FosterParent");
}
DebugHelper.WriteLine ("FosterParent created 0x{0:x}", FosterParent.ToInt32());
hwnd = new Hwnd();
hwnd.Queue = ThreadQueue(Thread.CurrentThread);
hwnd.WholeWindow = FosterParent;
hwnd.ClientWindow = FosterParent;
// Create a HWND for RootWIndow as well, so our queue doesn't eat the events
hwnd = new Hwnd();
hwnd.Queue = ThreadQueue(Thread.CurrentThread);
hwnd.whole_window = RootWindow;
hwnd.ClientWindow = RootWindow;
// For sleeping on the X11 socket
listen = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 0);
listen.Bind(ep);
listen.Listen(1);
// To wake up when a timer is ready
network_buffer = new byte[10];
wake = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
wake.Connect(listen.LocalEndPoint);
// Make this non-blocking, so it doesn't
// deadlock if too many wakes are sent
// before the wake_receive end is polled
wake.Blocking = false;
wake_receive = listen.Accept();
#if __MonoCS__
pollfds = new Pollfd [2];
pollfds [0] = new Pollfd ();
pollfds [0].fd = XConnectionNumber (DisplayHandle);
pollfds [0].events = PollEvents.POLLIN;
pollfds [1] = new Pollfd ();
pollfds [1].fd = wake_receive.Handle.ToInt32 ();
pollfds [1].events = PollEvents.POLLIN;
#endif
Keyboard = new X11Keyboard(DisplayHandle, FosterParent);
Dnd = new X11Dnd (DisplayHandle, Keyboard);
DoubleClickInterval = 500;
HoverState.Interval = 500;
HoverState.Timer = new Timer();
HoverState.Timer.Enabled = false;
//.........这里部分代码省略.........
示例5: ProcessGraphicsExpose
void ProcessGraphicsExpose (Hwnd hwnd)
{
XEvent xevent = new XEvent ();
IntPtr handle = Hwnd.HandleFromObject (hwnd);
EventPredicate predicate = GraphicsExposePredicate;
for (;;) {
XIfEvent (Display, ref xevent, predicate, handle);
if (xevent.type != XEventName.GraphicsExpose)
break;
AddExpose (hwnd, xevent.ExposeEvent.window == hwnd.ClientWindow, xevent.GraphicsExposeEvent.x, xevent.GraphicsExposeEvent.y,
xevent.GraphicsExposeEvent.width, xevent.GraphicsExposeEvent.height);
if (xevent.GraphicsExposeEvent.count == 0)
break;
}
}
示例6: UnmapWindow
void UnmapWindow(Hwnd hwnd, WindowType windows) {
if (hwnd.mapped) {
Form f = null;
if (Control.FromHandle(hwnd.Handle) is Form) {
f = Control.FromHandle(hwnd.Handle) as Form;
if (f.WindowState == FormWindowState.Normal) {
f.waiting_showwindow = true;
SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, IntPtr.Zero, IntPtr.Zero);
}
}
// it's possible that our Hwnd is no
// longer valid after making that
// SendMessage call, so check here.
// FIXME: it is likely wrong, as it has already sent WM_SHOWWINDOW
if (hwnd.zombie)
return;
if ((windows & WindowType.Client) != 0) {
XUnmapWindow(DisplayHandle, hwnd.client_window);
}
if ((windows & WindowType.Whole) != 0) {
XUnmapWindow(DisplayHandle, hwnd.whole_window);
}
hwnd.mapped = false;
if (f != null) {
if (f.waiting_showwindow) {
WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
CreateParams cp = f.GetCreateParams();
if (!ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_MDICHILD) &&
!StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
WaitForHwndMessage (hwnd, Msg.WM_ACTIVATE, true);
}
}
}
}
}
示例7: PerformNCCalc
void PerformNCCalc(Hwnd hwnd) {
XplatUIWin32.NCCALCSIZE_PARAMS ncp;
IntPtr ptr;
Rectangle rect;
rect = new Rectangle (0, 0, hwnd.Width, hwnd.Height);
ncp = new XplatUIWin32.NCCALCSIZE_PARAMS();
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ncp));
ncp.rgrc1.left = rect.Left;
ncp.rgrc1.top = rect.Top;
ncp.rgrc1.right = rect.Right;
ncp.rgrc1.bottom = rect.Bottom;
Marshal.StructureToPtr(ncp, ptr, true);
NativeWindow.WndProc(hwnd.client_window, Msg.WM_NCCALCSIZE, (IntPtr)1, ptr);
ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(ptr, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
Marshal.FreeHGlobal(ptr);
rect = new Rectangle(ncp.rgrc1.left, ncp.rgrc1.top, ncp.rgrc1.right - ncp.rgrc1.left, ncp.rgrc1.bottom - ncp.rgrc1.top);
hwnd.ClientRect = rect;
rect = TranslateClientRectangleToXClientRectangle (hwnd);
if (hwnd.visible) {
MoveResizeWindow (DisplayHandle, hwnd.client_window, rect.X, rect.Y, rect.Width, rect.Height);
}
AddExpose (hwnd, hwnd.WholeWindow == hwnd.ClientWindow, 0, 0, hwnd.Width, hwnd.Height);
}
示例8: CreateWindow
internal override IntPtr CreateWindow(CreateParams cp) {
Hwnd hwnd;
Hwnd parent_hwnd = null;
int X;
int Y;
int Width;
int Height;
IntPtr ParentHandle;
IntPtr WindowHandle;
IntPtr WholeWindow;
IntPtr ClientWindow;
IntPtr WholeWindowTracking;
IntPtr ClientWindowTracking;
hwnd = new Hwnd ();
X = cp.X;
Y = cp.Y;
Width = cp.Width;
Height = cp.Height;
ParentHandle = IntPtr.Zero;
WindowHandle = IntPtr.Zero;
WholeWindow = IntPtr.Zero;
ClientWindow = IntPtr.Zero;
WholeWindowTracking = IntPtr.Zero;
ClientWindowTracking = IntPtr.Zero;
if (Width < 1) Width = 1;
if (Height < 1) Height = 1;
if (cp.Parent != IntPtr.Zero) {
parent_hwnd = Hwnd.ObjectFromHandle (cp.Parent);
ParentHandle = parent_hwnd.client_window;
} else {
if (StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
}
}
Point next;
if (cp.control is Form) {
next = Hwnd.GetNextStackedFormLocation (cp, parent_hwnd);
X = next.X;
Y = next.Y;
}
hwnd.x = X;
hwnd.y = Y;
hwnd.width = Width;
hwnd.height = Height;
hwnd.Parent = Hwnd.ObjectFromHandle (cp.Parent);
hwnd.initial_style = cp.WindowStyle;
hwnd.initial_ex_style = cp.WindowExStyle;
hwnd.visible = false;
if (StyleSet (cp.Style, WindowStyles.WS_DISABLED)) {
hwnd.enabled = false;
}
ClientWindow = IntPtr.Zero;
Size QWindowSize = TranslateWindowSizeToQuartzWindowSize (cp);
Rectangle QClientRect = TranslateClientRectangleToQuartzClientRectangle (hwnd, cp.control);
SetHwndStyles(hwnd, cp);
/* FIXME */
if (ParentHandle == IntPtr.Zero) {
IntPtr WindowView = IntPtr.Zero;
IntPtr GrowBox = IntPtr.Zero;
Carbon.WindowClass windowklass = Carbon.WindowClass.kOverlayWindowClass;
Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZEBOX)) {
attributes |= Carbon.WindowAttributes.kWindowCollapseBoxAttribute;
}
if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZEBOX)) {
attributes |= Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowHorizontalZoomAttribute | Carbon.WindowAttributes.kWindowVerticalZoomAttribute;
}
if (StyleSet (cp.Style, WindowStyles.WS_SYSMENU)) {
attributes |= Carbon.WindowAttributes.kWindowCloseBoxAttribute;
}
if (StyleSet (cp.Style, WindowStyles.WS_CAPTION)) {
windowklass = Carbon.WindowClass.kDocumentWindowClass;
}
if (hwnd.border_style == FormBorderStyle.FixedToolWindow) {
windowklass = Carbon.WindowClass.kUtilityWindowClass;
} else if (hwnd.border_style == FormBorderStyle.SizableToolWindow) {
attributes |= Carbon.WindowAttributes.kWindowResizableAttribute;
windowklass = Carbon.WindowClass.kUtilityWindowClass;
}
if (windowklass == Carbon.WindowClass.kOverlayWindowClass) {
attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
}
attributes |= Carbon.WindowAttributes.kWindowLiveResizeAttribute;
Carbon.Rect rect = new Carbon.Rect ();
if (StyleSet (cp.Style, WindowStyles.WS_POPUP)) {
SetRect (ref rect, (short)X, (short)(Y), (short)(X + QWindowSize.Width), (short)(Y + QWindowSize.Height));
} else {
SetRect (ref rect, (short)X, (short)(Y + MenuBarHeight), (short)(X + QWindowSize.Width), (short)(Y + MenuBarHeight + QWindowSize.Height));
}
//.........这里部分代码省略.........
示例9: Enqueue
public void Enqueue (Hwnd hwnd) {
hwnds.Add(hwnd);
}
示例10: WaitForHwndMessage
private void WaitForHwndMessage (Hwnd hwnd, Msg message) {
MSG msg = new MSG ();
bool done = false;
do {
if (GetMessage(null, ref msg, IntPtr.Zero, 0, 0)) {
if ((Msg)msg.message == Msg.WM_QUIT) {
PostQuitMessage (0);
done = true;
}
else {
if (msg.hwnd == hwnd.Handle) {
if ((Msg)msg.message == message)
break;
else if ((Msg)msg.message == Msg.WM_DESTROY)
done = true;
}
TranslateMessage (ref msg);
DispatchMessage (ref msg);
}
}
} while (!done);
}
示例11: AddExpose
private void AddExpose (Hwnd hwnd, bool client, int x, int y, int width, int height) {
// Don't waste time
if ((hwnd == null) || (x > hwnd.Width) || (y > hwnd.Height) || ((x + width) < 0) || ((y + height) < 0)) {
return;
}
// Keep the invalid area as small as needed
if ((x + width) > hwnd.width) {
width = hwnd.width - x;
}
if ((y + height) > hwnd.height) {
height = hwnd.height - y;
}
if (client) {
hwnd.AddInvalidArea(x, y, width, height);
if (!hwnd.expose_pending && hwnd.visible) {
MSG msg = new MSG ();
msg.message = Msg.WM_PAINT;
msg.hwnd = hwnd.Handle;
EnqueueMessage (msg);
hwnd.expose_pending = true;
}
} else {
hwnd.AddNcInvalidArea (x, y, width, height);
if (!hwnd.nc_expose_pending && hwnd.visible) {
MSG msg = new MSG ();
Region rgn = new Region (hwnd.Invalid);
IntPtr hrgn = rgn.GetHrgn (null); // Graphics object isn't needed
msg.message = Msg.WM_NCPAINT;
msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
msg.refobject = rgn;
msg.hwnd = hwnd.Handle;
EnqueueMessage (msg);
hwnd.nc_expose_pending = true;
}
}
}
示例12: PerformNCCalc
internal void PerformNCCalc(Hwnd hwnd) {
XplatUIWin32.NCCALCSIZE_PARAMS ncp;
IntPtr ptr;
Rectangle rect;
rect = new Rectangle (0, 0, hwnd.Width, hwnd.Height);
ncp = new XplatUIWin32.NCCALCSIZE_PARAMS();
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ncp));
ncp.rgrc1.left = rect.Left;
ncp.rgrc1.top = rect.Top;
ncp.rgrc1.right = rect.Right;
ncp.rgrc1.bottom = rect.Bottom;
Marshal.StructureToPtr(ncp, ptr, true);
NativeWindow.WndProc(hwnd.client_window, Msg.WM_NCCALCSIZE, (IntPtr)1, ptr);
ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(ptr, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
Marshal.FreeHGlobal(ptr);
rect = new Rectangle(ncp.rgrc1.left, ncp.rgrc1.top, ncp.rgrc1.right - ncp.rgrc1.left, ncp.rgrc1.bottom - ncp.rgrc1.top);
hwnd.ClientRect = rect;
rect = TranslateClientRectangleToQuartzClientRectangle (hwnd);
if (hwnd.visible) {
Carbon.HIRect r = new Carbon.HIRect (rect.X, rect.Y, rect.Width, rect.Height);
HIViewSetFrame (hwnd.client_window, ref r);
}
AddExpose (hwnd, false, 0, 0, hwnd.Width, hwnd.Height);
}
示例13: WaitForHwndMessage
void WaitForHwndMessage (Hwnd hwnd, Msg message, bool process) {
MSG msg = new MSG ();
XEventQueue queue;
queue = ThreadQueue(Thread.CurrentThread);
queue.DispatchIdle = false;
bool done = false;
string key = hwnd.Handle + ":" + message;
if (!messageHold.ContainsKey (key))
messageHold.Add (key, 1);
else
messageHold[key] = ((int)messageHold[key]) + 1;
do {
DebugHelper.WriteLine ("Waiting for message " + message + " on hwnd " + String.Format("0x{0:x}", hwnd.Handle.ToInt32 ()));
DebugHelper.Indent ();
if (PeekMessage(queue, ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)) {
if ((Msg)msg.message == Msg.WM_QUIT) {
PostQuitMessage (0);
done = true;
}
else {
DebugHelper.WriteLine ("PeekMessage got " + msg);
if (msg.hwnd == hwnd.Handle) {
if ((Msg)msg.message == message) {
if (process) {
TranslateMessage (ref msg);
DispatchMessage (ref msg);
}
break;
}
else if ((Msg)msg.message == Msg.WM_DESTROY)
done = true;
}
TranslateMessage (ref msg);
DispatchMessage (ref msg);
}
}
done = !messageHold.ContainsKey (key) || ((int)messageHold[key] < 1) || done;
} while (!done);
messageHold.Remove (key);
DebugHelper.Unindent ();
DebugHelper.WriteLine ("Finished waiting for " + key);
queue.DispatchIdle = true;
}
示例14: Remove
public void Remove(Hwnd hwnd) {
if (!hwnd.expose_pending && !hwnd.nc_expose_pending) {
hwnds.Remove(hwnd);
}
}
示例15: MapWindow
void MapWindow(Hwnd hwnd, WindowType windows) {
if (!hwnd.mapped) {
Form f = Control.FromHandle(hwnd.Handle) as Form;
if (f != null) {
if (f.WindowState == FormWindowState.Normal) {
f.waiting_showwindow = true;
SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
}
}
// it's possible that our Hwnd is no
// longer valid after making that
// SendMessage call, so check here.
if (hwnd.zombie)
return;
if (hwnd.topmost) {
// Most window managers will respect the _NET_WM_STATE property.
// If not, use XMapRaised to map the window at the top level as
// a last ditch effort.
if ((windows & WindowType.Whole) != 0) {
XMapRaised(DisplayHandle, hwnd.whole_window);
}
if ((windows & WindowType.Client) != 0) {
XMapRaised(DisplayHandle, hwnd.client_window);
}
} else {
if ((windows & WindowType.Whole) != 0) {
XMapWindow(DisplayHandle, hwnd.whole_window);
}
if ((windows & WindowType.Client) != 0) {
XMapWindow(DisplayHandle, hwnd.client_window);
}
}
hwnd.mapped = true;
if (f != null) {
if (f.waiting_showwindow) {
WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
CreateParams cp = f.GetCreateParams();
if (!ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_MDICHILD) &&
!StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
WaitForHwndMessage (hwnd, Msg.WM_ACTIVATE, true);
}
}
}
}
}