@@ -47,15 +47,17 @@ MLDX12App::MLDX12App(UINT width, UINT height, UINT options)
4747 // 設定を読み出します。
4848 std::string imgPath = mSettings .LoadStringA (" ImgFilePath" );
4949 if (imgPath.empty ()) {
50- strcpy_s (mImgFilePath , " c:/data/OpenEXR_HDR10_test1.exr" );
50+ wcscpy_s (mImgFilePath , L " c:/data/OpenEXR_HDR10_test1.exr" );
5151 } else {
52- strcpy_s (mImgFilePath , imgPath.c_str ());
52+ memset (mImgFilePath , 0 , sizeof mImgFilePath );
53+ MultiByteToWideChar (CP_UTF8, 0 , imgPath.c_str (), -1 , mImgFilePath , _countof (mImgFilePath )-1 );
5354 }
5455 std::string aviPath = mSettings .LoadStringA (" AviFilePath" );
5556 if (aviPath.empty ()) {
56- strcpy_s (mAviFilePath , " D:/test.avi" );
57+ wcscpy_s (mAviFilePath , L " D:/test.avi" );
5758 } else {
58- strcpy_s (mAviFilePath , aviPath.c_str ());
59+ memset (mAviFilePath , 0 , sizeof mAviFilePath );
60+ MultiByteToWideChar (CP_UTF8, 0 , aviPath.c_str (), -1 , mAviFilePath , _countof (mAviFilePath ) - 1 );
5961 }
6062
6163 int outOfRangeR = mSettings .LoadInt (" OutOfRangeR" , 0 );
@@ -75,8 +77,17 @@ MLDX12App::MLDX12App(UINT width, UINT height, UINT options)
7577
7678MLDX12App::~MLDX12App (void )
7779{
78- mSettings .SaveStringA (" ImgFilePath" , mImgFilePath );
79- mSettings .SaveStringA (" AviFilePath" , mAviFilePath );
80+ // WriteToFile()まで消えないバッファーを作る。
81+ char imgPath[MAX_PATH * 3 ];
82+ memset (imgPath, 0 , sizeof imgPath);
83+ WideCharToMultiByte (CP_UTF8, 0 , mImgFilePath , -1 , imgPath, sizeof imgPath - 1 , nullptr , nullptr );
84+ mSettings .SaveStringA (" ImgFilePath" , imgPath);
85+
86+ // WriteToFile()まで消えないバッファーを作る。
87+ char aviPath[MAX_PATH * 3 ];
88+ memset (aviPath, 0 , sizeof aviPath);
89+ WideCharToMultiByte (CP_UTF8, 0 , mAviFilePath , -1 , aviPath, sizeof aviPath - 1 , nullptr , nullptr );
90+ mSettings .SaveStringA (" AviFilePath" , aviPath);
8091
8192 int outOfRangeR = (int )(mShaderConsts .outOfRangeColor .x * 255 .0f );
8293 int outOfRangeG = (int )(mShaderConsts .outOfRangeColor .y * 255 .0f );
@@ -127,7 +138,7 @@ MLDX12App::OnInit(void)
127138
128139 if (argc == 2 ) {
129140 wchar_t * pathW = argv[1 ];
130- WideCharToMultiByte (CP_UTF8, 0 , pathW, - 1 , mImgFilePath , sizeof ( mImgFilePath ) - 1 , nullptr , nullptr );
141+ wcscpy_s ( mImgFilePath , pathW );
131142 ReadImg ();
132143 }
133144 }
@@ -807,6 +818,15 @@ MLDX12App::OnKeyUp(int key)
807818 }
808819}
809820
821+ void
822+ MLDX12App::OnDropFiles (HDROP hDrop)
823+ {
824+ UINT rv = DragQueryFile (hDrop, 0 , mImgFilePath , _countof (mImgFilePath ) - 1 );
825+ if (0 < rv) {
826+ mRequestReadImg = true ;
827+ }
828+ }
829+
810830void
811831MLDX12App::OnSizeChanged (int width, int height, bool minimized)
812832{
@@ -1070,6 +1090,8 @@ void
10701090MLDX12App::ShowVideoCaptureWindow (void )
10711091{
10721092 HRESULT hr = S_OK;
1093+ char s[MAX_PATH * 3 ];
1094+ memset (s, 0 , sizeof s);
10731095
10741096 ImGui::Begin (" Video Capture Settings ##VCS" );
10751097
@@ -1162,25 +1184,26 @@ MLDX12App::ShowVideoCaptureWindow(void)
11621184 MLAviImageFormat aviIF = BMDPixelFormatToMLAviImageFormat (fmt.pixelFormat );
11631185
11641186 if (MLIF_Unknown != aviIF) {
1165- ImGui::InputText (" Record AVI filename ##VCS" , mAviFilePath , sizeof mAviFilePath - 1 );
1187+ WideCharToMultiByte (CP_UTF8, 0 , mAviFilePath , -1 , s, sizeof s - 1 , nullptr , nullptr );
1188+ if (ImGui::InputText (" Record AVI filename ##VCS" , s, sizeof s - 1 )) {
1189+ // text Updated.
1190+ MultiByteToWideChar (CP_UTF8, 0 , s, -1 , mAviFilePath , _countof (mAviFilePath ));
1191+ }
1192+
11661193 if (ImGui::Button (" Record ## VCS" , ImVec2 (256 , 48 ))) {
1167- if (PathFileExistsA (mAviFilePath )) {
1168- sprintf_s (mErrorVCMsg , " Error: File exists.\n Please input different file name. %s " , mAviFilePath );
1194+ if (PathFileExists (mAviFilePath )) {
1195+ sprintf_s (mErrorVCMsg , " Error: File exists.\n Please input different file name." );
11691196 ImGui::OpenPopup (" ErrorVCPopup" );
11701197 } else {
1171- wchar_t path[512 ];
1172- memset (path, 0 , sizeof path);
1173- MultiByteToWideChar (CP_UTF8, 0 , mAviFilePath , sizeof mAviFilePath , path, 511 );
1174-
11751198 bool bRv = mVCU .AviWriter ().Start (
1176- path , fmt.width , fmt.height ,
1199+ mAviFilePath , fmt.width , fmt.height ,
11771200 (double )fmt.frameRateTS /fmt.frameRateTV ,
11781201 aviIF, true );
11791202 if (bRv) {
11801203 mVCState = VCS_Recording;
11811204 mErrorVCMsg [0 ] = 0 ;
11821205 } else {
1183- sprintf_s (mErrorVCMsg , " Error: Record Failed.\n File open error : %s " , mAviFilePath );
1206+ sprintf_s (mErrorVCMsg , " Error: Record Failed.\n File open error. " );
11841207 ImGui::OpenPopup (" ErrorVCPopup" );
11851208 }
11861209 }
@@ -1193,7 +1216,7 @@ MLDX12App::ShowVideoCaptureWindow(void)
11931216 break ;
11941217 case VCS_Recording:
11951218 ImGui::Text (" Now Recording..." );
1196- ImGui::Text (" Record filename : %s " , mAviFilePath );
1219+ ImGui::Text (" Record filename : %S " , mAviFilePath );
11971220 {
11981221 // hour:min:sec:frameを算出。
11991222 auto vt = MLFrameNrToTime ((int )(mVCU .AviWriter ().FramesPerSec ()+0.5 ), mVCU .AviWriter ().TotalVideoFrames ());
@@ -1406,22 +1429,22 @@ enum ExtensionType {
14061429};
14071430
14081431static ExtensionType
1409- PathNameToExtensionType (const char * path)
1432+ PathNameToExtensionType (const wchar_t * path)
14101433{
14111434 assert (path);
14121435
1413- int len = (int )strlen (path);
1436+ int len = (int )wcslen (path);
14141437 if (len < 5 ) {
14151438 return ET_Other;
14161439 }
14171440
1418- if (0 == _stricmp (&path[len - 4 ], " .PNG" )) {
1441+ if (0 == _wcsicmp (&path[len - 4 ], L " .PNG" )) {
14191442 return ET_PNG;
14201443 }
1421- if (0 == _stricmp (&path[len - 4 ], " .EXR" )) {
1444+ if (0 == _wcsicmp (&path[len - 4 ], L " .EXR" )) {
14221445 return ET_EXR;
14231446 }
1424- if (0 == _stricmp (&path[len - 4 ], " .BMP" )) {
1447+ if (0 == _wcsicmp (&path[len - 4 ], L " .BMP" )) {
14251448 return ET_BMP;
14261449 }
14271450 return ET_Other;
@@ -1432,20 +1455,29 @@ MLDX12App::ReadImg(void)
14321455{
14331456 HRESULT hr = 0 ;
14341457
1458+ if (ET_Other == PathNameToExtensionType (mImgFilePath )) {
1459+ sprintf_s (mErrorFileReadMsg , " Error: Unsupported Image format." );
1460+ ImGui::OpenPopup (" ErrorImageFileRWPopup" );
1461+ return E_FAIL;
1462+ }
1463+
14351464 mMutex .lock ();
14361465 hr = MLBmpRead (mImgFilePath , mRenderImg );
14371466 if (hr == 1 ) {
14381467 // ファイルは存在するがBMPではなかった場合。
14391468 hr = MLPngRead (mImgFilePath , mRenderImg );
14401469 if (hr == 1 ) {
14411470 // ファイルは存在するがPNGではなかった場合。
1442- hr = MLExrRead (mImgFilePath , mRenderImg );
1471+ char s[MAX_PATH * 3 ];
1472+ memset (s, 0 , sizeof s);
1473+ WideCharToMultiByte (CP_UTF8, 0 , mImgFilePath , -1 , s, sizeof s - 1 , nullptr , nullptr );
1474+ hr = MLExrRead (s, mRenderImg );
14431475 }
14441476 }
14451477 mMutex .unlock ();
14461478
14471479 if (hr < 0 ) {
1448- sprintf_s (mErrorFileReadMsg , " Error: Read Image Failed.\n File open error : %s " , mImgFilePath );
1480+ sprintf_s (mErrorFileReadMsg , " Error: Read Image Failed." );
14491481 ImGui::OpenPopup (" ErrorImageFileRWPopup" );
14501482 } else {
14511483 mState = S_ImageViewing;
@@ -1458,6 +1490,9 @@ MLDX12App::ReadImg(void)
14581490void
14591491MLDX12App::ShowImageFileRWWindow (void )
14601492{
1493+ char path[MAX_PATH];
1494+ memset (path, 0 , sizeof path);
1495+
14611496 int hr = S_OK;
14621497 ImGui::Begin (" File Read / Write" );
14631498
@@ -1472,7 +1507,12 @@ MLDX12App::ShowImageFileRWWindow(void)
14721507
14731508 if (mState == S_Capturing) {
14741509 // キャプチャー中。
1475- ImGui::InputText (" PNG / EXR Image Filename to Write" , mImgFilePath , sizeof mImgFilePath - 1 );
1510+ memset (path, 0 , sizeof path);
1511+ WideCharToMultiByte (CP_UTF8, 0 , mImgFilePath , -1 , path, sizeof path - 1 , nullptr , nullptr );
1512+ if (ImGui::InputText (" PNG / EXR Image Filename to Write" , path, sizeof path - 1 )) {
1513+ // text has changed. update mImgFilePath.
1514+ MultiByteToWideChar (CP_UTF8, 0 , path, -1 , mImgFilePath , _countof (mImgFilePath ) - 1 );
1515+ }
14761516
14771517 if (mWriteImg .data != nullptr ) {
14781518 // 静止画をファイルに保存する。
@@ -1481,29 +1521,30 @@ MLDX12App::ShowImageFileRWWindow(void)
14811521 switch (et) {
14821522 case ET_PNG:
14831523 if (ImGui::Button (" Write PNG Image ##RF0" , ImVec2 (256 , 48 ))) {
1484- if (PathFileExistsA (mImgFilePath )) {
1485- sprintf_s (mErrorFileReadMsg , " Error: File exists.\n Please input different file name. %s " , mImgFilePath );
1524+ if (PathFileExists (mImgFilePath )) {
1525+ sprintf_s (mErrorFileReadMsg , " Error: File exists.\n Please input different file name." );
14861526 ImGui::OpenPopup (" ErrorImageFileRWPopup" );
14871527 } else {
14881528 hr = MLPngWrite (mImgFilePath , mWriteImg );
14891529
14901530 if (FAILED (hr)) {
1491- sprintf_s (mErrorFileReadMsg , " Error: Write Image Failed.\n File Write error : %s " , mImgFilePath );
1531+ sprintf_s (mErrorFileReadMsg , " Error: Write Image Failed.\n File Write error. " );
14921532 ImGui::OpenPopup (" ErrorImageFileRWPopup" );
14931533 }
14941534 }
14951535 }
14961536 break ;
14971537 case ET_EXR:
14981538 if (ImGui::Button (" Write EXR Image ##RF0" , ImVec2 (256 , 48 ))) {
1499- if (PathFileExistsA (mImgFilePath )) {
1500- sprintf_s (mErrorFileReadMsg , " Error: File exists.\n Please input different file name. %s " , mImgFilePath );
1539+ if (PathFileExists (mImgFilePath )) {
1540+ sprintf_s (mErrorFileReadMsg , " Error: File exists.\n Please input different file name." );
15011541
15021542 ImGui::OpenPopup (" ErrorImageFileRWPopup" );
15031543 } else {
1504- hr = mExrWriter .Write (mImgFilePath , mWriteImg );
1544+ WideCharToMultiByte (CP_UTF8, 0 , mImgFilePath , -1 , path, sizeof path - 1 , nullptr , nullptr );
1545+ hr = mExrWriter .Write (path, mWriteImg );
15051546 if (FAILED (hr)) {
1506- sprintf_s (mErrorFileReadMsg , " Error: Write Image Failed.\n File Write error : %s " , mImgFilePath );
1547+ sprintf_s (mErrorFileReadMsg , " Error: Write Image Failed.\n File Write error. " );
15071548 ImGui::OpenPopup (" ErrorImageFileRWPopup" );
15081549 }
15091550 }
@@ -1515,10 +1556,17 @@ MLDX12App::ShowImageFileRWWindow(void)
15151556 }
15161557 }
15171558 } else {
1518- ImGui::InputText (" EXR/PNG/BMP Image Filename to Read" , mImgFilePath , sizeof mImgFilePath - 1 );
1559+ memset (path, 0 , sizeof path);
1560+ WideCharToMultiByte (CP_UTF8, 0 , mImgFilePath , -1 , path, sizeof path - 1 , nullptr , nullptr );
1561+
1562+ if (ImGui::InputText (" EXR/PNG/BMP Image Filename to Read" , path, sizeof path - 1 )) {
1563+ // text has changed. update mImgFilePath.
1564+ MultiByteToWideChar (CP_UTF8, 0 , path, -1 , mImgFilePath , _countof (mImgFilePath ) - 1 );
1565+ }
15191566
1520- if (ImGui::Button (" Read Image ##RF0" , ImVec2 (256 , 48 ))) {
1567+ if (mRequestReadImg || ImGui::Button (" Read Image ##RF0" , ImVec2 (256 , 48 ))) {
15211568 ReadImg ();
1569+ mRequestReadImg = false ;
15221570 }
15231571 }
15241572
0 commit comments