PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Using File Open Common Dialog with GapiDraw

From looking around, it appears all you need to do is call GetOpenFileName() to display a standard File Open Common Dialog. However, when I call that, nothing happens. Is there something more I need to do? Here is the current code:
Code:

m_display.SuspendDisplay();
OPENFILENAME lpOfn;
lpOfn.lpstrFilter = TEXT("Data File (*.dat)\0*.dat\0");
lpOfn.hwndOwner = GetForegroundWindow();
GetOpenFileName(&lpOfn);
m_display.ResumeDisplay();
Nevermind, I figured it out. Just for everybody's knowledge, I had to insert the following lines:
Code:

memset(&lpOfn, 0, sizeof(lpOfn));
lpOfn.lStructSize = sizeof(OPENFILENAME);


So it ended up looking like:
Code:

m_display.SuspendDisplay();
OPENFILENAME lpOfn;
memset(&lpOfn, 0, sizeof(lpOfn));
lpOfn.lStructSize = sizeof(OPENFILENAME);
lpOfn.lpstrFilter = TEXT("Data File (*.dat)\0*.dat\0");
lpOfn.hwndOwner = GetForegroundWindow();
GetOpenFileName(&lpOfn);
m_display.ResumeDisplay();


Not sure if the SuspendDisplay and Resume Display calls are neccesary. I'll play around with it.
Using GD 2.0.4 I am unable to get the open file dialog to display (using code from above post)

It works on the PC but on the device it never shows (I am not calling suspend or resume because I don't know where or how to do that in 2.0.4)

any help would be much appreciated!
By the way - I added a m_display.Suspend() in ProcessNextFrame but it does not seem to make a difference - I can't tell if the dialog comes up at all...
OK - finally figured it out... suspend and resume are not needed

The problem is that I didn't setup the struct correctly. Once I did it worked. The big one is to populate lpstrFile and nMaxFile

if anyone is curious (some of these may not need to be set initially but I wanted to make sure I was covered)

Code:

TCHAR szBuffer[_MAX_PATH];
OPENFILENAME lpOfn;

memset(&lpOfn, 0, sizeof(OPENFILENAME));
szBuffer[0] = '\0';
lpOfn.lStructSize = sizeof(OPENFILENAME);
lpOfn.lpstrFile = szBuffer;
lpOfn.nMaxFile = _MAX_PATH;
lpOfn.lpstrFilter = TEXT("Image files (*.jpg,*.bmp,*.png,*.gif)\0*.jpg;*.bmp;*.png;*.gif\0All Files (*.*)\0*.*\0");
lpOfn.nFilterIndex = 1;
lpOfn.lpstrInitialDir = NULL;
lpOfn.lpstrTitle = NULL;
lpOfn.lpstrFileTitle = NULL;
lpOfn.hwndOwner = GetForegroundWindow();
lpOfn.Flags = OFN_FILEMUSTEXIST;

if (GetOpenFileName(&lpOfn) != 0)
{
if FAILED(image.CreateSurface(0,lpOfn.lpstrFile))
{
return GDERR_BITMAPNOTFOUND;
}
}
I just wanted to add that Suspend/Resume display might be needed for some devices (especially double buffered ones). So it is recommended that you use them...
Thanks Johan - where is the best place to call Suspend / Resume? Is processnextframe OK or is there a better function?

<sorry I just started using GapiDraw 2 days ago so I'm still feeling around the lib>

thanks