小篆作品 | 小篆知识 | 加入收藏 小篆转换器软件可转换多种小篆在线预览 网页版 V2.0
小篆转换器

当前位置:小篆网 > 知识库 >

movewindow

时间:2023-07-29 23:26:57 编辑:小篆君 来源:小篆网

1,C语言中的MoveWindow函数如何使用

#001 //
#002 // 响应命令.
#003 //
#004 //
#005 LRESULT CCaiWinMsg::OnCommand(int nID,int nEvent)
#006 {
#007  // 菜单选项命令响应:
#008  switch (nID)
#009  {
#010  case IDC_CREATEBTN:
#011         //显示一个按钮。
#012         if (!m_hBtn)
#013         {
#014                m_hBtn = CreateWindow(_T("BUTTON"),_T("按钮"),
#015                    WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
#016                    50,50,100,32,
#017                     m_hWnd,(HMENU)IDC_BTN,m_hInstance,NULL);
#018         }  
#019         break;
#020  case IDC_BTN:
#021         OutputDebugString(_T("按钮按下\r\n"));
#022         {
#023               static bool bChangeText = true;
#024               if (bChangeText)
#025               {
#026                    //设置按钮的文字。
#027                    SetWindowText(m_hBtn,_T("改变它"));
#028
#029                    //改变按钮窗口的位置和大小。
#030                   MoveWindow(m_hBtn,10,10,100,32,TRUE);
#031               }
#032               else
#033               {
#034                    //设置按钮的文字。
#035                    SetWindowText(m_hBtn,_T("按钮"));
#036
#037                   //改变按钮窗口的位置和大小。
#038                   MoveWindow(m_hBtn,50,50,100,32,TRUE);
#039               }
#040
#041               //每一次都改变。
#042               bChangeText = !bChangeText;
#043         }
#044         break;
#045  default:
#046         return CCaiWin::OnCommand(nID,nEvent);
#047  }
#048
#049  return 1;
#050 }

2,MoveWindow和setwindowpos的区别

两者都能实现移动和改变窗口大小。
MoveWindow()功能比较单一,只能移动和改变窗口大小,而SetWindowPos()可以设置更多的参数,实现Zorder及显示方式标志。
MoveWindow()发送WM_WINDOWPOSCHANGING,WM_WINDOWPOSCHANGED,WM_MOVE,WM_SIZE和WM_NCCALCSIZE等消息到窗口,SetWindowPos()只发送WM_WINDOWPOSCHANGED消息到窗口。所以说如果需要发送更多消息时还是使用MoveWindow()的好。

3,vc中怎样移动窗口到(0,0)

用 SetWindowPos这个函数 (功能包括了MoveWindow这个函数)
你可以这样:

SetWindowPos(hWnd,HWND_TOPMOST,0,0,200,200,SWP_SHOWWINDOW);

窗口就移动到(0,0)的位置了

关于它的原型和说明:

The SetWindowPos function changes the size, position, and Z order of a child, pop-up, or top-level window. Child, pop-up, and top-level windows are ordered according to their appearance on the screen. The topmost window receives the highest rank and is the first window in the Z order.

BOOL SetWindowPos(
HWND hWnd, // handle to window
HWND hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
UINT uFlags // window-positioning flags
);

Parameters
hWnd
Handle to the window.
hWndInsertAfter
Handle to the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values: Value Meaning
HWND_BOTTOM Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other windows.
HWND_NOTOPMOST Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window.
HWND_TOP Places the window at the top of the Z order.
HWND_TOPMOST Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.


For more information about how this parameter is used, see the following Remarks section.

X
Specifies the new position of the left side of the window, in client coordinates.
Y
Specifies the new position of the top of the window, in client coordinates.
cx
Specifies the new width of the window, in pixels.
cy
Specifies the new height of the window, in pixels.
uFlags
Specifies the window sizing and positioning flags. This parameter can be a combination of the following values: Value Meaning
SWP_ASYNCWINDOWPOS If the calling thread does not own the window, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request.
SWP_DEFERERASE Prevents generation of the WM_SYNCPAINT message.
SWP_DRAWFRAME Draws a frame (defined in the window's class description) around the window.
SWP_FRAMECHANGED Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed.
SWP_HIDEWINDOW Hides the window.
SWP_NOACTIVATE Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
SWP_NOCOPYBITS Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
SWP_NOMOVE Retains the current position (ignores the X and Y parameters).
SWP_NOOWNERZORDER Does not change the owner window's position in the Z order.
SWP_NOREDRAW Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
SWP_NOREPOSITION Same as the SWP_NOOWNERZORDER flag.
SWP_NOSENDCHANGING Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
SWP_NOSIZE Retains the current size (ignores the cx and cy parameters).
SWP_NOZORDER Retains the current Z order (ignores the hWndInsertAfter parameter).
SWP_SHOWWINDOW Displays the window.


Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, callGetLastError.

Remarks
If the SWP_SHOWWINDOW or SWP_HIDEWINDOW flag is set, the window cannot be moved or sized.

If you have changed certain window data using SetWindowLong, you must call SetWindowPos to have the changes take effect. Use the following combination for uFlags: SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED.

A window can be made a topmost window either by setting the hWndInsertAfter parameter to HWND_TOPMOST and ensuring that the SWP_NOZORDER flag is not set, or by setting a window's position in the Z order so that it is above any existing topmost windows. When a non-topmost window is made topmost, its owned windows are also made topmost. Its owners, however, are not changed.

If neither the SWP_NOACTIVATE nor SWP_NOZORDER flag is specified (that is, when the application requests that a window be simultaneously activated and its position in the Z order changed), the value specified in hWndInsertAfter is used only in the following circumstances:

Neither the HWND_TOPMOST nor HWND_NOTOPMOST flag is specified in hWndInsertAfter.
The window identified by hWnd is not the active window.
An application cannot activate an inactive window without also bringing it to the top of the Z order. Applications can change an activated window's position in the Z order without restrictions, or it can activate a window and then move it to the top of the topmost or non-topmost windows.

If a topmost window is repositioned to the bottom (HWND_BOTTOM) of the Z order or after any non-topmost window, it is no longer topmost. When a topmost window is made non-topmost, its owners and its owned windows are also made non-topmost windows.

A non-topmost window can own a topmost window, but the reverse cannot occur. Any window (for example, a dialog box) owned by a topmost window is itself made a topmost window, to ensure that all owned windows stay above their owner.

If an application is not in the foreground, and should be in the foreground, it must call the SetForegroundWindow function.

Windows CE: If this is a visible top-level window, and the SWP_NOACTIVATE flag is not specified, this function will activate the window. If this is the currently active window, and either the SWP_NOACTIVATE flag or the SWP_HIDEWINDOW flag is specified, the activation is passed on to another visible top-level window.

When you set the SWP_FRAMECHANGED flag in the nFlags parameter to this function, Windows CE redraws the entire non-client area of the window, which may change the size of the client area. This is the only way to get the non-client area to be recalculated and is typically used after a you've changed the window style by calling SetWindowLong.

SetWindowPos will always cause a WM_WINDOWPOSCHANGED message to be sent to the window. The flags passed in this message are exactly the same as those passed into the function. No other messages are sent by this function.

Windows CE 1.0 does not support the HWND_TOPMOST and HWND_NOTOPMOST constants in the hwndInsertAfter parameter.

Windows CE 1.0 does not support the SWP_DRAWFRAME or SWP_NOCOPYBITS flags in the fuFlags paramete.

4,使用MoveWindow()改变窗口大小时遇到问题了。

MoveWindow()函数用于改变指定窗口的位置和大小。顶级窗口可能受最大或最小尺寸的限制,那些尺寸优先于这里设置的参数。
因为windows窗体为了保证标题栏按钮的缓冲区不会因为调整窗体大小而溢出,对窗体的最小宽度做了限制(保证能够显示一个图标和三个按钮的宽度),所以即使你给函数传的宽度参数为10,也不会被应用到窗体。

5,用MoveWindow设置窗口大小是放在OnInitialUpdate()里吗

不能使用RecalcLayout的,RecalcLayout就是告诉Frame要重新调整子窗口(视图、工具栏、状态栏等)在客户区中的位置,且撑满客户区。
后面的ResizeParentToFit也没有意义的。
楼主对这两个函数似乎没搞明白,当程序出现了未知情况,就需要仔细了解自己所使用的函数,尤其是陌生的函数。一般都是到MSDN中去查阅的。当然,实际这两个函数没什么更深入的东西可以挖掘,就是应该要避免RecalcLayout。

然后,去掉了RecalcLayout后,发现视图还是会撑满整个客户区。可以根据这个情况猜测出,会不会后面MFC框架又调用了RecalcLayout呢,如果是的话,那么可以肯定在OnInitialUpdate中改变视图大小是没有意义的。

怎么调试,才能确定在OnInitialUpdate后是否调用了RecalcLayout呢?这里说一下我使用的一个技巧:
在OnInitialUpdate中,第一行输入:
TRACE(_T("Entering View::OnInitialUpdate\n"));

然后切换到Frame中,重载RecalcLayout函数,在第一行也输入:
TRACE(_T("Entering Frame::RecalcLayout\n"));

按F5进行调试,然后在调试器的输出框中,可以发现MFC框架进入这两个函数的先后次序及进入的次数。

结果可以验证在OnInitialUpdate后MFC框架又调用了RecalcLayout。

正确加载MoveWindow的函数其实应该是CView::OnActivateView(BOOL, CView*, CView*)

程序遇上问题一般没什么大不了的,关键是如何分析解决问题的能力是很重要的。我把自己的一些经验在此与楼主分享,希望楼主也能提高自己调试程序的能力。

P.S.为什么要改变视图大小呢,似乎没这个必要呢。要放其他东西,可以做切分窗口。自己手工调整客户区中的各窗口布局是很辛苦的。 OnActivateView并不是用来修改窗口界面的地方,因此在这里调用MoveWindow并不好。其实,最好的办法是重载RecalcLayout,然后自己写代码进去,不要去调用基类的RecalcLayout,难度较大。

6,C# 如何能在子窗口中处理父窗口中的控件

将父窗口的N个按钮的Modifiers属性设为Public

假设模拟个Button点击事件
private void btn_Click(object sender, EventArgs e)
{
Form2 frmNew = new Form2(this); //将父窗体作为参数传到子窗体
frmNew.Show();
}

在子窗体中
首先声明个父窗体的变量 Form1 frm;
添加个重载的构造函数
public Form2(Form1 frm1)
{
frm = frm1; //将传进来的父窗体参数赋给界面上的变量
Init...(); //调用默认设计器的代码
}

然后在子窗体就可以通过frm.btn1.BackColor修改父窗体的按钮的颜色了

精华总结

雨露,是万物生长的灵丹妙药,它能让万物欣欣向荣,给人带来希望和欢乐。起名,是给孩子取名最重要的一步,因为名字,在某种程度上就是一种文化。一个好的名字,可以让孩子从小拥有一个好的起点。那么,旸字取名呢,有着什么样的寓意及含义?

1、旸是五行金之字,五行属水,寓意孩子聪明机智,有大智慧,富有爱心。

根据五行属性来取名,金能克水,就像是金被水淹没了,所以会出现水变少,阳气不充足的情况。而旸字五行属水,表示有希望的样子,寓意孩子聪明机智,有大智慧,富有爱心,有爱心之义,对人非常友好,人缘非常好。由于在起名时需要注意五行八字,所以名字要避开太多不利因素。例如孩子取名为旸这个名字时,可选择五行属金且与水相冲或水火相济或金水相济等字面寓意相搭。

2、旸字是木之金之字,五行属木,为金之态,寓意孩子金木水火土五行协调,和谐发展。

雨露的滋润,日出而作,日落而息,都让人感到无比满足。旸,字音shèng,寓意着孩子有一颗包容和感恩之心。这与“日出而作、日落而息”有异曲同工之妙……旸给人带来欢乐、吉祥的同时,也寓意着孩子金木水火土协调发展……

3、旸是一种很有灵性的字,可形容孩子生机勃勃,乐观向上。

【旸】有光明、温暖、明朗的意思,可用作名字。【阳凯是太阳之意。【阳阳阳】阳代表明亮,阳代表光明及温暖。用阳代表光明的事物,表示孩子生机勃勃,乐观向上。【阳欣可表示欣欣向荣之意。【阳和】可表示温暖的意思。

4、旸字取名,寓意孩子乐观向上,对生活充满希望。

旸字寓意孩子乐观向上,对生活充满希望,乐观积极的生活态度,有助于提高孩子的自信心。另外旸字取名还有着积极向上、乐观开朗、吉祥幸福、生活美满、幸福美满等美好祝愿,其寓意吉祥。而且旸在中国汉字里是非常多见的一个字,我们可以将这个字用在名字中来表达。旸字取名代表着孩子未来很美好而充满希望。如果将其用于起名中,则代表着孩子未来会有很多希望。同时也象征着孩子将来会有所成就。

5、旸作为名字有吉祥富贵之意。

旸这个名字,在很早的时候就被赋予了吉祥富贵的寓意,因为它在名字中的意思很多。所以有很高的吉祥富贵之意。这个名字将孩子命名为【旸】具有美好的寓意。

Copyright:2014-2023 小篆转换器 www.93805.com.cn All rights reserved.