⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waba.cpp

📁 这段程序包含了一个播放mp3 mp4的核心库文件,也包含了对系统联系人列表即poom的调用知识
💻 CPP
字号:
// waba.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "waba.h"
#include "maplay.h"
#include <windows.h>
#include <commctrl.h>
#include <initguid.h>

#define INITGUID
#define MAX_LOADSTRING 100
IPOutlookApp * g_polApp = NULL;
// Global Variables:
HINSTANCE			g_hInst;			// current instance
HWND				g_hWndMenuBar;	
TCHAR g_fileNameStr[MAX_LOADSTRING];
int g_FriendCount;
HANDLE				m_hMap;
TCHAR               g_StartMusic[2][MAX_PATH];   
int g_nCurrFolder = olFolderContacts;
typedef struct
{
	TCHAR cName[MAX_PATH][MAX_LOADSTRING];
	TCHAR cRingToneName[MAX_PATH][MAX_LOADSTRING];
	TCHAR cSMSToneName[MAX_PATH][MAX_LOADSTRING];
	int count;
}RINGSETTING;
RINGSETTING g_FriendRing;
RINGSETTING g_DefaultRing;
RINGSETTING g_GroupRing;
typedef struct{
	TCHAR           Name[MAX_PATH][MAX_PATH];
	TCHAR           Path[MAX_PATH][MAX_PATH];
	int             findFileCount;
}DESFILE;
int g;
DESFILE fileFind;
TCHAR               g_musicname[MAX_LOADSTRING];
DEFINE_GUID(CLSID_Application, 0x05058F23, 0x20BE, 0x11d2, 0x8F, 0x18, 0x00, 0x00, 0xF8, 0x7A, 0x43, 0x35);
DEFINE_GUID(IID_IPOutlookApp, 0x05058F22, 0x20BE, 0x11d2, 0x8F, 0x18, 0x00, 0x00, 0xF8, 0x7A, 0x43, 0x35);
// Forward declarations of functions included in this code module:
ATOM			MyRegisterClass(HINSTANCE, LPTSTR);
BOOL			InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
void chagezc(TCHAR *bs);
BOOL InitPoom();
void ShutdownPoom();
void PiPContacts(TCHAR *appa);
void SetDefaultRing();
void chageqz(TCHAR *bs);
void dstop();
void dplay(TCHAR *musicName);
void SetRing();

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
	MSG msg;

	// Perform application initialization:
	if (!InitInstance(hInstance, nCmdShow)) 
	{
		return FALSE;
	}


	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
  m_hMap = MAP_Initialize();
	return (int) msg.wParam;
}

//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
	WNDCLASS wc;

	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WABA));
	wc.hCursor       = 0;
	wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = szWindowClass;

	return RegisterClass(&wc);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    HWND hWnd;
    TCHAR szTitle[MAX_LOADSTRING];		// title bar text
    TCHAR szWindowClass[MAX_LOADSTRING];	// main window class name

    g_hInst = hInstance; // Store instance handle in our global variable

    // SHInitExtraControls should be called once during your application's initialization to initialize any
    // of the device specific controls such as CAPEDIT and SIPPREF.
    SHInitExtraControls();

    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 
    LoadString(hInstance, IDC_WABA, szWindowClass, MAX_LOADSTRING);

    //If it is already running, then focus on the window, and exit
    hWnd = FindWindow(szWindowClass, szTitle);	
    if (hWnd) 
    {
        // set focus to foremost child window
        // The "| 0x00000001" is used to bring any owned windows to the foreground and
        // activate them.
        SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
        return 0;
    } 

    if (!MyRegisterClass(hInstance, szWindowClass))
    {
    	return FALSE;
    }

    hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {
        return FALSE;
    }

   
    ShowWindow(hWnd, nCmdShow);
   // UpdateWindow(hWnd);


    return TRUE;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    switch (message) 
    {
        case WM_COMMAND:
            wmId    = LOWORD(wParam); 
            wmEvent = HIWORD(wParam); 
            // Parse the menu selections:
            switch (wmId)
            {
                case IDM_OK:
                    DestroyWindow(hWnd);
                    break;
                default:
                    return DefWindowProc(hWnd, message, wParam, lParam);
            }
            break;
        case WM_CREATE:
            SHMENUBARINFO mbi;

            memset(&mbi, 0, sizeof(SHMENUBARINFO));
            mbi.cbSize     = sizeof(SHMENUBARINFO);
            mbi.hwndParent = hWnd;
            mbi.nToolBarId = IDR_MENU;
            mbi.hInstRes   = g_hInst;

            if (!SHCreateMenuBar(&mbi)) 
            {
                g_hWndMenuBar = NULL;
            }
            else
            {
                g_hWndMenuBar = mbi.hwndMB;
            }
			{
			wsprintf(g_fileNameStr,_T("\\Storage\\Application Data\\Sounds\\"));
			SetDefaultRing();
			InitPoom();
			TCHAR appe[30];
			wcscpy(appe,_T("12345678920"));
			PiPContacts(appe);    
			ShutdownPoom();
			SetRing();
			if(g>0)
			{
				for(int i=0;i<fileFind.findFileCount;i++)
				{
					if(wcscmp(g_musicname, fileFind.Name[i])==0)
					{ 
						dplay(fileFind.Path[i]);
					}
				}
			}
			}
            break;
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);

         
            
            EndPaint(hWnd, &ps);
            break;
        case WM_DESTROY:
            CommandBar_Destroy(g_hWndMenuBar);
            PostQuitMessage(0);
            break;


        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

BOOL InitPoom()
{
	BOOL bSuccess = FALSE;

	if (SUCCEEDED(CoInitializeEx( NULL, 0)))
	{
		// Now, let's get the main outlook application
		if (SUCCEEDED(CoCreateInstance(CLSID_Application, NULL, CLSCTX_INPROC_SERVER, 
			IID_IPOutlookApp, reinterpret_cast<void **>(&g_polApp))))
		{

			// login to the Pocket Outlook object model
			if(SUCCEEDED(g_polApp->Logon(NULL)))
			{
				// can't login to the app
				bSuccess = TRUE;
			}
		}
	}
	return bSuccess;
}
BOOL GetPoomFolder(int nFolder, IFolder ** ppFolder)
{

	if (SUCCEEDED(g_polApp->GetDefaultFolder(nFolder, ppFolder)))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}

}
void ShutdownPoom()
{
	if (g_polApp)
	{
		g_polApp->Logoff();
		g_polApp->Release();
	}
	CoUninitialize();
}
void PiPContacts(TCHAR *appa)
{
	BSTR bstrFirstName;
	BSTR bstrLastName;
	BSTR bstrContactInfo;
	BSTR mobliete;
	BSTR cate;
	IContact * pContact = NULL;
	IFolder * pCurrFldr = NULL;
	IPOutlookItemCollection * pItemCol = NULL;
	int cItems = 0;
	if (GetPoomFolder(g_nCurrFolder, &pCurrFldr))
	{
		if (SUCCEEDED(pCurrFldr->get_Items(&pItemCol)))
		{
			pItemCol->get_Count(&cItems);

			for (int i = 1; i <= cItems; i++)
			{
				if (SUCCEEDED(pItemCol->Item (i, reinterpret_cast<IDispatch**>(&pContact))))
				{
					pContact->get_MobileTelephoneNumber(&mobliete);
					if(mobliete[0]!='\0')
					{ 
						if (wcsstr(appa, mobliete) != NULL)
						{  pContact->get_FirstName(&bstrFirstName);
						pContact->get_LastName(&bstrLastName);
						pContact->get_Categories(&cate);
						bstrContactInfo = SysAllocStringByteLen(NULL, SysStringByteLen(bstrFirstName) + 
							SysStringByteLen(bstrFirstName) + (4*sizeof(OLECHAR)));
						_tcscpy(bstrContactInfo, bstrLastName);
						_tcscat(bstrContactInfo, _T(", "));
						_tcscat(bstrContactInfo, bstrFirstName);
						if(cate[0]!='\0')
							chageqz(cate);
						chagezc(bstrContactInfo);
						SysFreeString(bstrFirstName);
						SysFreeString(bstrLastName);
						SysFreeString(bstrContactInfo);
						SysFreeString(cate);
						pContact->Release();
						break;
						}
					}
				}
			}	
			pItemCol->Release();
		}
		pCurrFldr->Release();
	}
}
void chagezc(TCHAR *bs)
{
	TCHAR fileNameStr1[256];
	int i;
	BOOL bIsSaved = FALSE;
	int k=0;

	_stprintf(fileNameStr1, _T("%s%s"), g_fileNameStr, _T("RingFriend.dll"));

	HANDLE hFile;
	hFile = CreateFile(fileNameStr1, GENERIC_READ | GENERIC_WRITE, 
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile == INVALID_HANDLE_VALUE)
	{   k=0;
	g_FriendCount = 0;
	CloseHandle(hFile);
	}
	else
	{
		DWORD dwReadNum;
		SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
		ReadFile(hFile, &g_FriendRing, sizeof(g_FriendRing), &dwReadNum, NULL);
		CloseHandle(hFile);
		g_FriendCount = g_FriendRing.count; 
		for (i = 0; i < g_FriendCount; i++)
		{
			if(wcscmp(bs, g_FriendRing.cName[i])==0)
			{   k=1;
			wcscpy(g_musicname,g_FriendRing.cSMSToneName[i]);
			break;
			}
		}
		if(i==g_FriendCount)
		{  k=0;
		}

	}

}
void SetDefaultRing()
{  
	TCHAR fileNameStr1[256];

	_stprintf(fileNameStr1, _T("%s%s"), g_fileNameStr, _T("RingoDefaults.dll"));

	HANDLE hFile;
	hFile = CreateFile(fileNameStr1, GENERIC_READ | GENERIC_WRITE, 
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile == INVALID_HANDLE_VALUE)// 文件不存在
	{
		wcscpy(g_StartMusic[0],_T("Busy.wav"));
		wcscpy(g_StartMusic[1],_T("Busy.wav"));
		// 初始化前十名结构
		_tcscpy(g_DefaultRing.cRingToneName[0], g_StartMusic[0]);
		_tcscpy(g_DefaultRing.cSMSToneName[0], g_StartMusic[1]);

		DWORD dwWrittenNum;
		hFile = CreateFile(fileNameStr1, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ 
			| FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hFile != INVALID_HANDLE_VALUE)
		{
			WriteFile(hFile, &g_DefaultRing, sizeof(g_DefaultRing), &dwWrittenNum, NULL);
			CloseHandle(hFile);
		}
	}
	else
	{
		DWORD dwReadNum;
		SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
		ReadFile(hFile, &g_DefaultRing, sizeof(g_DefaultRing), &dwReadNum, NULL);
		CloseHandle(hFile);
		wcscpy(g_StartMusic[0],g_DefaultRing.cRingToneName[0]);
		wcscpy(g_StartMusic[1],g_DefaultRing.cSMSToneName[0]);
	}
	wcscpy(g_musicname,g_StartMusic[1]);
}
void chageqz(TCHAR *bs)
{
	TCHAR fileNameStr1[256];
	int i;
	int k=0;
	_stprintf(fileNameStr1, _T("%s%s"), g_fileNameStr, _T("RingoGroups.dll"));

	HANDLE hFile;
	hFile = CreateFile(fileNameStr1, GENERIC_READ | GENERIC_WRITE, 
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile == INVALID_HANDLE_VALUE)// 文件不存在
	{   k=0;
	g_FriendCount=0;
	CloseHandle(hFile);
	}
	else
	{
		// 读出文件
		DWORD dwReadNum;
		SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
		ReadFile(hFile, &g_GroupRing, sizeof(g_GroupRing), &dwReadNum, NULL);
		CloseHandle(hFile);
		g_FriendCount = g_GroupRing.count; 
		for (i = 0; i < g_FriendCount; i++)
		{
			if(wcsstr(bs, g_GroupRing.cName[i])!=NULL)
			{   k=1;
			wcscpy(g_musicname,g_GroupRing.cSMSToneName[i]);
			break;
			}
		}

	}

}
void SetRing()
{  
	TCHAR fileNameStr[256];

	_stprintf(fileNameStr, _T("%s%s"), g_fileNameStr, _T("Ring.dll"));

	HANDLE hFile;
	hFile = CreateFile(fileNameStr, GENERIC_READ | GENERIC_WRITE, 
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile == INVALID_HANDLE_VALUE)// 文件不存在
	{
		g=0;
	}
	else
	{
		g=1;
		// 读出文件
		DWORD dwReadNum;
		SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
		ReadFile(hFile, &fileFind, sizeof(fileFind), &dwReadNum, NULL);
		CloseHandle(hFile);
	}
}
void dplay(TCHAR *musicName)
{
	if(wcsstr(musicName,_T("wav"))!=NULL)
		PlaySound(musicName,NULL,SND_ASYNC);
	else
	{
		MAP_Open(m_hMap, musicName);
		MAP_Play(m_hMap);
	}
}
void dstop()
{
	PlaySound(NULL,NULL,0);
	MAP_Stop(m_hMap);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -