dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

Win32 commctrl - GetOpenFileName troblis!

 
dev.gamez.lv Forum Index -> Programmēšana
View previous topic :: View next topic  
Author Message
Hobits
Indago organizātors


Joined: 04 Jul 2003
Posts: 491
Location: Riga

PostPosted: Sat Jun 04, 2005 1:17 pm    Post subject: Win32 commctrl - GetOpenFileName troblis!

Jo!
Man ir viena probleeminja ar win32 saistiibaa. Vajag helpu!
Lieta taada ka noraadot un atverot failu ar GetOpenFileName paliidziibu kaut kaa tiek samainiiti programmas pathi, respektiivi paths tiek uzsetots uz to vietu no kuras ir atveerts fails un ja peec tam meegjina piemeeram veidot jaunu failu ar kaut vai topashu FILE un fopen funkciju tad tas fails tiek izveidots direktorijaa no kura ir ticis atveerts peedeejais fails ar GetOpenFileName funkciju, nevis tajaa vietaa kur atrodaas programma.
Vai ir kaut kaada funkcija kas uzstaada pathu atpakalj uz folderi kur atrodas programma? Man nav pat ideja ko mekleet 8/
Hmm, varbuut probleema ir citur?
Sheku reku file open funkcija deelj kuras visa beeda:
Code:

string OpenTheFile(HWND hWnd)
{
   OPENFILENAME OpenFileName;
   TCHAR         szFile[MAX_PATH]      = "\0";

   // Fill in the OPENFILENAME structure to support a template and hook.
   OpenFileName.lStructSize       = sizeof(OPENFILENAME);
    OpenFileName.hwndOwner         = hWnd;
    OpenFileName.hInstance         = GetModuleHandle(0);
    OpenFileName.lpstrFilter       = "CFG File *.cfg\0*.CFG\0\0";
    OpenFileName.lpstrCustomFilter = NULL;
    OpenFileName.nMaxCustFilter    = 0;
    OpenFileName.nFilterIndex      = 0;
    OpenFileName.lpstrFile         = szFile;
    OpenFileName.nMaxFile          = sizeof(szFile);
    OpenFileName.lpstrFileTitle    = NULL;
    OpenFileName.nMaxFileTitle     = 0;
    OpenFileName.lpstrInitialDir   = NULL;
    OpenFileName.lpstrTitle        = "Open a File";
    OpenFileName.nFileOffset       = 0;
    OpenFileName.nFileExtension    = 0;
    OpenFileName.lpstrDefExt       = 0;
    OpenFileName.lCustData         = NULL;
   OpenFileName.lpfnHook          = 0;
   OpenFileName.lpTemplateName    = 0;
    OpenFileName.Flags             = 0;

// Call the common dialog function.
    if (GetOpenFileName(&OpenFileName))
    {
      return string(OpenFileName.lpstrFile);
    }    
   
   return string("");
}
Back to top
View user's profile Send e-mail Visit poster's website
GiGa
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 25 Sep 2003
Posts: 887

PostPosted: Sat Jun 04, 2005 1:37 pm    Post subject:

Es gan neatceros, ka man buutu taada probleema ar GetOpenFileName bijusi un tagad uzreiz nepateikshu kaapeec Tev taada vareetu rasties, bet shaadi vareetu atrisinaat probleemu, peec tam uzsetojot atpakalj uz pareizo direktoriju:
Code:

char CurrentPath[MAX_PATH];
GetModuleFileName(hInstance, CurrentPath, MAX_PATH);
GetDir(CurrentPath);
SetCurrentDirectoryA(CurrentPath);

kur hInstance Tavas progas instance un GetDir - funkcija, kas vienkaarshi nonjem nost file name'u dotajaa celjaa.

Edit:
Un shitaada man izskataas taa GetDir:
Code:

void GetDir(char *Path)
{
int l=0,Last;
for(;;l++)
{
if(Path[l]=='\\') Last=l;
if(Path[l]=='\0') break;
}
Path[Last+1]='\0';
}

_________________
Back to top
View user's profile Send e-mail
Vecais_Dumais_Laacis
Guru
Guru


Joined: 29 Jan 2004
Posts: 800

PostPosted: Sat Jun 04, 2005 2:04 pm    Post subject:

OpenFileName.Flags=OFN_NOCHANGEDIR;
Restores the current directory to its original value if the user changed the directory while searching for files.
_________________
...un ja bites buutu laachi...
Back to top
View user's profile
Hobits
Indago organizātors


Joined: 04 Jul 2003
Posts: 491
Location: Riga

PostPosted: Sat Jun 04, 2005 2:05 pm    Post subject:

Izskataas ka izdevaas, paldies Gint.

Vai tik vaina nevareeja buut deelj taa ka openfile dialogam kaa parents bija uzstaadiits nevis galvenaa loga hwnd, bet gan cits dialoglogs?
Back to top
View user's profile Send e-mail Visit poster's website
GiGa
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 25 Sep 2003
Posts: 887

PostPosted: Sat Jun 04, 2005 2:07 pm    Post subject:

Opaa, luuk arii VDL pateica to, ko es nevareeju Wink
_________________
Back to top
View user's profile Send e-mail
Hobits
Indago organizātors


Joined: 04 Jul 2003
Posts: 491
Location: Riga

PostPosted: Sat Jun 04, 2005 2:09 pm    Post subject:

Dem.. es jau skatiijos uz to pashu flagu un domaaju mosh tas kaut ko maina, butu paproveejis ieekonomeetu krietnu dalju laika.

Senks koleegas. :)
Back to top
View user's profile Send e-mail Visit poster's website
Display posts from previous:   
dev.gamez.lv Forum Index -> Programmēšana All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group