unit general; interface uses Windows, Menus, WMPLib_TLB; function gfnbOpenFileDialog(var sFile: WideString): Boolean; procedure gpcMenuSubMenuFree(MenuItem: TMenuItem); procedure gpcWMPSetBounds(WindowsMediaPlayer: TWindowsMediaPlayer; const rcRect: TRect); function gfnbWMPMediaIsDVD(WindowsMediaPlayer: TWindowsMediaPlayer): Boolean; function gfnbMediaIsDVD(sMedia: WideString): Boolean; function gfnbKeyState(iKey: Integer): Boolean; function gfniStrToInt(sNum: WideString): Int64; function gfnsClassNameGet(hHandle: HWND): AnsiString; implementation uses ActiveX, SysUtils, CommDlg, Forms; function gfnbOpenFileDialog(var sFile: WideString): Boolean; { Unicode対応のファイル選択ダイアログ。 http://delwiki.info/?%A5%B3%A1%BC%A5%C9%C1%D2%B8%CB%2FUnicode%C2%D0%B1%FE%B0%C6%A4%BD%A4%CE%A3%B2 } var lr_Info: TOpenFilenameW; begin FillChar(lr_Info, SizeOf(lr_Info), 0); //0で初期化 with lr_Info do begin lStructSize := SizeOf(lr_Info); hWndOwner := Application.Handle; Flags := OFN_EXPLORER; nMaxFile := 1024 * 1024; lpstrFile := AllocMem((nMaxFile + 2) * 2); //終了マーカーの'#0#0'の分で + 2。Unicodeなのでその2倍。 try Result := GetOpenFileNameW(lr_Info); if (Result) then begin //一つだけ選択 sFile := WideString(lpstrFile); end; finally FreeMem(lpstrFile); end; end; end; //メニュー procedure gpcMenuSubMenuFree(MenuItem: TMenuItem); //MenuItemのサブメニューを解放。 var i: Integer; begin for i := MenuItem.Count -1 downto 0 do begin MenuItem.Items[i].Free; end; end; procedure gpcWMPSetBounds(WindowsMediaPlayer: TWindowsMediaPlayer; const rcRect: TRect); //メディアプレーヤーのサイズをセット const lcID_IOLE_INPLACEOBJECT: TGUID = '{00000113-0000-0000-C000-000000000046}'; var lI_Obj: IOleInPlaceObject; begin IDispatch(WindowsMediaPlayer.OleObject).QueryInterface(lcID_IOLE_INPLACEOBJECT, lI_Obj); lI_Obj.SetObjectRects(rcRect, rcRect); //↓はあった方がちらつきが少ない Application.ProcessMessages; end; function gfnbMediaIsDVD(sMedia: WideString): Boolean; begin Result := (Copy(sMedia, 1, 9) = 'wmpdvd://'); end; function gfnbWMPMediaIsDVD(WindowsMediaPlayer: TWindowsMediaPlayer): Boolean; begin Result := (Assigned(WindowsMediaPlayer.currentMedia)) and (gfnbMediaIsDVD(WindowsMediaPlayer.currentMedia.sourceURL)); end; function gfnbKeyState(iKey: Integer): Boolean; var li_Check: SHORT; begin //左右ボタンを入れ替えている場合に対処 if (GetSystemMetrics(SM_SWAPBUTTON) <> 0) then begin if (iKey = VK_LBUTTON) then begin iKey := VK_RBUTTON; end else if (iKey = VK_RBUTTON) then begin iKey := VK_LBUTTON; end; end; li_Check := GetAsyncKeyState(iKey); //Result := BOOL(Hi(li_Check)) and (BOOL(Lo(li_Check))); Result := BOOL(Hi(li_Check)); end; function gfniStrToInt(sNum: WideString): Int64; //sNumを整数にして返す。 var li_Pos, i: Integer; ls_Tmp: AnsiString; begin sNum := WideUpperCase(Trim(sNum)); try Result := StrToInt64(sNum); except ls_Tmp := ''; for i := 1 to Length(sNum) do begin li_Pos := Pos(sNum[i], '$X-+0123456789ABCDEF'); if (li_Pos >= 15) then begin if (ls_Tmp[1] = '$') then begin ls_Tmp := ls_Tmp + sNum[i]; end else begin //頭に'$'を付け加えて変換できるようにする //頭に$がないと16進表記はエラーになるのでそれへの対処 ls_Tmp := '$' + ls_Tmp + sNum[i]; end; end else if (li_Pos >= 5) then begin ls_Tmp := ls_Tmp + sNum[i]; end else if ((li_Pos = 1) or (li_Pos = 2)) and (ls_Tmp = '') then begin //16進表記 ls_Tmp := '$'; //'x'や'X'ではだめ end else if ((li_Pos = 3) or (li_Pos = 4)) and (ls_Tmp = '') then begin //and (i = 1) でもよい //sNum[i]は'-+'のどれか ls_Tmp := sNum[i]; end else begin Break; end; end; if (ls_Tmp = '') then begin Result := 0; end else begin Result := StrToInt64Def(ls_Tmp, 0); end; end; end; function gfnsClassNameGet(hHandle: HWND): AnsiString; //ウィンドウハンドルhHandleのクラス名を返す const lci_LEN = 256; var lp_Class: PAnsiChar; begin Result := ''; lp_Class := AllocMem(lci_LEN); try GetClassName(hHandle, lp_Class, lci_LEN -1); Result := AnsiString(lp_Class); finally FreeMem(lp_Class); end; end; end.