Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Open File Dialog

Author
Message
Vesper
14
Years of Service
User Offline
Joined: 22nd Nov 2009
Location:
Posted: 28th Jan 2010 13:00
im trying to figure out this open file dialog but im having issues, heres my source:



and the file im trying to open:



im not getting any errors issue is nothing happens. The box comes up, i click open. then it doesnt print. no errors, no warnings. ive always had trouble with file io but i dont know why. I have used a breakpoint and checked out the buffer variable and it contains alot of random numbers and letters when loaded in. I know its not the most efficient but im jes trying to get it to work.

I should also state that when I included all the open dialog code in its own header i kepy getting "no return value specified -int assumed" error even tho i copy pasted the function name...

Show me your combat algorithms(programmers read this NOT in a programming state of mind)
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 28th Jan 2010 22:31
You don't need the CreateFile function call. That belongs to another system of file opening. If you use ifstream, that will open the file given in the constructor. You should rather return a boolean flag which lets you check if the file selection was successful or not (because the user can close the dialog box without selecting anything):



For a first test, you can just call GetOpenFileName without returning anything. If you erase the CreateFile call, then it works.
Vesper
14
Years of Service
User Offline
Joined: 22nd Nov 2009
Location:
Posted: 30th Jan 2010 08:38
okay thanks alot I got it working now

Show me your combat algorithms(programmers read this NOT in a programming state of mind)
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 30th Jan 2010 10:55
Regarding the "no return value specified -int assumed" error, if you get it again, post the code and I'll figure it out. There must be some simple explanation for that type of error message.
Vesper
14
Years of Service
User Offline
Joined: 22nd Nov 2009
Location:
Posted: 30th Jan 2010 11:39
well i get it `00% of the time i try to put the open file code in its own header, heres the code:

header:

with code in main:

without code in main:


this code is only for testing purposes atm i dont really wanna use it for real until this little issue gets figured out.

Show me your combat algorithms(programmers read this NOT in a programming state of mind)
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 30th Jan 2010 12:52 Edited at: 30th Jan 2010 12:52
Pay attention to C++ language rules because there are several problems there. The vdOpenFileDialog is not closed with a bracket. It returns a value but it is still declared as void. The vdGetOpenFileDialog function tries to return a string type when it should return a char pointer (szFile is a char array which is not an std::string and in any case you have to give a char pointer to the constructor of the stream. Finally, this is not really the proper way to use a header file. Although technically you can put everything in a header and maybe it will compile, but a header should contain only declarations, function headers, constants - but no variables and no function bodies. The point in separating the program into several modules is that the implementation details of a module should be self-contained and hidden from the other modules that use it.

Here is an improved version with header. I made some more changes - suggestions only, you can accept it or not. You have two functions for the open file dialog but one of them is only one line, so I combined these into one function. That function returns a success flag, and expects the calling function to provide the character buffer as a parameter. The advantage is that you can easily check if the user clicked OK or Cancel in the dialog box, which would be more difficult to check if the function returns only the buffer. You can see the handling of the return flag in the main program.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-10-01 23:28:54
Your offset time is: 2024-10-01 23:28:54