|
Hi,
I am trying to use GetSaveFileNamePreview to show a preview of the selected AVI movie. When I call GetSaveFileNamePreview I see the typical explorer-style dialog but no control to preview the movie. Is there something special that I need to add to make this happen?
Here is a code snippet:
OPENFILENAME ofn;
DWORD dwWinMajor;
dwWinMajor = (DWORD)(LOBYTE(LOWORD(::GetVersion())));
::ZeroMemory(&ofn, sizeof(OPENFILENAME));
TCHAR szFile[MAX_PATH];
TCHAR szFileTitle[MAX_PATH];
::ZeroMemory(&ofn, sizeof(ofn));
_tcscpy(szFile, this->m_sFileName);
if((BYTE)dwWinMajor >= 5)
{
/*Add 12 bytes to OPENFILENAME on Win2K or greater*/
ofn.lStructSize = sizeof(OPENFILENAMEEX);
}
else
{
ofn.lStructSize = sizeof(OPENFILENAME);
}
ofn.hwndOwner = ::GetActiveWindow();
ofn.lpstrFile = szFile;
ofn.lpstrFilter = TEXT("AVI Files (*.avi)\0*.avi\0");
ofn.nMaxFile = (DWORD)_tcsclen(szFile);
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle);
ofn.lpstrInitialDir = NULL;
ofn.lpstrDefExt = TEXT(".avi");
ofn.lpstrTitle = TEXT("Save AVI Movie As");
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_OVERWRITEPROMPT;
if(::GetSaveFileNamePreview(&ofn) == TRUE)
{
/*Do something here*/
}
Thanks for your help,
Andy
|
|
|
|
|
Hi,
I'm trying to implement double buffering in my MFC application, but keep running into a (to me) strange problem. I've read through the article "drawing speed in GDI+", and been trying to follow the code from step 2 in this article. My code (see below) compiles, but when I execute my app, I get the "standard" windows dialog, which asks if I want to send an error report, and forces me to terminate the application.
Please remember that I'm a newbie, there are certanly much bad code below, I'm just asking for the error ...
My view is derived frow CScrollView. Does this have anything to do with anything?
<br />
<br />
CRect rect;<br />
GetClientRect(&rect);<br />
int nWidth = rect.right - rect.left +1;<br />
int nHeight = rect.bottom - rect.top + 1;<br />
<br />
CClientDC ClientDC(this);<br />
Graphics graphics(ClientDC.m_hDC);
<br />
#ifdef _DEBUG<br />
#undef new<br />
Bitmap* bmp = new Bitmap(nWidth,nHeight);<br />
#define new DEBUG_NEW<br />
#else<br />
Bitmap* bmp = new Bitmap(nWidth,nHeight);<br />
#endif<br />
Graphics* graph = Graphics::FromImage(bmp);<br />
<br />
CRect area( 0, 0, 0, 0);<br />
<br />
area.SetRect( 8, 90, 814, 90);
DrawLine(&graphics, area, 1);<br />
<br />
<br />
Pen pen(Color(200,0,0, 50));<br />
for( int j=100; j<500;j = j + 5) {<br />
for (int i=100; i<500; i = i + 5) {<br />
area.SetRect( 110,110, j, i);<br />
<br />
DrawLine(&graphics, area, 1);<br />
<br />
}<br />
}<br />
<br />
graphics.DrawImage( bmp, 0,0, 600, 600);<br />
delete graph;<br />
delete bmp;<br />
<br />
This is my version of DrawLine
<br />
void CITPAXpertView::DrawLine(Graphics *pdc, CRect rect, int width)<br />
{<br />
CPoint where = GetDeviceScrollPosition();<br />
<br />
Pen penn(Color(0,0,0), REAL(width));<br />
<br />
pdc->DrawLine( &penn, rect.left - where.x, rect.top - where.y, rect.right - where.x, rect.bottom - where.y);<br />
}<br />
|
|
|
|
|
I try to reproduce your program. In MFC SDI application I added to following code to view OnDraw function:
void CGDITestView::OnDraw(CDC* pDC)
{
CGDITestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rect;
GetClientRect(&rect);
int nWidth = rect.right - rect.left +1;
int nHeight = rect.bottom - rect.top + 1;
CClientDC ClientDC(this);
// Graphics graphics(ClientDC.m_hDC); // GDI+ Stuff graph(ClientDC.m_hDC);
Graphics graphics(pDC->m_hDC); // GDI+ Stuff graph(ClientDC.m_hDC);
// Test for drawing with double buffering
// Bitmap* bmp = new Bitmap(nWidth,nHeight); and
// Bitmap* bmp(nWidth,nHeight); seems to give the same results...
#ifdef _DEBUG
#undef new
Bitmap* bmp = new Bitmap(nWidth,nHeight);
#define new DEBUG_NEW
#else
Bitmap* bmp = new Bitmap(nWidth,nHeight);
#endif
Graphics* graph = Graphics::FromImage(bmp);
CRect area( 0, 0, 0, 0);
// This works, no questions asked, but it's not double buffering
//area.SetRect( 8, 90, 814, 90); // Skillelinje som skiller elevdata fra resten av skjemaet
//DrawLine(&graphics, area, 1);
/* Test drawing to test double buffering */
// Takes about 10 seconds without double buffering
// Takes about xx seconds with double buffering
Pen pen(Color(200,0,0, 50));
for( int j=100; j<500;j = j + 5) {
for (int i=100; i<500; i = i + 5) {
area.SetRect( 110,110, j, i);
// This works.
//DrawLine(&graphics, area, 1);
// This line causes the crach, when commented out, the code does what it's supposed to do
graph->DrawLine(&pen, area.left, area.top, area.Width(), area.Height());
}
}
graphics.DrawImage( bmp, 0,0, 600, 600);
delete graph;
delete bmp;
/* End test drawing */
}
It works. From your post it is difficult to understand what happens. Please remove all lines which are not related to your problem, and post the whole function (including header).
>> I get the "standard" windows dialog, which asks if I want to send an error report.
To get more information run program in Debug congiguration, and use Go command instead of Run. In this case program breaks in Debugger and you can see what exactly happens.
|
|
|
|
|
<br />
void CITPAXpertView::OnDraw(CDC* )<br />
{<br />
CITPAXpertDoc* pDoc = GetDocument();<br />
ASSERT_VALID(pDoc);<br />
if (!pDoc)<br />
return;<br />
<br />
<br />
CRect rect;<br />
GetClientRect(&rect);<br />
int nWidth = rect.right - rect.left +1;<br />
int nHeight = rect.bottom - rect.top + 1;<br />
<br />
CClientDC ClientDC(this);<br />
Graphics graphics(ClientDC.m_hDC);
<br />
#ifdef _DEBUG<br />
#undef new<br />
Bitmap* bmp = new Bitmap(nWidth,nHeight);<br />
#define new DEBUG_NEW<br />
#else<br />
Bitmap* bmp = new Bitmap(nWidth,nHeight);<br />
#endif<br />
Graphics* graph = Graphics::FromImage(bmp);<br />
<br />
CRect area( 0, 0, 0, 0);<br />
<br />
<br />
Pen pen(Color(200,0,0, 50));<br />
for( int j=100; j<500;j = j + 5) {<br />
for (int i=100; i<500; i = i + 5) {<br />
area.SetRect( 110,110, j, i);<br />
}<br />
}<br />
graphics.DrawImage( bmp, 0,0, 600, 600);<br />
delete graph;<br />
delete bmp;<br />
<br />
}<br />
This is the function in question. As you can see, I've commented out both lines that draw in the view. If I use the first line, things work fine. If I use the second line, I get in trouble
The rest of the class is basically a standard CView class, except that I've made a few changes to change it to CScrollView. Things seem to be working fine, so I assume that I haven't missed anything, and the class is in fact a CScrollView class, but I might be wrong?
As in your test, the application is SDI.
Thanks, I really appreciate your efforts.
|
|
|
|
|
Please correct obvious error:
CClientDC ClientDC(this);
Graphics graphics(ClientDC.m_hDC);
replace with
Graphics graphics(pDC->m_hDC);
Uncomment pDC in the function header. I don't beleive this is a reason, but I want to be sure that all code is OK. If problem is not fixed, post here.
I want some other information: debug this function and be sure that after the lines:
Bitmap* bmp = new Bitmap(nWidth,nHeight);
Graphics* graph = Graphics::FromImage(bmp);
bmp and graph are not NULL.
|
|
|
|
|
Alex Farber wrote:
CClientDC ClientDC(this);
Graphics graphics(ClientDC.m_hDC);
replace with
Graphics graphics(pDC->m_hDC);
Ok, I've done this, and uncommented pDC in the header. The results are the same...
I sat a breakpoint at the line "CRect area(0,0,0,0);", and checked bmp and graph... I'm quite sure this is the problem, I just don't know what to do about it
bmp gave me 0x00000000.
graph gave me the status "0x00000000 {nativeGraphics=??? lastResult=??? }"
I might be misunderstanding these results, but I hope it's what you asked for. (Not quite used to using the debugger, you might say )
|
|
|
|
|
Bitmap is not created. Interesting, why. What are nWidth and nHeight values? Try this:
Bitmap* pMemBitmap = new Bitmap(nWidth, nHeight, PixelFormat24bppRGB );
|
|
|
|
|
nWidth are right-left+1 in the rect returned by GetClientRect, and the similar goes for nHeight.
Using another Pixel Format didn't help, unfortunately.
|
|
|
|
|
>> nWidth are right-left+1 in the rect returned by GetClientRect, and the similar goes for nHeight.
I know, I asked what are their values in debugger? 10, 100 etc.
|
|
|
|
|
Sorry, my bad
nHeight = 654
nWidth = 1023
However, VStudio marks these values in red. Any particular reason?
|
|
|
|
|
They are marked in red because they are used in current program line.
I really don't have idea what happens. The last thing I can suggest is to see the whole project. If you can make it available for download, post me link to it. Or you can e-mail it to me.
|
|
|
|
|
Yeah, "check"'s in the mail :P
|
|
|
|
|
Move GDI+ initialization code in InitInstance to the place before creating of main frame. Currently it is placed after creating and showing of main frame, and first time view is redrawn, GDI+ is not initialized.
By the way, I didn't know that CodeProject allows to post e-mail with attachments. Since you mahaged to do this, you get an answer immidiately.
|
|
|
|
|
Works, thanks!
About the e-mail: I don't quite understand. I simply found your e-mail from the mail I got with the alert connected to this thread, and sendt you a ordinary mail
Thanks for all help!
|
|
|
|
|
Hi,
I was hoping I could get you to look at another problem I've been having with this double buffering...
It's posted elsewhere on the forum: Thread.
Could you maybe take a look at it, and give it a shot?
|
|
|
|
|
Hi,
How could I get the begin and the end of the hibernate event (if exist) on WinXP ?
I have to know when the user start ("turn off" the machine) and finish ("turn on" the machine again) the hibernate process.
Thanks,
Cris.
|
|
|
|
|
You could try handling the WM_POWERBROADCAST message.
|
|
|
|
|
Hello,
Can anyone provide me some ideas or resources in order to read the .PSD file? I am more interest to know how can I read the layer information of in the .PSD file.
Thanks!
Nachi
|
|
|
|
|
Go here and search for the PSD format.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
is there a way to place a drop menu nexto and image
|
|
|
|
|
I have an MFC application that creates a WH_GETMESSAGE with a callback function in an external non-MFC DLL. It specifically monitors mouse and keyboard events. Event notifications are sent to my app with PostMessage from inside the DLL callback function. This in itself works perfectly. However, when I try to close the app, the app will crash or start to take up 100% cpu usage. If I right click the app in the task bar and choose close, I get 100% cpu usage, or if I then press 'C' for the 'Close' menu option, the app crashes. The X button will crash, double clicking the icon in the titlebar will exit without error, as will Alt-F4, and choosing Close from the system menu will crash.
It doesn't matter if I uninstall the hook in OnClose or not, because the DLL will cleanup on DLL_PROCESS_DETACH. I get the same result anyway.
I'm very confused, I have no idea what the problem is, its not consistant at all. I do know that if in the DLL I comment out the PostMessage lines in the event callback, there are no crashes or hangs at all. So I don't know if my app or dll is to blaim. Before the GetMesssage hook I had separate mouse and keyboard hooks, which didn't cause the CPU hang, but would occassionally crash.
Any suggestions?
Thanks!
-Aaron
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Maybe the dll shouldn't notify the application in case the application was closing? (infinite loop?)
Try unloading the dll from the application first
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
The problem is I want the DLL running the entire time the app is, without some sort of stop button being requried.
I was wondering if there may be an infinite loop, and I think you're right, that that was the problem. What I did is add a conditional to my hook callback that would only postmessage if the orginator of the message was not my window. And that works great! I don't really need the messages to be posted while they're in my app anyway.
Thanks!
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Aaron Stubbendieck wrote:
I have an MFC application that creates a WH_GETMESSAGE with a callback function in an external non-MFC DLL. It specifically monitors mouse and keyboard events. Event notifications are sent to my app with PostMessage from inside the DLL callback function.
Uh oh. That there is an infinite loop waiting to happen. Your app calls GetMessage(), which triggers your hook, which posts a message to your app, which calls GetMessage() to read it, which triggers your hook, which posts a message to your app...
See where that's gonna end up going?
You'll have to find some other way of notifying your app - look at shared memory or some other inter-process communication; messages won't work in this case.
I can't really explain why some cases didn't cause the crash, although it may be due to the "feature" of WH_GETMESSAGE hooks where messages retrieved via GetMessage() are processed by the hook, but messages retrieved with PeekMessage() are not. I never really understood why this was the case, but it's possible PeekMessage() may be being used for some of those cases.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Yeah, I eventually worked around that by not posting the message if it was from my app, that's as clean of a solution I could come up with. The odd thing is, that except when closing the app, there was no problem.
Thanks for the help on this thread and the other.
modified 12-Jul-20 21:01pm.
|
|
|
|
|