約 2,850,867 件
https://w.atwiki.jp/sampleisbest/pages/412.html
開発環境 メモ帳 実行環境 Windows 7 Home Premium (32bit)
https://w.atwiki.jp/sampleisbest/pages/547.html
vsync2.asm comment * MASM32 SDK ml /c /AT /Fl vsync2.asm link16 /t vsync2; * .modeltiny TABLEequ0028h; VSYNC VRAMSEGequ0a000h CLSequ1ah ESCAPEequ1bh .code org0100h mainproc movah, 02h movdl, CLS int21h callsetvect out64h, al; VSYNCリセット @@loop calldisp movah, 0bh; キーボードのステータスチェック int21h cmpal, 0 je@@loop movah, 07h; コンソールからの直接入力 int21h cmpal, ESCAPE jne@@loop callresvect movax, 4c00h int21h mainendp myint0aprocfar sti inccs count out64h, al; VSYNCリセット jmpcs [vect] ;iret myint0aendp setvectproc cli movax, 0000h moves, ax movsi, TABLE movax, es [si] movvect_off, ax movax, es [si+2] movvect_seg, ax movax, offset myint0a moves [si], ax movax, cs; = seg myint0a moves [si+2], ax inal, 02h andal, 0fbh; VSYNC割り込みマスク on out02h, al jmp$+2 sti ret setvectendp resvectproc cli inal, 02h oral, 04h; VSYNC割り込みマスク off out02h, al movax, 0000h moves, ax movsi, TABLE movax, vect_off moves [si], ax movax, vect_seg moves [si+2], ax jmp$+2 sti ret resvectendp dispproc movah, 00h; 日付・時刻の読み出し pushcs popes movbx, offset clock int1ch; カレンダ時計のBIOS moval, clock[5] cmpal, sec je@@skip movsec, al movax, count movdx, ax subax, fps movfps, dx movdi, offset buf calltodec5 @@skip movax, count movdi, offset buf + 6 calltodec5 movax, VRAMSEG moves, ax movsi, offset buf movdi, 0 cld movah, 0 movcx, 11 @@loop lodsb stosw loop@@loop ret dispendp ; ax=数値 di=バッファ todec5proc adddi, 5 movbx, 10 movcx, 5 @@loop movdx, 0 divbx adddl, 0 decdi mov[di], dl loop@@loop ret todec5endp vectlabeldword vect_offdw? vect_segdw? secdb-1 fpsdw0 countdw0 clockdb6 dup (?) bufdb xxxxx xxxxx endmain
https://w.atwiki.jp/sampleisbest/pages/500.html
small.asm ;small.asm ;for MASM32 .modelsmall stdoutequ1 lfequ0ah crequ0dh .data outdatadb hello, world , cr, lf outdata_lenequ$ - outdata .code start movax, @data movds, ax movdx, offset outdata movcx, outdata_len movbx, stdout movah, 40h int21h movax, 4c00h int21h endstart コマンドプロンプト path %path%;c \masm32\bin ml /c /Fl small.asm link16 /st 0xcafe small.obj; ダンプリスト _IMAGE_DOS_HEADER (winnt.h) 0000 5a4d Magic number (MZ=5a4d) 0002 0026 Bytes on last page of file 0004 0002 Pages in file (1page=512bytes) 0006 0001 Relocations 0008 0020 Size of header in paragraphs (1para=16bytes) 000a 0000 Minimum extra paragraphs needed 000c ffff Maximum extra paragraphs needed 000e 0000 Initial (relative) SS value 0010 cafe Initial SP value 0012 0000 Checksum 0014 0000 Initial IP value 0016 0000 Initial (relative) CS value 0018 001e File address of relocation table 001a 0000 Overlay number address 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 0123456789abcdef 00000000 4d 5a 26 00-02 00 01 00-20 00 00 00-ff ff 00 00 MZ ..... ....... 00000010 fe ca 00 00-00 00 00 00-1e 00 00 00-01 00 01 00 ................ 00000020 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000030 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000040 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000050 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000060 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000070 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000080 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000090 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000000a0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000000b0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000000c0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000000d0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000000e0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000000f0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000100 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000110 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000120 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000130 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000140 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000150 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000160 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000170 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000180 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000190 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000001a0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000001b0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000001c0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000001d0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000001e0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 000001f0 00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00 ................ 00000200 b8 01 00 8e-d8 ba 08 00-b9 0e 00 bb-01 00 b4 40 ...............@ 00000210 cd 21 b8 00-4c cd 21 00-68 65 6c 6c-6f 2c 20 77 .!..L.!.hello, w 00000220 6f 72 6c 64-0d 0a - - orld..
https://w.atwiki.jp/mybestapp/pages/15.html
test
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/ponyta_isii/pages/353.html
【ポケモンカード公式】ハイクラスパック「THE BEST OF XY」2BOX開封とは、ポケモンカード公式チャンネル第198回のこと。 (第197回 ←← 第198回 →→ 第199回) 概要欄 ハイクラスパック「THE BEST OF XY」4/21発売! 早速2BOXを開封してみたぞ! 登場するキャラクター ポニータ石井 ピッピ樋口 Youtube動画 字幕・台詞 備考 当たり内訳 草:ジュカインEX、MジュカインEX 炎:バクーダEX×2 水:ゲッコウガBREAK 雷:ライボルトEX×2、サンダースEX(SR) 闘:ルカリオEX×2、メレシーBREAK 超:フーディンEX、ミュウツーEX 悪:イベルタルEX(UR)、イベルタルEX、サメハダーEX、カラマネロEX 鋼:マギアナEX ドラゴン:サザンドラEX フェアリー:サーナイトEX 無色:シェイミEX 使用されているBGM #0 00 Lying On Cloud #0 56 Morning #4 55 Stream #7 24 王国への凱旋
https://w.atwiki.jp/koushien-yosou/pages/187.html
人数:的中校数別 平均的中数 人数:的中校数別 的中 人数 称号 8校 1人 神 7校 4人 プチ神 6校 25人 天使 5校 41人 プチ天使 4校 67人 人間 3校 56人 プチ悪魔 2校 30人 悪魔 1校 12人 プチ逆神 0校 3人 逆神 平均的中数 平均的中数 3.76校 参加人数 239人 予想パターン 65,536通り メニュー ↑ ページの上部へ
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/71.html
開発環境 Microsoft Visual C++ 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 Win32 プロジェクト プロジェクト名 RadioButton アプリケーションの種類 Windows アプリケーション 追加のオプション 空のプロジェクト 文字セット Unicode RadioButton.cpp #include tchar.h #include Windows.h #include WindowsX.h #include "resource.h" INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); void OnOK(HWND hDlg); int APIENTRY _tWinMain( HINSTANCEhInstance, HINSTANCEhPrevInstance, LPTSTRlpCmdLine, intnCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, DialogProc); return 0; } INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { INT_PTR iRetVal = TRUE; switch (uMsg) { case WM_COMMAND switch (LOWORD(wParam)) { case IDOK OnOK(hwndDlg); break; } break; case WM_INITDIALOG Button_SetCheck(GetDlgItem(hwndDlg, IDC_RADIO1), BST_CHECKED); break; case WM_CLOSE EndDialog(hwndDlg, 0); break; default iRetVal = FALSE; } return iRetVal; } void OnOK(HWND hDlg) { LRESULTlr; inti1, i2, i3; i1 = GetDlgItemInt(hDlg, IDC_EDIT1, NULL, TRUE); i2 = GetDlgItemInt(hDlg, IDC_EDIT2, NULL, TRUE); lr = Button_GetCheck(GetDlgItem(hDlg, IDC_RADIO1)); if (lr == BST_CHECKED) { i3 = i1 + i2; } else { i3 = i1 - i2; } SetDlgItemInt(hDlg, IDC_EDIT3, i3, TRUE); } resource.h #define IDD_DIALOG100 #define IDC_STATIC-1 #define IDC_EDIT11000 #define IDC_EDIT21001 #define IDC_EDIT31002 #define IDC_RADIO11003 #define IDC_RADIO21004 RadioButton.rc #include windows.h #include "resource.h" IDD_DIALOG DIALOGEX 300, 200, 130, 55 STYLE WS_POPUPWINDOW | WS_MINIMIZEBOX EXSTYLE WS_EX_APPWINDOW CAPTION "RadioButton" FONT 9, "MS Pゴシック" BEGIN EDITTEXTIDC_EDIT1,4,4,36,12 EDITTEXTIDC_EDIT2,44,4,36,12 EDITTEXTIDC_EDIT3,88,4,36,12 CONTROL"+",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON | WS_GROUP, 8,32,28,12 CONTROL"-",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON, 40,32,28,12 GROUPBOX"演算子",IDC_STATIC,4,20,76,32,WS_GROUP DEFPUSHBUTTON"OK",IDOK,88,24,26,16 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); }