約 2,846,738 件
https://w.atwiki.jp/sampleisbest/pages/176.html
開発環境 Microsoft Visual C++ 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 空の CLR プロジェクト プロジェクト名 ClrD3D 参考 迷路を表示する ClrD3D_25.cpp /* #25 迷路 プロジェクトへの参照の追加(参照タブ) C \WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0 Microsoft.DirectX.dll Microsoft.DirectX.Direct3D.dll Microsoft.DirectX.Direct3DX.dll */ #pragma comment(linker, "/subsystem windows /entry main") // アセンブリ #using System.dll #using System.Drawing.dll #using System.Windows.Forms.dll // 名前空間 using namespace System; using namespace System Drawing; using namespace System Threading; using namespace System Windows Forms; using namespace Microsoft DirectX; using namespace Microsoft DirectX Direct3D; #define POST_NUM 4// 柱の数 #define MAZE_SIZE (POST_NUM * 2 + 3)// 迷路の大きさ ref class MainForm Form { private Device^ dev; PresentParameters^ pp; Mesh^ mesh; array int, 2 ^ nBlock; Vector3 vPos;// 位置 int nCamDir;// 向き Direct3D Font^ font; int nSec; int nFps; int nFrame; public MainForm() { MinimumSize = Drawing Size(160, 120); MaximizeBox = false; ClientSize = Drawing Size(640, 480); Text = "ClrD3D"; KeyDown += gcnew KeyEventHandler(this, MainForm OnKeyDown); } bool DXInitialize() { try { pp = gcnew PresentParameters; pp- Windowed = true; pp- SwapEffect = SwapEffect Discard; pp- AutoDepthStencilFormat = DepthFormat D16; pp- EnableAutoDepthStencil = true; dev = gcnew Device(0, DeviceType Hardware, this, CreateFlags HardwareVertexProcessing, pp); CreateMesh(); CreateFont(); MakeMaze(); vPos = Vector3(1.0f, -0.2f, 0.0f); nCamDir = 0; return true; } catch (Exception^) { return false; } } void Render() { if (dev == nullptr) return; if (WindowState == FormWindowState Minimized) return; nFrame++; if (nSec != DateTime Now.Second) { nSec = DateTime Now.Second; nFps = nFrame; nFrame = 0; } dev- RenderState- ZBufferEnable = true; dev- RenderState- ZBufferWriteEnable = true; // カメラの設定 float fDir = nCamDir * (float)Math PI / 180; float fTargetX = (float)Math Sin(fDir); float fTargetZ = (float)Math Cos(fDir); dev- Transform- View = Matrix LookAtLH( vPos, Vector3(vPos.X + fTargetX * 10.0f, 0.0f, vPos.Z + fTargetZ * 10.0f), Vector3(0.0f, 1.0f, 0.0f)); dev- Transform- Projection = Matrix PerspectiveFovLH((float)Math PI / 4, (float)ClientSize.Width / (float)ClientSize.Height, 0.1f, 10.0f); // ライトの設定 dev- Lights[0]- Direction = Vector3 Normalize(Vector3(-1, -2, 3)); dev- Lights[0]- Type = LightType Directional; dev- Lights[0]- Diffuse = Color FromArgb(0xff,0xff,0xff); dev- Lights[0]- Ambient = Color FromArgb(0x28,0x28,0x28); dev- Lights[0]- Enabled = true; dev- Lights[0]- Update(); dev- Clear(ClearFlags Target | ClearFlags ZBuffer, 0x7f7fff, 1.0f, 0); dev- BeginScene(); // メッシュ描画 ColorValue color(0.5f, 1.0f, 0.5f); for (int nRow = 0; nRow MAZE_SIZE; nRow++) { for (int nCol = 0; nCol MAZE_SIZE; nCol++) { switch (nBlock[nRow, nCol]) { case 1 DrawMesh(color, nRow, nCol, 0); break; case 2 DrawMesh(ColorValue(0.5f, 0.5f, 1.0f), nRow, nCol, -1); break; case 3 DrawMesh(ColorValue(1.0f, 0.5f, 0.5f), nRow, nCol, -1); break; } } } font- DrawText(nullptr, "fps=" + nFps, 0, 0, Color White); dev- EndScene(); try { dev- Present(); } catch (DeviceLostException^) { ResetDevice(); } } private void CreateMesh() { mesh = Mesh Box(dev, 1, 1, 1); } void DrawMesh(ColorValue color, int nRow, int nCol, int nAlt) { Material mat; mat.AmbientColor = color; mat.DiffuseColor = color; dev- Material = mat; Vector3 v((float)nRow, (float)nAlt, (float)nCol); dev- Transform- World = Matrix Translation(v); mesh- DrawSubset(0); } void CreateFont() { FontDescription fd; fd.Height = 20; fd.FaceName = "MS ゴシック"; font = gcnew Direct3D Font(dev, fd); } void ResetDevice() { int hResult; if (!dev- CheckCooperativeLevel(hResult)) { switch (hResult) { case ResultCode DeviceLost Thread Sleep(10); break; case ResultCode DeviceNotReset dev- Reset(pp); break; } } } void OnKeyDown(Object^ sender, KeyEventArgs^ e) { switch (e- KeyCode) { case Keys W Walk(0); break; case Keys S Walk(180); break; case Keys A Walk(-90); break; case Keys D Walk(90); break; case Keys Left nCamDir -= 5; break; case Keys Right nCamDir += 5; break; case Keys Up vPos.Y += 0.1f; break; case Keys Down vPos.Y -= 0.1f; break; case Keys Escape Close(); break; } } void Walk(int nDir) { float fDir = (nCamDir + nDir) * (float)Math PI / 180; float fX = (float)Math Sin(fDir) * 0.2f; float fZ = (float)Math Cos(fDir) * 0.2f; vPos.X += fX; vPos.Z += fZ; } // 迷路を作る(棒倒し法) void MakeMaze() { nBlock = gcnew array int, 2 (MAZE_SIZE, MAZE_SIZE); // 全体をクリア for (int nRow = 0; nRow MAZE_SIZE; nRow++) { for (int nCol = 0; nCol MAZE_SIZE; nCol++) { nBlock[nRow, nCol] = 0; } } // 外枠をセット for (int n = 0; n MAZE_SIZE; n++) { nBlock[0, n] = 1; nBlock[MAZE_SIZE - 1, n] = 1; nBlock[n, 0] = 1; nBlock[n, MAZE_SIZE - 1] = 1; } // 柱をセット for (int nPostRow = 1; nPostRow = POST_NUM; nPostRow++) { for (int nPostCol = 1; nPostCol = POST_NUM; nPostCol++) { nBlock[nPostRow * 2, nPostCol * 2] = 1; } } // 迷路作成 array int ^ aCol = {0, 1, 0, -1}; array int ^ aRow = {-1, 0, 1, 0}; Random^ rnd = gcnew Random; for (int nPostRow = 1; nPostRow = POST_NUM; nPostRow++) { for (int nPostCol = 1; nPostCol = POST_NUM; nPostCol++) { int nRow, nCol; do { int nDir = rnd- Next((nPostRow == 1) ? 4 3); nRow = nPostRow * 2 + aRow[nDir]; nCol = nPostCol * 2 + aCol[nDir]; } while (nBlock[nRow, nCol]); nBlock[nRow, nCol] = 1; } } // 入口・出口 nBlock[1, 0] = 2; nBlock[MAZE_SIZE - 2, MAZE_SIZE - 1] = 3; } }; int main() { MainForm^ form = gcnew MainForm; if (!form- DXInitialize()) { MessageBox Show("Direct3Dの初期化に失敗しました。", "ClrD3D"); return 0; } form- Show(); while (form- Created) { form- Render(); Application DoEvents(); } return 0; }
https://w.atwiki.jp/sampleisbest/pages/412.html
開発環境 メモ帳 実行環境 Windows 7 Home Premium (32bit)
https://w.atwiki.jp/bzspirit/pages/462.html
発売日 1998年9月20日 出版社 J-ROCK MAGAZINE B'zのリクエストベストアルバム 『B z The Best Treasure︎︎ 』の公式バンドスコア。 計16曲のスコアを収録。 19ページの豪華フォト、メンバーコメント入り全楽曲解説などを掲載。 収録曲 BLOWIN' 恋心(KOI-GOKORO) TIME Liar! Liar! ねがい 愛しい人よGood Night… Pleasure'98 ~人生の快楽~ ミエナイチカラ~INVISIBLE ONE~ もう一度キスしたかった FIREBALL Real Thing Shakes MOTEL いつかのメリークリスマス RUN HOME The Wild Wind 名前 コメント
https://w.atwiki.jp/mybestapp/pages/15.html
test
https://w.atwiki.jp/sampleisbest/pages/526.html
開発環境 Microsoft Visual Studio Community 2017 実行環境 Microsoft Windows 10 Home (64bit) プロジェクトの種類 Visual C++ / 空のプロジェクト 参考 サウンド デバイスの列挙 コンソール版(dsenum_c) dsenum_c.cpp // マルチバイト文字セット // https //msdn.microsoft.com/ja-jp/library/cc354468.aspx #pragma comment(lib, "dsound") #include dsound.h #include stdio.h BOOL CALLBACK DSEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext) { printf("[%s][%s]\n", lpszDesc, lpszDrvName); return TRUE; } int main() { HRESULT hr = DirectSoundEnumerate(DSEnumProc, NULL); return 0; } 出力 [プライマリ サウンド ドライバー][] [EX-LD2071T (Intel SST Audio Device (WDM))][{0.0.0.00000000}.{0226a988-680d-43c9-b4e4-f71db4992a9c}] [スピーカー (Intel SST Audio Device (WDM))][{0.0.0.00000000}.{1dbfc4da-902e-4808-b91b-5381f6f64943}] ウィンドウ版(dsenum_w) dsenum_w.cpp // Unicode文字セット // https //msdn.microsoft.com/ja-jp/library/cc354468.aspx #pragma comment(lib, "dsound") #include windowsx.h #include dsound.h #include "Resource.h" INT_PTR CALLBACK MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); void Init(HWND hDlg); BOOL CALLBACK DSEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext); //// int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAINDLG), NULL, MainDlg); return 0; } INT_PTR CALLBACK MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND switch (LOWORD(wParam)) { case IDCANCEL EndDialog(hDlg, IDCANCEL); break; } break; case WM_INITDIALOG Init(hDlg); break; default return FALSE; } return TRUE; } void Init(HWND hDlg) { HWND hCombo1 = GetDlgItem(hDlg, IDC_COMBO1); DirectSoundEnumerate(DSEnumProc, hCombo1); } BOOL CALLBACK DSEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext) { HWND hCombo = (HWND)lpContext; ComboBox_AddString(hCombo, lpszDesc); return TRUE; } Resource.h #define IDD_MAINDLG100 #define IDC_STATIC-1 #define IDC_COMBO11000 dsenum_w.rs // resource script #include windows.h #include "resource.h" IDD_MAINDLG DIALOGEX 100, 100, 320, 200 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW CAPTION "dsenum_w" FONT 9, "MS UI Gothic" BEGIN COMBOBOXIDC_COMBO1, 10, 10, 200, 100, CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP END
https://w.atwiki.jp/sampleisbest/pages/276.html
開発環境 Microsoft Visual C++ 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 Win32 プロジェクト プロジェクト名 WaveGraph アプリケーションの種類 Windows アプリケーション 追加のオプション 空のプロジェクト 文字セット Unicode WaveGraph.cpp // WaveGraph5 Waveファイルグラフ表示 #pragma comment(lib, "winmm") #include Windows.h #include tchar.h #define SAFE_FREE(p)if (p) { free(p); p = NULL; } #define APP_NAMETEXT("WaveGraph") // 関数プロトタイプ宣言 void Trace(LPCTSTR format, ...); BOOL Load(LPTSTR pszFileName); BOOL ReadWaveFile(LPTSTR pszFileName); LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void ScrollInfo(HWND hWnd); void OnDropFiles(HWND hWnd, WPARAM wParam); void OnSize(HWND hWnd, WPARAM wParam, LPARAM lParam); void OnHScroll(HWND hWnd, WPARAM wParam); void OnPaint(HWND hWnd); void PaintWaveform(HDC hdc, LONG top, LONG bottom, RECT rcPaint, int ch); void SetTitle(HWND hWnd); // 外部変数 SCROLLINFO siHorz; PBYTE waveformData = NULL; int waveformLen = 0; WAVEFORMATEX wfx; TCHAR szFileName[MAX_PATH]; //============================================================================== int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) { // プログラム引数 LPTSTR lpCmdLine = GetCommandLine(); int argc; LPTSTR *argv = CommandLineToArgvW(lpCmdLine, argc); if (2 = argc) { Load(argv[1]); } // ウィンドウクラスの登録 WNDCLASSEX wcx; ZeroMemory( wcx, sizeof wcx); wcx.cbSize= sizeof wcx; wcx.style= CS_HREDRAW | CS_VREDRAW; wcx.lpfnWndProc= WndProc; wcx.hInstance= hInstance; wcx.hCursor= LoadCursor(NULL, IDC_ARROW); wcx.hbrBackground= (HBRUSH)(COLOR_WINDOW + 1); wcx.lpszClassName= APP_NAME; if (RegisterClassEx( wcx) == 0) { return 0; } // ウィンドウの作成 HWND hWnd = CreateWindowEx( WS_EX_ACCEPTFILES, APP_NAME, APP_NAME, WS_OVERLAPPEDWINDOW | WS_HSCROLL, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (hWnd == NULL) { return 0; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); SetTitle(hWnd); // メッセージループ MSG msg; while (GetMessage( msg, NULL, 0, 0)) { TranslateMessage( msg); DispatchMessage( msg); } return msg.wParam; } void Trace(LPCTSTR format, ...) { va_list arg_ptr; TCHAR buffer[256]; int size; va_start(arg_ptr, format); size = _vsntprintf_s(buffer, _countof(buffer), _TRUNCATE, format, arg_ptr); va_end(arg_ptr); OutputDebugString(buffer); if (size 0) { OutputDebugString(_T("...\n")); } } BOOL Load(LPTSTR pszFileName) { BOOL br = ReadWaveFile(pszFileName); _tcscpy_s(szFileName, pszFileName); return br; } BOOL ReadWaveFile(LPTSTR pszFileName) { MMRESULT mmr; SAFE_FREE(waveformData); waveformLen = 0; // Open HMMIO hmmio = mmioOpen(pszFileName, NULL, MMIO_READ); if (hmmio == NULL) { return FALSE; } // RIFFチャンク MMCKINFO ckParent; ckParent.fccType = mmioFOURCC( W , A , V , E ); mmr = mmioDescend(hmmio, ckParent, NULL, MMIO_FINDRIFF); if (mmr != MMSYSERR_NOERROR) { return FALSE; } // fmtチャンク MMCKINFO ckSub; ckSub.ckid = mmioFOURCC( f , m , t , ); mmr = mmioDescend(hmmio, ckSub, ckParent, MMIO_FINDCHUNK); if (mmr != MMSYSERR_NOERROR) { return FALSE; } LONG read = mmioRead(hmmio, (HPSTR) wfx, 16); if (read != 16) { return FALSE; } mmioAscend(hmmio, ckSub, 0); // dataチャンク ckSub.ckid = mmioFOURCC( d , a , t , a ); mmr = mmioDescend(hmmio, ckSub, ckParent, MMIO_FINDCHUNK); if (mmr != MMSYSERR_NOERROR) { return FALSE; } waveformData = (PBYTE)malloc(ckSub.cksize); if (waveformData == NULL) { return FALSE; } read = mmioRead(hmmio, (HPSTR)waveformData, ckSub.cksize); if (read != ckSub.cksize) { return FALSE; } waveformLen = ckSub.cksize / wfx.nBlockAlign; mmioAscend(hmmio, ckSub, 0); // RIFFチャンク mmioAscend(hmmio, ckParent, 0); // Close mmioClose(hmmio, 0); return TRUE; } //------------------------------------------------------------------------------ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_PAINT OnPaint(hWnd); return 0; case WM_HSCROLL OnHScroll(hWnd, wParam); return 0; case WM_SIZE OnSize(hWnd, wParam, lParam); return 0; case WM_DROPFILES OnDropFiles(hWnd, wParam); DragFinish((HDROP)wParam); return 0; case WM_CREATE ScrollInfo(hWnd); return 0; case WM_DESTROY SAFE_FREE(waveformData); PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, uMsg, wParam, lParam); } void ScrollInfo(HWND hWnd) { RECT rc; GetClientRect(hWnd, rc); siHorz.cbSize= sizeof siHorz; siHorz.fMask= SIF_RANGE | SIF_PAGE | SIF_POS | SIF_DISABLENOSCROLL; siHorz.nMin= 0; siHorz.nMax= waveformLen - 1; siHorz.nPage= rc.right; siHorz.nPos= 0; SetScrollInfo(hWnd, SB_HORZ, siHorz, FALSE); } void OnDropFiles(HWND hWnd, WPARAM wParam) { HDROP hDrop = (HDROP)wParam; TCHAR szFile[MAX_PATH]; DragQueryFile(hDrop, 0, szFile, _countof(szFile)); Load(szFile); SetTitle(hWnd); ScrollInfo(hWnd); InvalidateRect(hWnd, NULL, TRUE); } void OnSize(HWND hWnd, WPARAM wParam, LPARAM lParam) { if (wParam == SIZE_MINIMIZED) return; siHorz.nPage= LOWORD(lParam); int nPosMax= max(siHorz.nMax - (int)siHorz.nPage + 1, 0); siHorz.nPos= min(siHorz.nPos, nPosMax); SetScrollInfo(hWnd, SB_HORZ, siHorz, TRUE); } void OnHScroll(HWND hWnd, WPARAM wParam) { int nPos = siHorz.nPos; switch (LOWORD(wParam)) { case SB_LINEUP nPos -= 10; break; case SB_LINEDOWN nPos += 10; break; case SB_PAGEUP nPos -= siHorz.nPage; break; case SB_PAGEDOWN nPos += siHorz.nPage; break; case SB_THUMBTRACK SCROLLINFO si; si.cbSize= sizeof si; si.fMask= SIF_TRACKPOS; if (GetScrollInfo(hWnd, SB_HORZ, si) != 0) { nPos = si.nTrackPos; } break; } int nPosMax = max(siHorz.nMax - (int)siHorz.nPage + 1, 0); nPos = min(nPos, nPosMax); nPos = max(nPos, 0); if (nPos == siHorz.nPos) return; ScrollWindowEx(hWnd, siHorz.nPos - nPos, 0, NULL, NULL, NULL, NULL, SW_INVALIDATE | SW_ERASE); siHorz.nPos = nPos; SetScrollInfo(hWnd, SB_HORZ, siHorz, TRUE); UpdateWindow(hWnd); } void OnPaint(HWND hWnd) { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, ps); RECT rc; GetClientRect(hWnd, rc); if (waveformData) { switch (wfx.nChannels) { case 1 PaintWaveform(hdc, rc.top, rc.bottom, ps.rcPaint, 0); break; case 2 LONG center = rc.bottom / 2; PaintWaveform(hdc, rc.top, center, ps.rcPaint, 0); PaintWaveform(hdc, center + 1, rc.bottom, ps.rcPaint, 1); MoveToEx(hdc, 0, center, NULL); LineTo(hdc, rc.right, center); break; } } EndPaint(hWnd, ps); } void PaintWaveform(HDC hdc, LONG top, LONG bottom, RECT rcPaint, int ch) { LONG height = bottom - top; HPEN pen = CreatePen(PS_SOLID, 0, RGB(0,0,255)); HGDIOBJ penOld = SelectObject(hdc, pen); for (int x = rcPaint.left; x rcPaint.right; x++) { int i = siHorz.nPos + x; if (waveformLen = i) break; int y; if (wfx.wBitsPerSample == 8) { y = top + height * (255 - waveformData[wfx.nChannels * i + ch]) / 256; } else { y = top + height * (32767 - ((short*)waveformData)[wfx.nChannels * i + ch]) / 65536; } MoveToEx(hdc, x, top + height / 2, NULL); LineTo(hdc, x, y); } SelectObject(hdc, penOld); DeleteObject(pen); } void SetTitle(HWND hWnd) { if (waveformData == NULL) { SetWindowText(hWnd, APP_NAME); return; } TCHAR str[512]; _stprintf_s(str, _T("%s [%uHz %ubit %uch] - %s"), szFileName, wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels, APP_NAME); SetWindowText(hWnd, str); }
https://w.atwiki.jp/sampleisbest/pages/242.html
開発環境 Microsoft Visual C# 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 空のプロジェクト プロジェクト名 MdxSample プロジェクト プロジェクトの保存 [ソリューションのディレクトリを作成]はチェックを付けなくてもいい。 プロジェクトのプロパティ [アプリケーション]タブ 出力の種類:Windows アプリケーション プロジェクトにクラスを追加。 テンプレート:クラス 名前:Program.cs 名前:Form1.cs 名前:MdxSample.cs プロジェクトに新しい項目を追加。 テンプレート:アプリケーション構成ファイル 名前:App.config プロジェクトの参照設定に追加。(.NETタブ) ※Ctrlキーで複数選択可 System System.Drawing System.Windows.Forms プロジェクトの参照設定に追加。(参照タブ) ※Ctrlキーで複数選択可 C \WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0 Microsoft.DirectX.dll Microsoft.DirectX.Direct3D.dll Microsoft.DirectX.Direct3DX.dll Microsoft.DirectX.DirectInput.dll 注意 MdxSample.exeと同じディレクトリにMdxSample.exe.configがないと動作が不安定になる。 参考 Managed DirectX - ソーサリーフォース LoaderLockエラーの対処 メニューから[ツール]-[設定]-[上級者設定]を選択する。 メニューから[デバッグ]-[例外]を選択する。 Managed Debugging Assistants/LoaderLockの[スローされるとき]のチェックを外す。 App.config ?xml version="1.0" encoding="utf-8" ? configuration startup useLegacyV2RuntimeActivationPolicy="true" supportedRuntime version="v4.0"/ /startup /configuration Program.cs using System; using System.Threading; using System.Windows.Forms; namespace MdxSample { static class Program { [STAThread] static void Main() { using (Form1 form = new Form1()) using (MdxSample main = new MdxSample()) { if (!main.DXInitialize(form)) { MessageBox.Show("Direct3Dの初期化に失敗しました。", "MdxSample"); return; } form.Show(); while (form.Created) { main.Render(); Thread.Sleep(1); Application.DoEvents(); } } } } } Form1.cs using System.Drawing; using System.Windows.Forms; namespace MdxSample { class Form1 Form { public Form1() { Text = "MdxSample"; ClientSize = new Size(1280, 720); MaximizeBox = false; FormBorderStyle = FormBorderStyle.FixedSingle; } } } MdxSample.cs using System; using System.Drawing; using System.Threading; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; using Microsoft.DirectX.DirectInput; namespace MdxSample { class MdxSample IDisposable { Form1 form; PresentParameters pp; Microsoft.DirectX.Direct3D.Device dev; Microsoft.DirectX.Direct3D.Font font; Microsoft.DirectX.DirectInput.Device keyboard; VertexBuffer vertexBuffer; // fps int fpsSec; int fpsDraw = 0; int fpsCount = 0; // カメラ float camDist = 3; int camLat = 0; int camLon = 180; public bool DXInitialize(Form1 topLevelForm) { try { form = topLevelForm; // キーボードデバイスの初期化 keyboard = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard); keyboard.SetCooperativeLevel(form, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background); keyboard.Acquire(); // Direct3Dデバイス作成 pp = new PresentParameters(); pp.Windowed = true; pp.SwapEffect = SwapEffect.Discard; pp.EnableAutoDepthStencil = true; pp.AutoDepthStencilFormat = DepthFormat.D16; dev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, pp); // フォントの作成 FontDescription fd = new FontDescription(); fd.Height = 24; fd.FaceName = "MS ゴシック"; font = new Microsoft.DirectX.Direct3D.Font(dev, fd); // 頂点バッファ CustomVertex.PositionColored[] vertices = new CustomVertex.PositionColored[3]; vertices[0] = new CustomVertex.PositionColored(0, 1, 0, Color.Red.ToArgb()); vertices[1] = new CustomVertex.PositionColored(1, -1, 0, Color.Green.ToArgb()); vertices[2] = new CustomVertex.PositionColored(-1, -1, 0, Color.Blue.ToArgb()); vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, dev, Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Managed); using (GraphicsStream data = vertexBuffer.Lock(0, 0, LockFlags.None)) { data.Write(vertices); vertexBuffer.Unlock(); } dev.Transform.Projection = Matrix.PerspectiveFovLH(Geometry.DegreeToRadian(45), (float)dev.Viewport.Width / (float)dev.Viewport.Height, 1, 100); dev.RenderState.Lighting = false; return true; } catch { return false; } } public void Render() { KeyboardState state; state = keyboard.GetCurrentKeyboardState(); if (state[Key.Escape]) { form.Close(); return; } if (state[Key.Up]) camLat = Math.Min(camLat + 1, 89); if (state[Key.Down]) camLat = Math.Max(camLat - 1, -89); if (state[Key.Left]) camLon = (camLon + 1) % 360; if (state[Key.Right]) camLon = (camLon + 359) % 360; if (state[Key.PageUp]) camDist -= 0.1f; if (state[Key.PageDown]) camDist += 0.1f; // fps fpsDraw++; int sec = DateTime.Now.Second; if (fpsSec != sec) { fpsCount = fpsDraw; fpsDraw = 0; fpsSec = sec; } // カメラ位置 Vector3 pos; float rad = Geometry.DegreeToRadian(camLat); pos.Y = (float)Math.Sin(rad) * camDist; float r = (float)Math.Cos(rad) * camDist; rad = Geometry.DegreeToRadian(camLon); pos.X = (float)Math.Sin(rad) * r; pos.Z = (float)Math.Cos(rad) * r; dev.Transform.View = Matrix.LookAtLH(pos, new Vector3(), new Vector3(0, 1, 0)); // バックバッファのクリア dev.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0); dev.BeginScene(); dev.SetStreamSource(0, vertexBuffer, 0); dev.VertexFormat = CustomVertex.PositionColored.Format; dev.DrawPrimitives(PrimitiveType.TriangleList, 0, 1); string text = string.Format("fps={0} lat={1} lon={2} dist={3 f1}", fpsCount, camLat, camLon, camDist); font.DrawText(null, text, 0, 0, Color.White); // バックバッファを表画面に反映 dev.EndScene(); try { dev.Present(); } catch (DeviceLostException) { ResetDevice(); } } void ResetDevice() { int result; if (!dev.CheckCooperativeLevel(out result)) { switch ((ResultCode)result) { case ResultCode.DeviceLost Thread.Sleep(10); break; case ResultCode.DeviceNotReset dev.Reset(pp); break; default form.Close(); break; } } } public void Dispose() { if (font != null) { font.Dispose(); } } } }
https://w.atwiki.jp/sampleisbest/pages/302.html
開発環境 Microsoft Visual C++ 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 Win32 コンソール アプリケーション プロジェクト名 mml2smf1 アプリケーションの種類 コンソール アプリケーション 追加のオプション 空のプロジェクト 文字セット マルチバイト 参考 こんにちは世界 mml2smf1.cpp // マルチバイト文字セット #include stdio.h #include Windows.h // 関数プロトタイプ宣言 void WriteBE(int len, DWORD val); void WriteData(DWORD t, BYTE cmd, BYTE d1, BYTE d2); // 外部変数 FILE* pFile; int datalen;// データ長 //============================================================================== int main() { if (fopen_s( pFile, "sample.mid", "wb") != 0) { fprintf(stderr, "fopen error\n"); return 1; } // ヘッダチャンク fwrite("MThd", 1, 4, pFile); WriteBE(4, 6);// データ長 WriteBE(2, 0);// フォーマットタイプ WriteBE(2, 1);// トラック数 WriteBE(2, 480);// タイムベース // トラックチャンク fwrite("MTrk", 1, 4, pFile); datalen = 0; WriteBE(4, datalen);// データ長(仮) // データセクション WriteData(0, 0x90, 60, 0x70); WriteData(480, 0x80, 60, 0); WriteData(0, 0x90, 64, 0x70); WriteData(480, 0x80, 64, 0); WriteData(0, 0x90, 67, 0x70); WriteData(480, 0x80, 67, 0); // トラック終了 WriteData(0, 0xff, 0x2f, 0x00); fseek(pFile, -4 - datalen, SEEK_CUR); WriteBE(4, datalen);// データ長 fclose(pFile); return 0; } void WriteBE(int len, DWORD val) { BYTE* p = (BYTE*) val + len; for (int n = 0; n len; n++) { fwrite(--p, 1, 1, pFile); } } void WriteData(DWORD t, BYTE cmd, BYTE d1, BYTE d2) { // 可変長tick DWORD v = ((t 0xfe00000) 3)|((t 0x1fc000) 2)|((t 0x3f80) 1)|(t 0x7f)|0x80808000; BYTE* p = (BYTE*) v + 4; for (int n = 0; n 4; n++) { if (*--p != 0x80) { fwrite(p, 1, 1, pFile); datalen++; } } fwrite( cmd, 1, 1, pFile); fwrite( d1, 1, 1, pFile); fwrite( d2, 1, 1, pFile); datalen += 3; } 出力 ADDRESS 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF ------------------------------------------------------------------------------ 00000000 4D 54 68 64 00 00 00 06 00 00 00 01 01 E0 4D 54 MThd..........MT 00000010 72 6B 00 00 00 1F 00 90 3C 70 83 60 80 3C 00 00 rk...... p.`. .. 00000020 90 40 70 83 60 80 40 00 00 90 43 70 83 60 80 43 .@p.`.@...Cp.`.C 00000030 00 00 FF 2F 00 .../.
https://w.atwiki.jp/sampleisbest/pages/223.html
開発環境 Microsoft Visual C# 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 Windows Game (4.0) プロジェクト名 XnaSphere2 CustomVertex.cs using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace CustomVertex { struct VertexPositionNormalColor IVertexType { public Vector3 Position; public Vector3 Normal; public Color Color; public VertexPositionNormalColor(Vector3 position, Vector3 normal, Color color) { Position = position; Normal = normal; Color = color; } static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration( new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(sizeof(float) * 3, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), new VertexElement(sizeof(float) * 6, VertexElementFormat.Color, VertexElementUsage.Color, 0)); VertexDeclaration IVertexType.VertexDeclaration { get { return VertexDeclaration; } } } } Game1.cs // XnaSphere2 - XNA 球体(法線) using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using CustomVertex; namespace XnaSphere { class Game1 Game { GraphicsDeviceManager graphics; SpriteBatch sprite; SpriteFont font; BasicEffect effect; VertexBuffer vertexBuffer; IndexBuffer indexBuffer; // fps int sec; int draw = 0; int fps = 0; // カメラ int camLat = 0; int camLong = 90; float camDist = 5; public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; Content.RootDirectory = "Content"; IsMouseVisible = true; } protected override void LoadContent() { font = Content.Load SpriteFont ("SpriteFont1"); sprite = new SpriteBatch(GraphicsDevice); effect = new BasicEffect(GraphicsDevice); //effect.VertexColorEnabled = true; effect.EnableDefaultLighting(); effect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), GraphicsDevice.Viewport.AspectRatio, 1, 100); // 頂点バッファ int stackNum = 16; // 輪切りの数 VertexPositionNormalColor[] vertices = new VertexPositionNormalColor[stackNum * stackNum + 2]; int i = 0; vertices[i++] = new VertexPositionNormalColor( new Vector3(0, 1, 0), new Vector3(0, 1, 0), Color.Yellow); for (int stack = 1; stack stackNum; stack++) { float rad = ((stackNum - 2 * stack) / (float)stackNum) * MathHelper.PiOver2; float y = (float)Math.Sin(rad); float r = (float)Math.Cos(rad); int sliceNum = 4 * Math.Min(stack, stackNum - stack); // 放射頂点の数 for (int slice = 0; slice sliceNum; slice++) { rad = (slice / (float)sliceNum) * MathHelper.TwoPi; float x = (float)Math.Cos(rad) * r; float z = (float)Math.Sin(rad) * r; Vector3 normal = Vector3.Normalize(new Vector3(x, y, z)); vertices[i++] = new VertexPositionNormalColor( normal, normal, (slice 1) == 0 ? Color.Red Color.Yellow); } } vertices[i++] = new VertexPositionNormalColor( new Vector3(0, -1, 0), new Vector3(0, -1, 0), Color.Yellow); vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionNormalColor), vertices.Length, BufferUsage.WriteOnly); vertexBuffer.SetData(vertices); // 索引バッファ short[] indices = new short[stackNum * stackNum * 6]; i = 0; int prevHead = 0; // 前の先頭頂点番号 int prevVtx = 1; // 前の頂点数 for (int stack = 0; stack stackNum / 2; stack++) { int currHead = prevHead + prevVtx; // 現在の先頭頂点番号 int currVtx = 4 * (stack + 1); // 現在の頂点数 for (int quad = 0; quad 4; quad++) // 4象限 { int prevQuad = quad * stack; // 前の象限オフセット int currQuad = quad * (stack + 1); // 現在の象限オフセット for (int n = 0; ; n++) { indices[i++] = (short)(prevHead + (prevQuad + n) % prevVtx); indices[i++] = (short)(currHead + (currQuad + n)); indices[i++] = (short)(currHead + (currQuad + n + 1) % currVtx); if (stack = n) break; indices[i++] = (short)(prevHead + (prevQuad + n)); indices[i++] = (short)(currHead + (currQuad + n + 1)); indices[i++] = (short)(prevHead + (prevQuad + n + 1) % prevVtx); } } prevHead = currHead; prevVtx = currVtx; } for (int stack = stackNum / 2 - 1; 0 = stack; stack--) { int currHead = prevHead + prevVtx; int currVtx = Math.Max(4 * stack, 1); for (int quad = 0; quad 4; quad++) // 4象限 { int prevQuad = quad * (stack + 1); int currQuad = quad * stack; for (int n = 0; ; n++) { indices[i++] = (short)(currHead + (currQuad + n) % currVtx); indices[i++] = (short)(prevHead + (prevQuad + n + 1) % prevVtx); indices[i++] = (short)(prevHead + (prevQuad + n)); if (stack = n) break; indices[i++] = (short)(currHead + (currQuad + n)); indices[i++] = (short)(currHead + (currQuad + n + 1) % currVtx); indices[i++] = (short)(prevHead + (prevQuad + n + 1)); } } prevHead = currHead; prevVtx = currVtx; } indexBuffer = new IndexBuffer(GraphicsDevice, typeof(short), indices.Length, BufferUsage.WriteOnly); indexBuffer.SetData(indices); base.LoadContent(); } protected override void Update(GameTime gameTime) { KeyboardState kState = Keyboard.GetState(); if (kState.IsKeyDown(Keys.Escape)) Exit(); if (kState.IsKeyDown(Keys.Up)) camLat++; if (kState.IsKeyDown(Keys.Down)) camLat--; if (kState.IsKeyDown(Keys.Left)) camLong = (camLong + 1) % 360; if (kState.IsKeyDown(Keys.Right)) camLong = (camLong + 359) % 360; if (kState.IsKeyDown(Keys.PageUp)) camDist -= 0.1f; if (kState.IsKeyDown(Keys.PageDown)) camDist += 0.1f; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); //GraphicsDevice.RasterizerState = // new RasterizerState { FillMode = FillMode.WireFrame }; // カメラ位置 float rad = MathHelper.ToRadians(camLat); float y = (float)Math.Sin(rad) * camDist; float r = (float)Math.Cos(rad) * camDist; rad = MathHelper.ToRadians(camLong); float x = (float)Math.Cos(rad) * r; float z = (float)Math.Sin(rad) * r; effect.View = Matrix.CreateLookAt(new Vector3(x, y, z), Vector3.Zero, Vector3.Up); GraphicsDevice.SetVertexBuffer(vertexBuffer); GraphicsDevice.Indices = indexBuffer; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 3); } // fps draw++; if (gameTime.TotalGameTime.Seconds != sec) { fps = draw; draw = 0; sec = gameTime.TotalGameTime.Seconds; } sprite.Begin(); string text = String.Format( "fps={0} lat={1} long={2} dist={3 f1}", fps, camLat, camLong, camDist); sprite.DrawString(font, text, new Vector2(0, 0), Color.White); sprite.End(); base.Draw(gameTime); } } }
https://w.atwiki.jp/sampleisbest/pages/511.html
開発環境 Microsoft Visual Studio Community 2017 実行環境 Microsoft Windows 10 Home (64-bit) プロジェクトの種類 Visual C++ / 空のプロジェクト プロジェクト名 waveout waveout.cpp /* プロジェクト・プロパティ 全般 Unicode 文字セット WaveOnMessage系は無理に処理する必要はない。 */ #pragma comment(lib, "winmm") #include Windows.h #include wchar.h #include math.h #include "resource.h" #define SAMPLE_RATE 48000 // 関数プロトタイプ宣言 void Trace(PCWSTR format, ...); INT_PTR CALLBACK MainDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); void CALLBACK waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2); void Play(HWND hDlg); void Stop(HWND hDlg); LPSTR GenerateWaveform(); // グローバル変数 HWAVEOUT hwo = NULL; WAVEHDR wh; LPSTR lpData = NULL; DWORD dwBufferLength; int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDlgProc); return 0; } void Trace(PCWSTR format, ...) { va_list arg_ptr; WCHAR buffer[256]; va_start(arg_ptr, format); int size = _vsnwprintf_s(buffer, _TRUNCATE, format, arg_ptr); va_end(arg_ptr); OutputDebugString(buffer); } INT_PTR CALLBACK MainDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { INT_PTR nRet = TRUE; switch (uMsg) { case MM_WOM_OPEN Trace(L"MM_WOM_OPEN \n"); break; case MM_WOM_CLOSE Trace(L"MM_WOM_CLOSE \n"); break; case MM_WOM_DONE Trace(L"MM_WOM_DONE \n"); //Stop(hDlg); break; case WM_COMMAND switch (LOWORD(wParam)) { case IDOK Play(hDlg); break; case IDCANCEL Stop(hDlg); break; } break; case WM_INITDIALOG break; case WM_CLOSE Stop(hDlg); EndDialog(hDlg, 0); break; default nRet = FALSE; } return nRet; } void CALLBACK waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) { switch (uMsg) { case WOM_OPEN Trace(L"WOM_OPEN "); break; case WOM_CLOSE Trace(L"WOM_CLOSE "); break; case WOM_DONE Trace(L"WOM_DONE "); break; } Trace(L" %x\n", dwInstance); } void Play(HWND hDlg) { lpData = GenerateWaveform(); // UINT mmr; WAVEFORMATEX wfx; wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.nChannels = 1; wfx.nSamplesPerSec = SAMPLE_RATE; wfx.nAvgBytesPerSec = SAMPLE_RATE; wfx.nBlockAlign = 1; wfx.wBitsPerSample = 8; wfx.cbSize = 0; //mmr = waveOutOpen( hwo, WAVE_MAPPER, wfx, (DWORD_PTR)hDlg, NULL, CALLBACK_WINDOW); mmr = waveOutOpen( hwo, WAVE_MAPPER, wfx, (DWORD_PTR)waveOutProc, 0xcafe, CALLBACK_FUNCTION); Trace(L"waveOutOpen %u\n", mmr); wh.lpData = (LPSTR)lpData; wh.dwBufferLength = dwBufferLength; wh.dwFlags = 0; mmr = waveOutPrepareHeader(hwo, wh, sizeof wh); Trace(L"waveOutPrepareHeader %u\n", mmr); mmr = waveOutWrite(hwo, wh, sizeof wh); Trace(L"waveOutWrite %u\n", mmr); EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); } void Stop(HWND hDlg) { Trace(L"Stop()\n"); if (hwo) { UINT mmr; mmr = waveOutReset(hwo); Trace(L"waveOutReset %u\n", mmr); mmr = waveOutUnprepareHeader(hwo, wh, sizeof wh); Trace(L"waveOutUnprepareHeader %u\n", mmr); mmr = waveOutClose(hwo); Trace(L"waveOutClose %u\n", mmr); hwo = NULL; } if (lpData) { free(lpData); lpData = NULL; } EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); } LPSTR GenerateWaveform() { const int note[] = { 0, 2, 4, 5, 7, 9, 11, 12 }; dwBufferLength = SAMPLE_RATE * 4; PBYTE data = (PBYTE)malloc(dwBufferLength); memset(data, 0x80, dwBufferLength); int pos = 0; for (int i = 0; i 8; i++) { int freq = (int)(440 * pow(2, (note[i] - 9) / 12.0)); int gate = SAMPLE_RATE / 2; double s = 0; for (int j = 0; j gate; j++) { s += freq; if (s = SAMPLE_RATE) s -= SAMPLE_RATE; double t = s / SAMPLE_RATE; data[pos + j] += (t 0.5 ? 1 -1) * 8; } pos += gate; } return (LPSTR)data; } resource.h #define IDD_MAIN100 #define IDC_STATIC-1 waveout.rc // resource script #include windows.h #include "resource.h" IDD_MAIN DIALOGEX 100, 100, 320, 200 STYLE WS_POPUPWINDOW | WS_MINIMIZEBOX EXSTYLE WS_EX_APPWINDOW CAPTION L"waveout" FONT 9, L"MS Pゴシック" BEGIN DEFPUSHBUTTONL"OK",IDOK,212,176,48,16 PUSHBUTTONL"Cancel",IDCANCEL,264,176,48,16 END