im trying to figure out this open file dialog but im having issues, heres my source:
#include "DarkGDK.h"
#include <fstream>
using namespace std;
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle
void vdOpenFileDialog()
{
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "Text-File\0*.txt\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE)
hf = CreateFile(ofn.lpstrFile,
GENERIC_READ,
0,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
}
char* vdGetOpenFileDialog()
{
return szFile;
}
// the main entry point for the application is this function
void DarkGDK ( void )
{
vdOpenFileDialog();
char buffer[256];
ifstream file(vdGetOpenFileDialog());
file>>buffer;
dbText(1,1,buffer);
file.close();
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
// our main loop
while ( LoopGDK ( ) )
{
// update the screen
dbSync ( );
}
// return back to windows
return;
}
and the file im trying to open:
#include "DarkGDK.h"
#include "fstream"
#include "sstream"
using namespace std;
//function initializations
void pasteSPR(int id, int x, int y, int img);
void grabSCRN(int id, int x1, int y1, int x2, int y2);
void draw_grid();
//global variables
int mouse[2];
int oldmouse[2];
int click_state;
char buffer[128];
int fps;
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
//initialize images
dbLoadImage("Media/Other/back.JPG",1);
dbPasteImage(1,1,1);
dbLoadImage("Media/Other/tbar.JPG",2);
dbPasteImage(2,1,1);
dbLoadImage("Media/Icons/tiles.PNG",3);
dbLoadImage("Media/Other/dot.PNG",4);
dbSprite(4,mouse[0],mouse[1],4);
dbSprite(5,0,0,4);
dbHideSprite(5);
dbSetSpriteFrame(5,0);
//create tileset markers
int counter=1;
ofstream file("file.txt");
while(counter!=301)
{
dbCreateAnimatedSprite(counter+4,"Media/Icons/tiles.PNG",2,1,3);
file<<counter;
file<<" ";
counter++;
}
file<<counter;
file.close();
//position sprites initially
draw_grid();
// our main loop
while ( LoopGDK ( ) )
{
//move pointer
dbSprite(4,mouse[0],mouse[1],4);
//update mouse variables
oldmouse[0]=mouse[0];
oldmouse[1]=mouse[1];
mouse[0]=dbMouseX();
mouse[1]=dbMouseY();
//redraw grid
draw_grid();
//set title to the current fps and refresh
fps=dbScreenFPS();
sprintf_s(buffer,sizeof(buffer),"FPS: %i Mouse X: %i Mouse Y: %i Current hit: %i" , fps ,mouse[0],mouse[1],dbSpriteHit(4,0));
dbSetWindowTitle(buffer);
// update the screen
dbSync ( );
}
// return back to windows
return;
}
//function declarations
void pasteSPR(int id, int x, int y, int img)
{
dbSprite(id,x,y,img);
dbPasteSprite(id,x,y);
dbDeleteSprite(id);
}
void grabSCRN(int id, int x1, int y1, int x2, int y2)
{
dbGetImage(id,x1,y1,x2,y2);
dbPasteImage(id,x1,y1);
dbDeleteImage(id);
}
void draw_grid()
{
int x=0;
int y=1;
int counter=1;
ofstream file3("file3.txt");
while(y!=15)
{
dbSprite(counter+4,x*16+150,y*16+25,3);
dbSetSpriteFrame(counter+4,0);
file3<<"1: ID:"<<x*y+4<<"\n X_pos: "<<x*16+150<<"\n Y_pos: "<<y*16+25<<"\n X: "<<x<<"\n Y: "<<y<<"\n\n";
if(x==20)
{
x=0;
y++;
}
else
{
x++;
}
counter++;
}
file3.close();
}
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)