# DirectX and Open File Dialogs +more questions.

This topic is 4878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Apparently four questions, the big one first. I'm learning DirectX while building a program and I've been very successful so far. I want to be able to open file Dialogs in a simplistic way. (I don't want to have to code an entire file directory structure if I can avoid it, I've already done a Button and a TextField Item that took a good amount of time.) So I started using MFC for a bit.
 bool Avatar::openfilename(HWND m_hWnd,IDirect3DDevice9* D3DDevice){
HRESULT hr;
static TCHAR strFileName[MAX_PATH] = TEXT("");
static TCHAR strPath[MAX_PATH] = TEXT("");

// Setup the OPENFILENAME structure
OPENFILENAME ofn = { sizeof(OPENFILENAME),m_hWnd, NULL,
TEXT("Character graphics bmp,jpg,gif\0*.bmp;*.jpg;*.gif\0All Files\0*.*\0\0"), NULL,
0, 1, strFileName, MAX_PATH, NULL, 0, strPath,
TEXT("Open Image file"),
NULL, 0, NULL, NULL };

// Get the default media path (something like C:\WINDOWS\MEDIA)
if( '\0' == strPath[0] )
{
if( GetCurrentDirectory(MAX_PATH, strPath ) != 0 )
{
//StringCchCat( strPath, MAX_PATH, TEXT("\\MEDIA") );
}
}

// Display the OpenFileName dialog. Then, try to load the specified file
if( TRUE != GetOpenFileName( &ofn ) )
{
// SetDlgItemText( m_hWnd, IDC_FILENAME, TEXT("Load aborted.") );
return Error("You have chosen not to open a file",m_hWnd);
}

// Verify the file is small
D3DXIMAGE_INFO imageinfo;
if(FAILED(hr=D3DXCreateTextureFromFileEx(D3DDevice, strFileName, D3DX_DEFAULT,
D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
D3DX_DEFAULT, D3DX_DEFAULT, 0, &imageinfo, NULL, &image)))
{
SAFE_RELEASE(image);
return Error("Could not load graphic file",m_hWnd);

}
else
if(imageinfo.Height<=128&&imageinfo.Width<=128)
{
xsize=imageinfo.Width;
ysize=imageinfo.Height;
}
else
{
SAFE_RELEASE(image);
return Error("Image is too large",m_hWnd);
}

// Remember the path for next time
/*
WCHAR* strLastSlash = wcsrchr( strPath, '\\' );
if( strLastSlash )
strLastSlash[0] = '\0';
*/	avatarfilename=strFileName;
//avatarpathname=strPath;
return true;
}


Which works fine in a Windowed Mode (If you want to know what I'm doing, I'm loading an avatar picture, which can only be 100x100 or less (I gave in and did 128x128) And then it'll save the filename (so I can save the character's data including this) Anyways when I try to use this in Fullscreen.. well it crashes and it gets really iffy (I can't debug it easily unfortunatly and it gets really bleeped up.) Is the MFC getOpenFileName not applicable for this use? In addition I have a few other questions that have come up in the last month. Is there any reason that F10 pauses a DirectX application? I haven't coded that into my application. Third my DirectX Application takes upwards of 80+percent of the processor even in the release mode, is there a way to tone it down? (or should I even think about that til I'm done coding?) finally a question about File IO
	HANDLE hFile;
DWORD write;
hFile = CreateFile(strFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile==INVALID_HANDLE_VALUE)
return Error("File creaton failed.",hWnd);
LightPlayerRip temp;
strcpy(temp.name,name.c_str());
strcpy(temp.filename,picture->getfilename().c_str());
strcpy(temp.tag,tag.c_str());
temp.realplayer=realplayer;

WriteFile(hFile,&temp,sizeof(LightPlayerRip) ,&write,NULL);

CloseHandle(hFile);


This obviously is a MFC class (Which i've been using minimal amounts of ) is this the best way to do file IO? (Light player is actually a class, Rip is just a struct that has the bare essentials with char instead of strings (because I have to edit the data into char's anyways as Writefile doesn't like anything "other then primitives" apparently?)

##### Share on other sites
To be honest, I don't see an ounce of MFC in that code =) It all looks like Win32 API to me. Oh well, no biggie. Anyway...

Quote:
 *Std Dialog Box Stuff*

 I'm assuming you're using Direct3D? [/edit]
Try calling 'IDirect3DDevice::SetDialogBoxMode(TRUE);'. It's supposed to allow dialog boxes to be usable in fullscreen mode. I haven't actually tried it so I can't really say weather or not it will work in this case.

Quote:
 In addition I have a few other questions that have come up in the last month. Is there any reason that F10 pauses a DirectX application? I haven't coded that into my application.

I have never seen/heard/smelled this before. Are you sure there is nothing else, another 3rd party library perhaps, doing this?

Quote:
 Third my DirectX Application takes upwards of 80+percent of the processor even in the release mode, is there a way to tone it down? (or should I even think about that til I'm done coding?)

Are you using only a single thread? Are you ever pausing it to allow other threads/processes extra time. It probably isn't too big of a deal for an average hobby-like project. If you really can't stand it, look into using multiple threads. That way you can separate your game-logic and the message-pump, and suspend threads that are getting too much processing time.

Quote:
 This obviously is a MFC class (Which i've been using minimal amounts of ) is this the best way to do file IO?

That actually looks like a Win32 API function to me ;)
Some people will say not to use it if you plan to port to another platform. And that you should use standard C/C++ file IO functions. Some will say, "Go ahead! It works fine. You can always change it later." Others will suggest some kind of file I/O library to handle the details for you. Personally, I don't think it matters a whole lot for simple I/O features. If you like it, use it. If not, use something else.

##### Share on other sites
YEah currently this is 100 percent Windows Born and bred (I can't really port a game from Windows to DirectX with out a total overhaul (using Directinput, Direct3d, and hopefully DirectPlay/DirectSound (I'm doing this to learn DirectX)) so I'll be keeping with this function.

As for SetDialogBoxMode It appears To work but is it supposed to minimize the ENTIRE window, allow you to input your selection and then you have to double click on the program again? to me that doesn't sound just right?

also is it supposed to be a little slow to open up the dialog box?

##### Share on other sites
Has anyone used this or have a suggestion on a better way to do File Dialog? For me right now it just shrinks to a small window and then stays small after using the file dialog.

In addition I had a question about toggling Fullscreen, because I seem not to get it working any more after fooling around on this topic. Toggle Fullscreen problems

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 36
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631703
• Total Posts
3001816
×