Post by Thomas RoggHello group!
I am developing a Windows (Win32) application. Is there any way to tell
a running instance of mIRC to set the user to away and stuff like that?
I guess the easiest way would be for my program to write that stuff in a
temporary script. But how, if possible, can my program (process) tell
the mIRC instance to start the script?
Thank you very much,
Thomas
Use SendMessage() command and eveluate function. You can easily control
mIRC and evaluate variables. This is how you create mutex (really
recommended) and evaluate or command in Delphi (if you use C++, then it
is easy to derive the code):
procedure CreateMutex;
begin
//create mutex
FhFileMap := CreateFileMapping(INVALID_HANDLE_VALUE, nil,
PAGE_READWRITE, 0, 4096, 'mIRC');
FmData := MapViewOfFile(FhFileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
hMutex := windows.CreateMutex(nil, false, 'BWI_Mutex');
if GetLastError = 183 then
hMutex := OpenMutex(SYNCHRONIZE, false, 'BWI_Mutex');
end;
procedure Command(c: string; cMethod: integer);
begin
if hmutex <> 0 then
WaitForSingleObject(hMutex, 1000);
StrPCopy(FmData, c);
SendMessage(mircHandle, WM_MCOMMAND, cMethod, 0);
ReleaseMutex(hMutex);
end;
function Evaluate(c: ansistring): ansistring;
begin
if hmutex <> 0 then
WaitForSingleObject(hMutex, 1000);
StrPCopy(FmData, c);
SendMessage(mircHandle, WM_MEVALUATE, 0, 0);
Result := FmData;
ReleaseMutex(hMutex);
end;
///end code
WM_MCOMMAND and WM_MEVALUATE are defined as constants:
WM_MCOMMAND = WM_USER + 200;
WM_MEVALUATE = WM_USER + 201;
To get the mIRC handle, use FindWindow() or FindWindowEx() API call.
Note that this will get the handle of the mIRC window with lowest
handle, ie if there are more then one mIRC running, you'll have problem
locating correct mIRC.
However, if you can call the program from mIRC, you can use
(undocumented feature) $window(-2).handle, which will give handle to
main mIRC window.
So if you want to set user away from your program:
a) FindWindow
b) CreateMutex (I recommend 'BWI_Mutex' (case-sensitive) as mutex name,
as quite a lot of mIRC dll's/programs use that)
c) command('//away Set by external program',1);
That will set the user away with the message 'Set by external program'
If you want to know, if user is already away, step c will be:
c)somevar := evaluate('$away');
and reply will be mIRC's $true/$false