home *** CD-ROM | disk | FTP | other *** search
- // demoplugin.cpp : Defines the entry point for the DLL application.
- //
-
- #include "stdafx.h"
- #include "..\..\TlenSources\plugin\plugin_struct.h"
- #include "..\..\TlenSources\plugin\plugin_sound_events.h"
- #include "AggressiveOptimize.h"
- #include "resource.h"
- #include <stdlib.h>
- #include <stdio.h>
-
- HINSTANCE hInst;
- TLENPLUGINFUNCTIONS *tlen_functions;
- HWND window = NULL;
- HANDLE soundHook;
-
- TLENPLUGININFO pluginInfo={
- sizeof(TLENPLUGININFO),
- "Sound events demo",
- PLUGIN_API_VERSION,
- MAKE_DWORD_VERSION(1,0,0,0),
- "Demonstracja funkcji i zdarze± dƒwiΩkowych",
- "⌐ Prawa autorskie",
- "Producent",
- "E@mail",
- "http://www",
- 0,
- 0,
- 0,
- 0
- };
-
- extern "C" __declspec(dllexport) TLENPLUGININFO* GetPluginInfo(DWORD TlenVersion);
- extern "C" __declspec(dllexport) int LoadPlugin(TLENPLUGINFUNCTIONS *tlen_functions);
- extern "C" __declspec(dllexport) int UnloadPlugin(void);
-
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wparam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_INITDIALOG:
- {
- ShowWindow(hWnd, SW_SHOW);
- UpdateWindow(hWnd);
- return TRUE;
- }
- case WM_DESTROY:
- {
- window = NULL;
- break;
- }
- case WM_CLOSE:
- {
- DestroyWindow(hWnd);
- break;
- }
- case WM_COMMAND:
- {
- static int value;
- switch (LOWORD(wparam))
- {
- case IDC_BUTTON1:
- {
- SoundEventDef sdef;
- InitializeStruct(sdef);
- sdef.EventCode = GetDlgItemInt(window, IDC_EDIT2, NULL, FALSE);
- tlen_functions->CallTlenFunction(hInst, TLEN_SOUNDENGINE_PLAYSOUND, (WPARAM) &sdef, NULL);
- break;
- }
- }
-
- break;
- }
- }
-
- return 0;
- }
-
- void AddTextToWindow(char *text, int len)
- {
- HWND hw = GetDlgItem(window, IDC_EDIT1);
- int length = GetWindowTextLength(hw);
- char *buf = (char *) malloc(length + len + 100);
- buf[length] = '\0';
- GetWindowText(hw, buf, length + 1);
- strcat(buf, "\r\n");
-
- strcat(buf, text);
- SetWindowText(hw, buf);
- free(buf);
- SendMessage(hw, EM_SETSEL, GetWindowTextLength(hw), GetWindowTextLength(hw));
- SendMessage(hw, EM_SCROLLCARET, 0, 0);
-
- }
-
- static int SoundEvent(WPARAM wparam, LPARAM lparam)
- {
- SoundEventDef *def = (SoundEventDef *) wparam;
-
- char buf[1024];
-
- sprintf(buf, "Event code: %d ", def->EventCode);
-
- if (def->Contact)
- {
- if (def->Contact->ContactID)
- {
- strcat(buf, def->Contact->ContactID);
- strcat(buf, " ");
- }
- if (def->Contact->ProtocolID)
- {
- strcat(buf, def->Contact->ProtocolID);
- strcat(buf, " ");
- }
- }
-
- if (def->WaveFile)
- {
- strcat(buf, def->WaveFile);
- }
-
- AddTextToWindow(buf, strlen(buf));
-
-
- //Gdyby£my nie chcieli aby tlen odgrywa│ ten dƒwiΩk, zwracamy nie-zero
- return 0;
- }
-
- BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
- {
- hInst=hinstDLL;
- return TRUE;
- }
-
- __declspec(dllexport) TLENPLUGININFO* GetPluginInfo(DWORD tlenVersion)
- {
- return &pluginInfo;
- }
-
- __declspec(dllexport) int LoadPlugin(TLENPLUGINFUNCTIONS *functions)
- {
- tlen_functions = functions;
-
- window = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC) WindowProc);
-
- soundHook= (HANDLE) tlen_functions->HookTlenEvent(hInst, TLEN_SOUNDENGINE_BEFOREEVENT, SoundEvent);
-
- return 0;
- }
-
- __declspec(dllexport) int UnloadPlugin(void)
- {
- tlen_functions->UnhookTlenEvent(hInst, soundHook);
- if (window) DestroyWindow(window);
- return 0;
- }
-