📄 exports.cpp
字号:
/*
so you're probably wondering what the hell all of this crap is for...
simple, this program supports plugins. i don't expect people to make plugins or anything
i simply put this in for my own purposes because i make plugins for my own uses
if you really are interested there is an example plugin in netmsgdll.zip included in the
zip file containing this source. i have no experience with this kind of thing so you could
say that the plugin support is pretty uhhh... heh.
*/
#include "stdafx.h"
#include "ContactView.h"
#include "Netmsg.h"
#include "MainFrm.h"
#include "Conversation.h"
#include "ConversationThread.h"
#include <direct.h>
static CONTACT contact;
void LoadPlugins()
{
CFileFind Find;
BOOL bWorking;
char cwd[1024];
getcwd(cwd, sizeof(cwd));
strcat(cwd, "\\*.dll");
bWorking = Find.FindFile(cwd);
while (bWorking)
{
T_INITPLUGIN init;
HINSTANCE hIns;
if (GetApp()->View->Plugins.GetCount() > 200) return; //too many damn plugins loaded
bWorking = Find.FindNextFile();
hIns = LoadLibrary(Find.GetFileName());
if (!hIns) continue;
init = (T_INITPLUGIN) GetProcAddress(hIns, "NMInitPlugin");
if (!init) continue;
if (!init(AfxGetInstanceHandle(), VER, GetApp()->View->Plugins.GetCount() + 1)) continue;
PLUGIN *plugin = new PLUGIN;
plugin->hHandle = hIns;
plugin->TimerId = GetApp()->View->Plugins.GetCount() + 1;
strcpy(plugin->filename, Find.GetFileName());
GetApp()->View->Plugins.AddTail(plugin);
}
}
CONTACT *MakeExtContact(CONTACT *extContact, CContact *Contact)
{
strcpy(contact.awayreason, Contact->GetAwayReason());
strcpy(contact.screenname, Contact->GetScreenName());
strcpy(contact.ip, Contact->GetHostName().Get());
contact.flags = Contact->Flags;
memcpy(&contact.font, &Contact->uFont, sizeof(USERFONT));
return &contact;
}
void PluginsNotifyContactsConnected()
{
CList<PLUGIN *, PLUGIN *> &Plugins = GetApp()->View->Plugins;
POSITION pos;
pos = Plugins.GetHeadPosition();
while (pos)
{
PLUGIN *plugin = Plugins.GetNext(pos);
T_FUNCVOID func;
func = (T_FUNCVOID) GetProcAddress(plugin->hHandle, "NMContactsConnected");
if (!func) continue;
func();
}
}
void PluginsApplicationExit()
{
CList<PLUGIN *, PLUGIN *> &Plugins = GetApp()->View->Plugins;
POSITION pos;
pos = Plugins.GetHeadPosition();
while (pos)
{
PLUGIN *plugin = Plugins.GetNext(pos);
T_FUNCVOID func;
func = (T_FUNCVOID) GetProcAddress(plugin->hHandle, "NMApplicationExit");
if (!func) continue;
func();
FreeLibrary(plugin->hHandle);
Plugins.RemoveAt(Plugins.Find(plugin));
delete plugin;
}
}
void PluginsContactAdded(CContact *Contact)
{
CList<PLUGIN *, PLUGIN *> &Plugins = GetApp()->View->Plugins;
POSITION pos;
if (!IsContact(Contact)) return;
pos = Plugins.GetHeadPosition();
while (pos)
{
PLUGIN *plugin = Plugins.GetNext(pos);
T_FUNCVOIDPTR func;
func = (T_FUNCVOIDPTR) GetProcAddress(plugin->hHandle, "NMContactAdded");
if (!func) continue;
func((CONTACT *)MakeExtContact(&contact, Contact));
}
}
void PluginsContactDeleted(CContact *Contact)
{
CList<PLUGIN *, PLUGIN *> &Plugins = GetApp()->View->Plugins;
POSITION pos;
if (!IsContact(Contact)) return;
pos = Plugins.GetHeadPosition();
while (pos)
{
PLUGIN *plugin = Plugins.GetNext(pos);
T_FUNCCHAR func;
func = (T_FUNCCHAR) GetProcAddress(plugin->hHandle, "NMContactDeleted");
if (!func) continue;
func(MakeExtContact(&contact, Contact)->ip);
}
}
void PluginsContactStatusChanged(CContact *Contact, unsigned long mask)
{
CList<PLUGIN *, PLUGIN *> &Plugins = GetApp()->View->Plugins;
POSITION pos;
if (!IsContact(Contact)) return;
pos = Plugins.GetHeadPosition();
while (pos)
{
PLUGIN *plugin = Plugins.GetNext(pos);
T_FUNCSTATUS func;
func = (T_FUNCSTATUS) GetProcAddress(plugin->hHandle, "NMContactStatusChanged");
if (!func) continue;
func((CONTACT *)MakeExtContact(&contact, Contact), mask);
}
}
void PluginsConversationWindowOpened(CContact *Contact)
{
CList<PLUGIN *, PLUGIN *> &Plugins = GetApp()->View->Plugins;
POSITION pos;
if (!IsContact(Contact)) return;
pos = Plugins.GetHeadPosition();
while (pos)
{
PLUGIN *plugin = Plugins.GetNext(pos);
T_FUNCCHAR func;
func = (T_FUNCCHAR) GetProcAddress(plugin->hHandle, "NMConversationWindowOpened");
if (!func) continue;
func(MakeExtContact(&contact, Contact)->ip);
}
}
void PluginsMessageReceived(CContact *Contact, char *Message)
{
CList<PLUGIN *, PLUGIN *> &Plugins = GetApp()->View->Plugins;
POSITION pos;
if (!IsContact(Contact)) return;
pos = Plugins.GetHeadPosition();
while (pos)
{
PLUGIN *plugin = Plugins.GetNext(pos);
T_MESSAGE func;
func = (T_MESSAGE) GetProcAddress(plugin->hHandle, "NMMessageReceived");
if (!func) continue;
func(MakeExtContact(&contact, Contact)->ip, Message);
}
}
void PluginsTimer(unsigned int nIDEvent)
{
CList<PLUGIN *, PLUGIN *> &Plugins = GetApp()->View->Plugins;
POSITION pos;
pos = Plugins.GetHeadPosition();
while (pos)
{
PLUGIN *plugin = Plugins.GetNext(pos);
if (plugin->TimerId == LOBYTE(nIDEvent))
{
T_TIMER func;
func = (T_TIMER) GetProcAddress(plugin->hHandle, "NMTimer");
if (!func) continue;
func(HIBYTE(nIDEvent));
}
else continue;
}
}
void PluginsMessageSent(CContact *Contact, char *Message)
{
CList<PLUGIN *, PLUGIN *> &Plugins = GetApp()->View->Plugins;
POSITION pos;
pos = Plugins.GetHeadPosition();
while (pos)
{
PLUGIN *plugin = Plugins.GetNext(pos);
T_MESSAGESEND func;
func = (T_MESSAGESEND) GetProcAddress(plugin->hHandle, "NMMessageSend");
if (!func) continue;
func(MakeExtContact(&contact, Contact)->ip, Message);
}
}
BOOL __declspec(dllexport) __stdcall
NMAppendMainMenu(int whichMenu, int nMenu, char *szText, void (__stdcall *lpfn)(void))
{
return GetApp()->MainFrame->AppendMainMenu(whichMenu, nMenu, szText, lpfn);
}
BOOL __declspec(dllexport) __stdcall
NMDeleteMainMenu(int whichMenu, int nMenu, unsigned int nItem)
{
return GetApp()->MainFrame->DeleteMainMenu(whichMenu, nMenu, nItem);
}
BOOL __declspec(dllexport) __stdcall
NMSendMessage(char *Ip, char *szMessage)
{
if (!GetApp()->View->GetContact(IP(Ip))) return FALSE;
MESSAGE *Msg = new MESSAGE;
Msg->To = GetApp()->View->GetContact(IP(Ip));
strncpy(Msg->Message, szMessage, 500);
Msg->Message[500] = 0;
if (Msg->To->IsConvWindowOpen())
{
Msg->To->pThread->Conv->SendMessage(WM_RECEIVEDMESSAGE, 1, (LPARAM)nstrdup(Msg->Message));
}
return ::SendMessage(GetApp()->View->GetSafeHwnd(), WM_SENDTHISMESSAGE, 0, (LPARAM)Msg);
}
BOOL __declspec(dllexport) __stdcall
NMGetSelectedContact(CONTACT *extContact)
{
CContact *Contact = GetApp()->View->GetFromListItem(GetApp()->View->GetSelectionMark());
if (Contact)
{
MakeExtContact(extContact, Contact);
return TRUE;
}
return FALSE;
}
BOOL __declspec(dllexport) __stdcall
NMGetContactInfo(char *Ip, CONTACT *extContact)
{
CContact *Contact = GetApp()->View->GetContact(IP(Ip));
if (Contact)
{
MakeExtContact(extContact, Contact);
return TRUE;
}
return FALSE;
}
void __declspec(dllexport) __stdcall
NMSetScreenName(char *szNewName)
{
GetApp()->View->ChangeMyName(szNewName);
}
void __declspec(dllexport) __stdcall
NMSetAway(bool bAway, char *szReason)
{
GetApp()->View->Me.SetAway(bAway, szReason ? szReason : "");
}
void __declspec(dllexport) __stdcall
NMSetOffline(bool bOffline)
{
GetApp()->View->SetMeOffline(bOffline);
}
void __declspec(dllexport) __stdcall
NMSetTimer(BYTE nPluginID, BYTE nIDEvent, unsigned int nDelay)
{
GetApp()->MainView->SetTimer(MAKEWORD(nPluginID, nIDEvent), nDelay, NULL);
}
HWND __declspec(dllexport) __stdcall
NMGetHwnd()
{
return GetApp()->MainFrame->GetSafeHwnd();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -