单文档,MyView类的父类为CScrollView
我要做个固定窗口大小的程序。
PreCreateWindow(CREATESTRUCT& cs)函数中,我这么写 cs.style = WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;// | WS_THICKFRAME;
cs.style &= ~WS_BORDER;
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
int iWinBorderX = GetSystemMetrics(SM_CXBORDER);//外边X
int iWinBorderY = GetSystemMetrics(SM_CYBORDER);//外边Y
int iCaptionY = GetSystemMetrics(SM_CYCAPTION);//标题栏
int iMenuY = GetSystemMetrics(SM_CYMENUCHECK);//菜单栏
int iStausY = GetSystemMetrics(SM_CYMENUCHECK);//状态栏
int iToolBarY = 16;//这里16为toolbar的bmp图像高度
int iFixFrameX = GetSystemMetrics(SM_CXFIXEDFRAME);//围绕具有标题但无法改变尺寸的窗口X的厚度
         int iFixFrameY = GetSystemMetrics(SM_CYFIXEDFRAME);//围绕具有标题但无法改变尺寸的窗口Y的厚度
int iScrollX = GetSystemMetrics(SM_CXHSCROLL);//水平滚动条的高度和水平滚动条上箭头X的宽度
int iScrollY = GetSystemMetrics(SM_CYHSCROLL);//水平滚动条的高度和水平滚动条上箭头Y的宽度 cs.cx = 400 + iWinBorderX*2 + iFixFrameX*2 + iScrollX;
cs.cy = 300 + iWinBorderY*2 + iCaptionY + iMenuY + iStausY + iToolBarY + iFixFrameY*2 + iScrollY;我想让程序开始时候就显示一幅400*300的图像,可是还是会显示出滚动条。请教各位高手怎么办啊?各位高手帮忙指点,不胜感激啊!

解决方案 »

  1.   

    ShowScrollBar(SB_HORZ,FALSE); 
    ShowScrollBar(SB_VERT,FALSE); 或者
    SetScrollSizes 试试
      

  2.   

    谢谢楼上,可是我的本意是直接把ClentRect的大小控制为400*300,然后创建这个固定ClentRect大小的对话框。今后可以让用户打开大图,打开大图的时候旁边加入滚动条。现在问题出现在我得不到合适的cs.cx和cs.cy的大小使ClentRect大小为400*300
      

  3.   

    CRect rc(0,0,400,300);
    AdjustWindowRect(&rc, GetWindowStyle(), FALSE);
    MoveWindow(&rc);
      

  4.   

    CRect rc(0,0,400,300); 
    CalcWindowRect(&rc); // MFC直接提供了CWnd::CalcWindowRect函数来计算窗口大小,传递进去客户区大小,传出窗口大小
    MoveWindow(&rc);