敲代码时,突然发现有一个背景图片无法显示,百思不得其解,最终发现是MoveWindow() SetWindowPos()这两个函数的使用不当造成的. 这里把这两个函数的前世今生给分析一下. 先看MoveWindow()函数,用于改变窗口的位置和尺寸,对于顶层窗口,按照屏幕对齐与左上角,对于子窗口,则对齐与父窗口的左上角. BOOL MoveWindow( HWND hWnd,int x, int y, int nWidth, int nHeight,BOOL bRepaint = TRUE);
定义:[DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hWnd, int hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags); 调用:API.SetWindowPos(mainhwnd, -1, 0, 0, 0, 0, 0x001 | 0x002 | 0x040); 参数: hWndInsertAfter 窗口叠层位置 HWN
敲代码时,突然发现有一个背景图片无法显示,百思不得其解,最终发现是MoveWindow() SetWindowPos()这两个函数的使用不当造成的. 这里把这两个函数的前世今生给分析一下. 先看MoveWindow()函数,用于改变窗口的位置和尺寸,对于顶层窗口,按照屏幕对齐与左上角,对于子窗口,则对齐与父窗口的左上角. BOOL MoveWindow( HWND hWnd,int x, int y, int nWidth, int nHeight,BOOL bRepaint = TRUE);/
[DllImport("user32.dll")] private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags); SetWindowPos( hWnd: HWND; {窗口句柄} hWndInsertAfter: HWND; {窗口的 Z 顺序} X, Y: Integer; {位置} cx, cy: Inte