How do I close a Desktop window using Matlab commands?

Like 'winopen' opens a desktop window, is there a command in Matalab that closes a particular desktop window (which does NOT belong to Matlab) ?
e.g. the code:
<MatlabCommand>('C:\Program Files\Altair')
closes the given desktop window.

 採用された回答

Walter Roberson
Walter Roberson 2018 年 7 月 4 日

0 投票

You can use system() to invoke taskkill

3 件のコメント

Asit Kumar
Asit Kumar 2018 年 7 月 4 日
If I taskkill explorer.exe all the desktop windows will close, how do I close only a particular window (as per user input)?
Walter Roberson
Walter Roberson 2018 年 7 月 4 日
Asit Kumar
Asit Kumar 2018 年 7 月 5 日
For some reason the script in the page you referred to didn't work. However, I looked for similar ideas involving the use of VBS and found a script that worked.
Thank you for the insight.

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2018 年 7 月 4 日
編集済み: Jan 2018 年 7 月 4 日

2 投票

This does not seem to be a task for Matlab. What about AutoHotKey (link)?
If you have a C compiler, try this:
// File: KillWindow.c
// Compile: mex -O KillWindow.c
//
// ATTENTION: !!! This kills the window !!!
// !!! There is no request to save changes !!!
#include <windows.h>
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
HWND hWnd;
size_t Len;
char *Name;
if (nrhs < 1 || !mxIsChar(prhs[0])) {
mexErrMsgIdAndTxt("JSimon:KillWindow:NInput",
"KillWindow needs a char vector as input.");
}
// Get name as C string:
Len = mxGetNumberOfElements(prhs[0]);
Name = (char *) mxCalloc(Len + 1, sizeof(char));
mxGetString(prhs[0], Name, Len + 1);
// Find window handle of the OS:
hWnd = FindWindow(NULL, Name);
mxFree(Name);
// Close window inf found:
if (hWnd != 0) {
// uint WM_SYSCOMMAND = 0x0112; int SC_CLOSE = 0xF060;
SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
}
}
After compiling, call it as:
doc % Open Matlab's Help window, window name is "Help"
pause(2)
KillWindow('Help'); % Help window is closed
Again: Killing a window, which contains modified data, will not ask you for saving!
Isn't it strange that you can access windows of other applications through the WindowsAPI?

3 件のコメント

Asit Kumar
Asit Kumar 2018 年 7 月 5 日
Unfortunately, I have to accomplish the task using Matlab only. I found a way using VB script and used Matlab to create and run the VBS. So problem solved :)
Christopher Rose
Christopher Rose 2020 年 11 月 18 日
Great, share the answer

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by