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"),
OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, 0, 0,
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)))
// if(FAILED(D3DXCreateTextureFromFile(m_pD3DDevice, "Mainmenu.jpg", &m_pMenuBGTexture)))
{
avatarloaded=false;
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;
avatarloaded=true;
}
else
{
avatarloaded=false;
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?)