发新话题
打印

[GUI界面] 问:如何用语句实现matlab图形窗口的最大化

问:如何用语句实现matlab图形窗口的最大化

图形窗口启动时为默认模式,我想用语句实现使它最大化
谢谢!

TOP

h = figure;
set(gcf,'outerposition',get(0,'screensize'));
本帖最近评分记录
  • lxq +25 2007-2-3 11:20 理由:回答比较全面
Email失效、QQ丢失、MSN没有、站内短信关闭
有事请在论坛matlab版留言,提问勿指名

TOP

引用:
原帖由 shuishenshen 于 2007-2-3 10:33 发表
图形窗口启动时为默认模式,我想用语句实现使它最大化
谢谢!
happy教授的方法没有问题,或者使用以下方法:
复制内容到剪贴板
代码:

h = figure;
set(gcf,'units','normalized','position',[0,0,1,0.9]);
还可以参考其他方法:
http://www.simwe.com/forum/viewthread.php?tid=161775
本人不使用任何聊天工具,请陌生人勿扰。有问题需要求助请发帖到论坛上,请勿使用短消息。欢迎光临并注册以下两个影视论坛:汉风论坛网上TVB论坛

TOP

回复 板凳 eight 的帖子

非常感谢3楼的回答
我想知道‘units’、'normalized'都表示什么意思??
能有解答的么??
不甚感激

TOP

回复 地板 tuoniao992002 的帖子

Units                        {pixels} | normalized | inches | centimeters  | points | characters

Unit of measurement. This property specifies the units MATLAB uses to interpret size and location data. All units are measured from the lower-left corner of the screen. Normalized units map the lower-left corner of the screen to (0,0) and the upper right corner to (1.0,1.0). inches, centimeters, and points are absolute units (one point equals 1/72 of an inch). Characters are units defined by characters from the default system font; the width of one unit is the width of the letter x, the height of one character is the distance between the baselines of two lines of text.

This property affects the PointerLocation and ScreenSize properties. If you change the value of Units, it is good practice to return it to its default value after completing your operation so as not to affect other functions that assume Units is set to the default value.
笛卡尔 : 我思故我在
抱歉个人无MSN/QQ, 直接发帖大家一起讨论! 勿发短消息询问!
发帖者应设法让人引起兴趣去试, 时间有限嘛!

TOP

引用:
原帖由 eight 于 2007-2-3 11:29 发表


happy教授的方法没有问题,或者使用以下方法:

h = figure;
set(gcf,'units','normalized','position',[0,0,1,0.9]);


还可以参考其他方法:
http://www.simwe.com/forum/viewthread.php?tid=161775
这个问题没那么简单~
1、happy的方法实际上只是把窗口铺满屏幕,可以看见窗口的下面被Windows系统最下面的导航栏(就是含有“开始”和快速启动的那一栏)遮盖住了。
2、eight 的方法也许是想把被Windows系统最下面的导航栏遮盖住的那一部分显示出来,显然“0.9”的选值并不理想。

如果要想用命令实现如点击最大化按钮一样的效果,并不简单。
1、如果用java,那matlab的图形界面功能就无限强大。参考http://www.mathworks.fr/matlabcentral/newsreader/view_thread/149166,上面有如何使用undocumented的java来实现窗口最大化。
2、正如eight指出的 http://forum.simwe.com/viewthread.php?tid=161775给出的程序非常不错,我们也可以写出自己的.m文件来把dll包装一下。
3、也可以试试http://www.mathworks.com/matlabcentral/fileexchange/10274,其中也给出了dell文件。
本帖最近评分记录
  • sogooda 体能 +5 2009-5-22 13:29 理由:这是一个非常有见地的意见

TOP

不错,在mathworks的fileexchange的那个链接下有一个.c文件可以看出,老外也是写了一个C-MEX调用windows的API实现的:
复制内容到剪贴板
代码:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
        /* declare variables */
        HWND hWnd;
        long nStyle;
        int strLength;
        char *windowname, *resizeState;

        /* length of the string */
        strLength = mxGetN(prhs[0])+1;
        /* allocate memory for the window name */
        /* MATLAB frees the allocated memory automatically */
        windowname = mxCalloc(strLength, sizeof(char));
        /* copy the variable from MATLAB */
        mxGetString(prhs[0],windowname,strLength);

        /* length of the string */
        strLength = mxGetN(prhs[1])+1;
        /* allocate memory for the resize state */
        /* MATLAB frees the allocated memory automatically */
        resizeState = mxCalloc(strLength, sizeof(char));
        /* copy the variable from MATLAB */
        mxGetString(prhs[1],resizeState,strLength);


        /* handle of the window */
        hWnd = FindWindow(NULL,windowname);

        /* get current window style */
        nStyle = GetWindowLong(hWnd,GWL_STYLE);

        /* make sure that the window can be resized */
        SetWindowLong(hWnd,GWL_STYLE,nStyle | WS_MAXIMIZEBOX);

        /* maximize window */
        ShowWindow(hWnd,SW_MAXIMIZE);

        /* window is not resizable */
        if(strcmp(resizeState,"off") == 0)
        {
                /* restore the settings */
                SetWindowLong(hWnd,GWL_STYLE,nStyle);
        }

        /* redraw the menu bar */
        DrawMenuBar(hWnd);
}
与SCIE的程序如出一辙。SCIE还曾经写过一个很有用的,用于获得figure窗口句柄的函数:
http://forum.simwe.com/thread-779810-1-3.html

至于java的UNDOCUMENTED属性,个人建议少用或者不用,其中一些在后续版本中将被取消,例如javaframe属性。
本帖最近评分记录
  • sogooda 体能 +5 2009-5-22 13:29 理由:这是一个非常有见地的意见
look the mess what we done!

TOP

发新话题
最近访问的版块