CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

一个SDI的程序,如何一开始就固定客户区的大小(就是c**view吧),谢谢

楼主xpaul(paul)2003-02-01 15:43:39 在 VC/MFC / 基础类 提问

在CMAINFRAME的PRECREATE**()中只能固定mainframe的大小,客户区不能用C**view的PRECREATE**()来固定,怎么办呢?谢谢! 问题点数:50、回复次数:12Top

1 楼LIFEForSoft(北京原来叫“阉”京)回复于 2003-02-01 16:51:45 得分 5

CWnd::SetWindowPos  
  BOOL   SetWindowPos(   const   CWnd*   pWndInsertAfter,   int   x,   int   y,   int   cx,   int   cy,   UINT   nFlags   );  
   
  Return   Value  
   
  Nonzero   if   the   function   is   successful;   otherwise   0.  
   
  Parameters  
   
  pWndInsertAfter  
   
  Identifies   the   CWnd   object   that   will   precede   this   CWnd   object   in   the   Z-order.   This   parameter   can   be   a   pointer   to   a   CWnd   or   a   Pointer   to   one   of   the   following   values:    
   
  wndBottom       Places   the   window   at   the   bottom   of   the   Z-order.   If   this   CWnd   is   a   topmost   window,   the   window   loses   its   topmost   status;   the   system   places   the   window   at   the   bottom   of   all   other   windows.  
   
   
  wndTop       Places   the   window   at   the   top   of   the   Z-order.  
   
   
  wndTopMost       Places   the   window   above   all   nontopmost   windows.   The   window   maintains   its   topmost   position   even   when   it   is   deactivated.  
   
   
  wndNoTopMost       Repositions   the   window   to   the   top   of   all   nontopmost   windows   (that   is,   behind   all   topmost   windows).   This   flag   has   no   effect   if   the   window   is   already   a   nontopmost   window.  
  See   the   “Remarks”   section   for   this   function   for   rules   about   how   this   parameter   is   used.  
   
  x  
   
  Specifies   the   new   position   of   the   left   side   of   the   window.  
   
  y  
   
  Specifies   the   new   position   of   the   top   of   the   window.  
   
  cx  
   
  Specifies   the   new   width   of   the   window.  
   
  cy  
   
  Specifies   the   new   height   of   the   window.  
   
  nFlags  
   
  Specifies   sizing   and   positioning   options.   This   parameter   can   be   a   combination   of   the   following:    
   
  SWP_DRAWFRAME       Draws   a   frame   (defined   when   the   window   was   created)   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   the   nontopmost   group   (depending   on   the   setting   of   the   pWndInsertAfter   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   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   and   scroll   bars),   and   any   part   of   the   parent   window   uncovered   as   a   result   of   the   moved   window.   When   this   flag   is   set,   the   application   must   explicitly   invalidate   or   redraw   any   parts   of   the   window   and   parent   window   that   must   be   redrawn.  
   
   
  SWP_NOREPOSITION       Same   as   SWP_NOOWNERZORDER.    
   
   
  SWP_NOSENDCHANGING       Prevents   the   window   from   receiving   the   WM_WINDOWPOSCHANGING   message.  
   
   
  SWP_NOSIZE       Retains   current   size   (ignores   the   cx   and   cy   parameters).  
   
   
  SWP_NOZORDER       Retains   current   ordering   (ignores   pWndInsertAfter).  
   
   
  SWP_SHOWWINDOW       Displays   the   window.    
  Remarks  
   
  Call   this   member   function   to   change   the   size,   position,   and   Z-order   of   child,   pop-up,   and   top-level   windows.  
   
  Windows   are   ordered   on   the   screen   according   to   their   Z-order;   the   window   at   the   top   of   the   Z-order   appears   on   top   of   all   other   windows   in   the   order.  
   
  All   coordinates   for   child   windows   are   client   coordinates   (relative   to   the   upper-left   corner   of   the   parent   window’s   client   area).    
   
  A   window   can   be   moved   to   the   top   of   the   Z-order   either   by   setting   the   pWndInsertAfter   parameter   to   &wndTopMost   and   ensuring   that   the   SWP_NOZORDER   flag   is   not   set   or   by   setting   a   window’s   Z-order   so   that   it   is   above   any   existing   topmost   windows.   When   a   nontopmost   window   is   made   topmost,   its   owned   windows   are   also   made   topmost.   Its   owners   are   not   changed.    
   
  A   topmost   window   is   no   longer   topmost   if   it   is   repositioned   to   the   bottom   (&wndBottom)   of   the   Z-order   or   after   any   nontopmost   window.   When   a   topmost   window   is   made   nontopmost,   all   of   its   owners   and   its   owned   windows   are   also   made   nontopmost   windows.  
   
  If   neither   SWP_NOACTIVATE   nor   SWP_NOZORDER   is   specified   (that   is,   when   the   application   requests   that   a   window   be   simultaneously   activated   and   placed   in   the   specified   Z-order),   the   value   specified   in   pWndInsertAfter   is   used   only   in   the   following   circumstances:    
   
  Neither   &wndTopMost   nor   &wndNoTopMost   is   specified   in   the   pWndInsertAfter   parameter.  
   
   
  This   window   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   the   Z-order   of   an   activated   window   without   restrictions.  
   
  A   nontopmost   window   may   own   a   topmost   window,   but   not   vice   versa.   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.  
   
  With   Windows   versions   3.1   and   later,   windows   can   be   moved   to   the   top   of   the   Z-order   and   locked   there   by   setting   their   WS_EX_TOPMOST   styles.   Such   a   topmost   window   maintains   its   topmost   position   even   when   deactivated.   For   example,   selecting   the   WinHelp   Always   On   Top   command   makes   the   Help   window   topmost,   and   it   then   remains   visible   when   you   return   to   your   application.  
   
  To   create   a   topmost   window,   call   SetWindowPos   with   the   pWndInsertAfter   parameter   equal   to   &wndTopMost,   or   set   the   WS_EX_TOPMOST   style   when   you   create   the   window.  
   
  If   the   Z-order   contains   any   windows   with   the   WS_EX_TOPMOST   style,   a   window   moved   with   the   &wndTopMost   value   is   placed   at   the   top   of   all   nontopmost   windows,   but   below   any   topmost   windows.   When   an   application   activates   an   inactive   window   without   the   WS_EX_TOPMOST   bit,   the   window   is   moved   above   all   nontopmost   windows   but   below   any   topmost   windows.  
   
  If   SetWindowPos   is   called   when   the   pWndInsertAfter   parameter   is   &wndBottom   and   CWnd   is   a   topmost   window,   the   window   loses   its   topmost   status   (WS_EX_TOPMOST   is   cleared),   and   the   system   places   the   window   at   the   bottom   of   the   Z-order.  
   
  Top

2 楼kingcom_xu(冷羽)回复于 2003-02-01 18:30:27 得分 0

>>在CMAINFRAME的PRECREATE**()中只能固定mainframe的大小,客户区不能用C**view的PRECREATE**()来固定,怎么办呢?谢谢!  
   
  固定是什么意思?客户区大小是由cmainframe决定的呀Top

3 楼xpaul(paul)回复于 2003-02-01 22:45:36 得分 0

to:   kingcom_xu(我的刀是杀不了人的)    
  举个例子吧,我让客户区永远是500*400,由cmainframe怎么办  
  Top

4 楼kingcom_xu(冷羽)回复于 2003-02-01 22:57:38 得分 0

是SDI的吧?这简单!~  
  BOOL   CMainFrame::PreCreateWindow(CREATESTRUCT&   cs)  
  {  
  if(   !CFrameWnd::PreCreateWindow(cs)   )  
  return   FALSE;  
  cs.style&=~(WS_MAXIMIZEBOX|WS_THICKFRAME   );  
   
  return   TRUE;  
  }  
  Top

5 楼xpaul(paul)回复于 2003-02-01 23:23:55 得分 0

这个方法我不太认同,我需要这两个样式  
  有没有其他的办法列  
  我的办法是:  
  BOOL   CMainFrame::PreCreateWindow(CREATESTRUCT&   cs)  
  {  
  if(   !CFrameWnd::PreCreateWindow(cs)   )  
  return   FALSE;  
  cs.cx=我要的客户区宽度+12;  
   
  cs.cy=我要的客户区高度+73;  
   
  return   TRUE;  
  }  
   
  我不想用这个办法  
  Top

6 楼kingcom_xu(冷羽)回复于 2003-02-01 23:27:51 得分 0

明白你的意思了...  
  学习...Top

7 楼xpaul(paul)回复于 2003-02-01 23:31:52 得分 0

老大,你是两颗五角星阿,有没有其他的办法阿,帮忙,谢谢了Top

8 楼kingcom_xu(冷羽)回复于 2003-02-01 23:39:46 得分 0

搞定:  
  在oncreate中加上如下代码  
  CRect   rect;  
  GetWindowRect(&rect);  
  rect.bottom=rect.top+400;  
  rect.right=rect.left+500;  
  this->CalcWindowRect(&rect,CWnd::adjustBorder);  
  this->MoveWindow(rect.top,rect.left,rect.Width(),rect.Height());  
  Top

9 楼kingcom_xu(冷羽)回复于 2003-02-01 23:40:40 得分 0

呵呵...我的两个星都是抢+骗来的...  
  专家分跟实力沾不了边呀..Top

10 楼kingcom_xu(冷羽)回复于 2003-02-01 23:41:21 得分 43

简洁的写法  
  CRect   rect(0,0,500,400);  
  this->CalcWindowRect(&rect,CWnd::adjustBorder);  
  this->MoveWindow(rect.top,rect.left,rect.Width(),rect.Height());Top

11 楼showmetheway(雪儿甜心)回复于 2003-02-02 00:15:29 得分 2

xpaul(paul)    
  我的办法是:  
  BOOL   CMainFrame::PreCreateWindow(CREATESTRUCT&   cs)  
  {  
  if(   !CFrameWnd::PreCreateWindow(cs)   )  
  return   FALSE;  
  cs.cx=我要的客户区宽度+12;  
   
  cs.cy=我要的客户区高度+73;  
   
  return   TRUE;  
  }  
   
  我不想用这个办法  
   
    kingcom_xu(我的刀是杀不了人的)    
  明白你的意思了...  
  学习...  
  简洁的写法  
  CRect   rect(0,0,500,400);  
  this->CalcWindowRect(&rect,CWnd::adjustBorder);  
  this->MoveWindow(rect.top,rect.left,rect.Width(),rect.Height());  
   
  恕我愈顿,怎么没看出来这两种方法有什么区别。。  
  Top

12 楼kingcom_xu(冷羽)回复于 2003-02-02 00:22:53 得分 0

#%$@%@#...  
   
  xpaul(paul)的方法得手动计算主窗口上的非客户区无素的大小。。。而且当用户在显示属性里改变了比如标题栏的高度的话。。。这种方法就失效了。。。  
   
  而CalcWindowRect是MFC的CWnd自己计算加上rect中定义的客户区大小后把非客户区加到rect上。。。。。。。  
  Top

相关问题

  • C# 中DataGrid固定第一列
  • 求:固定表头、表格体滚动的DataGrid(要C#版)。
  • 在C#的EXE程序中怎样固定datagrid的列?
  • 求助:C#中如何对DataGrid设定固定列宽??
  • 如何固定SDI框架窗口?请指点
  • 如何让SDI标题栏显示固定内容?
  • 请问C++ View的网址
  • C#.NET 有Document/View吗?
  • 请问如何在C#中声明一个有固定长度的 string ?
  • C#中怎样让DataGrid控件的大小固定不变??高手快来呀

关键词

  • 客户
  • cwnd
  • 固定
  • 大小
  • 客户区
  • topmost
  • places
  • order

得分解答快速导航

  • 帖主:xpaul
  • LIFEForSoft
  • kingcom_xu
  • showmetheway

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo