File Exchange

image thumbnail

Matlab loadlibrary user32.dll for windows functions in one class

version 1.3.0.0 (4.11 KB) by Vishnu
Implement topmostmsg, .Net forms, Tray notification, findwindow, showwindow & setforegroundwindow

1 Download

Updated 18 Oct 2017

View License

[UPDATE]
Guess what I just ran it in new MAT LAB R2017b in Windows 10 (x64 October 2017 Updated version) and there were errors.
[Bug Fixed]
1. Error in <Obj>.waitforuser() - waitfor() requires a valid Matlab handle - Fixed
2. Loadlibrary STDCALL not supported - Fixed
I have just tested it, it worked fine. at least all the examples work. if there are more errors just let me know.
This submission is an implementation of .Net functions like the t
opmostmsg, .Net forms, Tray notification along with my technique to successfully load user32.dll in matlab without a userproto function. Windows functions findwindow, showwindow and setforegroundwindow are currently implemented.
SysObj = SystemTools; SysObj.help;
waitforuser Function:
Syntax: <ClassObj>.waitforuser or <ClassObj>.waitforuser('Short Message')
View General Help.
TopmostMsg Function:
Syntax: <ClassObj>.TopmostMsg('Message goes here...', 'title', System.Windows.Forms.MessageBoxButtons.YesNo)
View General Help.
Notify Function:
Syntax: <ClassObj>.Notify('Balloon Tool Tip', 'Balloon Title', 'Notification App', [pwd '\icon.ico']);

Make sure the icon.ico file is present in current folder to use this syntax.
To remove tray icon use <NotificationIconObj>.Visible = false; followed by <NotificationIconObj>.Dispose();.

StartProcess Function:

Syntax: Stats = <ClassObj>.StartProcess() or <ClassObj>.StartProcess(<Full Path with Ext as String>)

View General Help.

AppSelect Function:

Syntax: Stats = <ClassObj>.AppSelect('Process Name', 'Window State')

Run the demo code below to see it in action.

...Demo Code...

SysObj = SystemTools;
SysObj.NETFramework();
ProcCred = SysObj.StartProcess;
if ~ProcCred.HasExited
AppSelStats = SysObj.AppSelect(char(ProcCred.MainWindowTitle), 'SW_SHOWMAXIMIZED');
if AppSelStats>0, disp('Operation Successfull');
else disp('Operation Failed'); end
else msgbox('The Process has exited');
end
<<<<<<<<<>>>>>>>>>

General Help:
Every function in this class requires .NET support.
So make sure to call <Class Obj>.NETFramework() at least once before any function calls.

Cite As

Vishnu (2020). Matlab loadlibrary user32.dll for windows functions in one class (https://www.mathworks.com/matlabcentral/fileexchange/49149-matlab-loadlibrary-user32-dll-for-windows-functions-in-one-class), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)

Yuhao Sun

Your work is what I am looking for to study.
By the way, if I want to call some strange function in this library with the C struct pointer input like BOOL GetWindowRect(hWnd, LPRECT); How should I add this in your program?I tried libstruct to convert but it seems not work.

Vishnu

@QiQin Zhan:

Just change the stdcall to cdecl

I've fixed it. check it out..

Vishnu

I am using MATLAB Version: 8.5.0.197613 (R2015a) x86... on Win 7 Ultimate... So may be you guys try the same configuration.

Manu French

This is exactly what I am looking for. Tray notification work very well but I am getting a error message 'The function call type stdcall is not supported' when running ShowWindow. Initially I thought it was due to missing user32.h but I still get the same error. Any help on this will be appreciated. Thanks...

I get the stdcall error on ML 2014 64bit windows

Vishnu

Following the "NOT WORKING" Accusations I have uploaded a working video proof...

Vishnu

Following the "NOT WORKING" acquisitions I have uploaded a working video proof...

Sebastian

I also had the 'unsupported stdcall' error using R2013b and R2015a.

I also got an error trying to start the demo with a 32-bit Matlab on a 64-bit machine.

QiQin Zhan

when I run the 'ShowWindow_Demo' Errors come up:
Error using loadlibrary (line 440)
The function call type stdcall is not supported

Error in SystemTools.AppSelect (line 210)
if ~libisloaded('WinUser32Lib'), loadlibrary('user32.dll','LoadLib.mat','alias','WinUser32Lib');

Error in ShowWindow_Demo (line 8)
AppSelStats = SysObj.AppSelect(char(ProcCred.MainWindowTitle), 'SW_SHOWNORMAL');

What's wrong with the function of loadlibrary? I'm using Matlab R2014b

Updates

1.3.0.0

[Mostly Bug Fixes]
Just Nothing I uploaded the wrong file lads.. this ones new

1.3.0.0

[Error]
1. Error in <Obj>.waitforuser() - waitfor() requires a valid Matlab handle - Fixed
2. Loadlibrary STDCALL not supported - Fixed
I have just tested it, it worked fine. at least all the examples work. if there are more errors just let me know.

1.3.0.0

[Mostly Bug Fix with new Matlab x64 and new Windows 10 x 64]
1. Error in <Obj>.waitforuser() - waitfor() requires a valid Matlab handle - Fixed
2. Loadlibrary STDCALL not supported - Fixed

1.2.0.0

Added Working Video Proof

1.2.0.0

updated

1.1.0.0

Update 0

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: WindowAPI