#13
投稿記事
by シエル » 15年前
すいません。やっぱりわかりません。。。
再現するコードが作成できたので貼ります。
ダイレクトサウンドを初期化して、解放するだけのコードです。
よろしくお願いいたします。
#include <windows.h>
#include <dsound.h>
#pragma comment(lib,"dsound.lib")
HWND hwnd;
HINSTANCE hinst;
LPDIRECTSOUND8 lpds8;
BOOL InitWindowClass(WNDPROC wndproc,LPCTSTR lpszclassname);
HRESULT DsoundInit(void)
{
if(DS_OK!=DirectSoundCreate8(NULL,&lpds8,NULL))
return E_FAIL;
if(DS_OK!=lpds8->SetCooperativeLevel(hwnd,DSSCL_PRIORITY)){
return E_FAIL;
}
return S_OK;
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp)
{
switch(msg){
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,TEXT("終了しますか"),TEXT("test"),MB_YESNO))
DestroyWindow(hwnd);
return 0;
}
return DefWindowProc(hwnd,msg,wp,lp);
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
MSG msg;
int width=700,height=640;
hinst = hInstance;
//親ウィンドウクラス名
LPCTSTR classname = TEXT("test");
RECT rect;
rect.left=0;
rect.right=width;
rect.top=0;
rect.bottom=height;
AdjustWindowRect(&rect,WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_VISIBLE | WS_MINIMIZEBOX,FALSE);
if(!InitWindowClass(WinProc,classname)) return -1;
hwnd = CreateWindow(
classname,TEXT("テストウィンドウ"),WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_VISIBLE | WS_MINIMIZEBOX,
(GetSystemMetrics(SM_CXSCREEN)-width)/2,(GetSystemMetrics(SM_CYSCREEN)-height)/2,
rect.right-rect.left,rect.bottom-rect.top,
NULL,NULL,hinst,NULL);
if(hwnd==NULL) return -1;
DsoundInit();
while(1){
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
if(msg.message==WM_QUIT){
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}else{
Sleep(16);
//
}
}
lpds8->Release();
return msg.wParam;
}
BOOL InitWindowClass(WNDPROC wndproc,LPCTSTR lpszclassname)
{
WNDCLASSEX winc;
winc.cbSize=sizeof(WNDCLASSEX);
winc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
winc.lpfnWndProc = wndproc;
winc.cbClsExtra = winc.cbWndExtra = 0;
winc.hInstance = hinst;
winc.hIcon = NULL;
winc.hCursor = LoadCursor(NULL,IDC_ARROW);
winc.hbrBackground =NULL;
winc.lpszMenuName = NULL;
winc.lpszClassName = lpszclassname;
winc.hIconSm=NULL;
return RegisterClassEx(&winc);
}