Problems with GetOpenFileName function

Posted By: txesmi

Problems with GetOpenFileName function - 08/30/16 20:42

Hi,
Once a file is selected with GetOpenFileName the engine does not find the paths to the files it already found before. I squeezed the problem to the following full working bunch of code lines.
Code:
#include <acknex.h>
#include <windows.h>
#define PRAGMA_PATH "images"

char* fileOpenDialog ( char* _chrLocation, char* _chrFilter )
{
	char szFile[MAX_PATH];
	ZeroMemory ( szFile, MAX_PATH );
	OPENFILENAME ofn;
	ZeroMemory ( &ofn, sizeof(OPENFILENAME) );
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NOREADONLYRETURN;
	if ( _chrFilter ) 
	{
		char szFilter[256];
	   ZeroMemory ( szFilter, 256 );
	   int size = str_len ( _chrFilter );
	   strcpy ( szFilter, _chr(_chrFilter) );
	   strcpy ( szFilter+size+1, _chr(_chrFilter) );
	   ofn.lpstrFilter = szFilter;
	} 
	else
	{
	   ofn.lpstrFilter = "All Files(*.*)\0*.*\0\0";
	}
	ofn.lpstrTitle      = NULL;
	ofn.lpstrFile       = szFile;
	ofn.nMaxFile        = MAX_PATH;
	ofn.lpstrInitialDir = _chr(_chrLocation);
	ofn.hwndOwner       = hWnd;
	if ( GetOpenFileName(&ofn) )
		return szFile;
	else
	   return NULL;
}

void evnSpace ()
{
	while ( key_space )
		wait(1);
	char *_chr = fileOpenDialog ( NULL, NULL );
}

void main ()
{
	wait(1);
	level_load ( "" );
	on_space = evnSpace;
	while ( !key_esc )
	{
		draw_text ( work_dir, 10, 10, COLOR_WHITE ); // Never changes
		if ( file_exists ( "negro.png" ) )
			draw_text ( "the file is accesable", 10, 40, COLOR_GREEN );
		else
			draw_text ( "the file is not accesable", 10, 40, COLOR_RED );
		wait(1);
	}
	sys_exit ( NULL );
}



After a week of headaches I would bet it changes the engines working folder because in the case you select a file into the project main folder everything works as expected although you select a file out of it before.

Any hint on how to restore the engines working path? Could this issue be a bug? I copied the dialog opening code from this forum. I am a winapi nescient laugh

Thak you in advance,
txes
Posted By: txesmi

Re: Problems with GetOpenFileName function - 08/30/16 20:50

I just found the flag OFN_NOCHANGEDIR

I can't understand how I missed it blush
© 2024 lite-C Forums