可以使用PlaySound()函数播放mp3音频,该函数原型位于windowsh。
PlaySound函数的声明为:
BOOL PlaySound(LPCSTR pszSound, HMODULE hwnd,DWORD fdwSound);
参数pszSound是指定了要播放声音的字符串。
参数hwnd是应用程序的实例句柄,除非pszSound的指向一个资源标识符(即fdwSound被定义为SND_RESOURCE),否则必须设置为NULL。
参数fdwSound是标志的组合,如下表所示。若成功则函数返回TRUE,否则返回FALSE。
使用PlaySound函数时需要在#include<windowsh>后面加上(注意:不能加在前面):
例程:
CFileDialog dlg(TRUE, "mp3", "mp3", OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, "mp3文件(mp3)|mp3|");/创建选择对话框,让用户从文件夹中选取一个MP3文件/
int iRet = dlgDoModal();//获得对话框返回值
if(IDOK == iRet) //如果返回值成功,表明成功获取一个MP3文件
{
CString pathName= dlgGetPathName(); //得到文件的路径名称
PlaySound( pathName , NULL, SND_FILENAME | SND_ASYNC);//用playsound函数播放该文件
}windows每个进程都有自己的地址空间。openprocess打开进程,readprocessmemory读进程数据,writeprocessmemory写进程数据。难点在于找到你想读的数据在进程地址空间中的偏移即相对地址是指同一计算机不同功能层之间的通信规则称为接口。
java接口作用:
1、利于代码的规范。这样做的目的一方面是为了给开发人员一个清晰的指示,告诉他们哪些业务需要实现;同时也能防止由于开发人员随意命名而导致的命名不清晰和代码混乱,影响开发效率。
2、有利于对代码进行维护。可以一开始定义一个接口,把功能菜单放在接口里,然后定义类时实现这个接口,以后要换的话只不过是引用另一个类而已,这样就达到维护、拓展的方便性。
3、保证代码的安全和严密。一个好的程序一定符合高内聚低耦合的特征,能够让系统的功能较好地实现,而不涉及任何具体的实现细节。这样就比较安全、严密一些,这一思想一般在软件开发中较为常见。API都是C写的, 反过来也成,
你使用VC来做C程序, 可以直接用API
例子:
// DDcpp : Defines the entry point for the application
//
#include "stdafxh"
#include "resourceh"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_DD, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_DD);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msghwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msgwParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95 It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcexcbSize = sizeof(WNDCLASSEX);
wcexstyle = CS_HREDRAW | CS_VREDRAW;
wcexlpfnWndProc = (WNDPROC)WndProc;
wcexcbClsExtra = 0;
wcexcbWndExtra = 0;
wcexhInstance = hInstance;
wcexhIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DD);
wcexhCursor = LoadCursor(NULL, IDC_ARROW);
wcexhbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcexlpszMenuName = (LPCSTR)IDC_DD;
wcexlpszClassName = szWindowClass;
wcexhIconSm = LoadIcon(wcexhInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HANDLE, 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;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// 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;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Mesage handler for about box
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)