声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 8888|回复: 6

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

[复制链接]
发表于 2007-2-3 10:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
图形窗口启动时为默认模式,我想用语句实现使它最大化
谢谢!
回复
分享到:

使用道具 举报

发表于 2007-2-3 10:46 | 显示全部楼层
h = figure;
set(gcf,'outerposition',get(0,'screensize'));

评分

1

查看全部评分

发表于 2007-2-3 11:29 | 显示全部楼层
原帖由 shuishenshen 于 2007-2-3 10:33 发表
图形窗口启动时为默认模式,我想用语句实现使它最大化
谢谢!


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

  1. h = figure;
  2. set(gcf,'units','normalized','position',[0,0,1,0.9]);
复制代码


还可以参考其他方法:
http://www.simwe.com/forum/viewthread.php?tid=161775
发表于 2009-4-10 10:00 | 显示全部楼层

回复 板凳 eight 的帖子

非常感谢3楼的回答
我想知道‘units’、'normalized'都表示什么意思??
能有解答的么??
不甚感激
发表于 2009-4-10 15:38 | 显示全部楼层

回复 地板 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.
发表于 2009-5-22 09:09 | 显示全部楼层


这个问题没那么简单~
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文件。

评分

2

查看全部评分

发表于 2009-5-22 12:38 | 显示全部楼层
本帖最后由 coohit 于 2016-8-16 10:05 编辑

不错,在mathworks的fileexchange的那个链接下有一个.c文件可以看出,老外也是写了一个C-MEX调用windows的API实现的:
  1. void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
  2. {
  3.         /* declare variables */
  4.         HWND hWnd;
  5.         long nStyle;
  6.         int strLength;
  7.         char *windowname, *resizeState;

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

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


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

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

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

  28.         /* maximize window */
  29.         ShowWindow(hWnd,SW_MAXIMIZE);

  30.         /* window is not resizable */
  31.         if(strcmp(resizeState,"off") == 0)
  32.         {
  33.                 /* restore the settings */
  34.                 SetWindowLong(hWnd,GWL_STYLE,nStyle);
  35.         }

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

至于java的UNDOCUMENTED属性,个人建议少用或者不用,其中一些在后续版本中将被取消,例如javaframe属性。

评分

2

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-18 06:35 , Processed in 0.261953 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表