|
In my app I have generated some temporary files and when the app closes I need to promp the user to save the files with new names. Then I would like to delete these temporary files. I have found the function 'CDoc::OnCloseDocument' and called the 'CDocument::OnFileSaveAs();' function. This is all fine except that it comes up in what ever directory the temporary files are stored in. I don't want the user to put his/her files in the temporary directory.
I can't find any help on 'OnFileSaveAs', is this because I should not be using it?
Anyone know how to change the directory that 'OnFileSaveAs' starts in?
Or am I just going about this in the wrong way?
Any help appreciated, Regards Ali
ali p
|
|
|
|
|
Oh just read Nish's message about more info, so here it is...
Platform :- XP
Dev Tool :- VC++ 6.0
Libraries :- MFC
Cheers,
ali p
|
|
|
|
|
Hi, hope this helps. The Load & Save Dialogs are the same just put save insted of open. This code works as one chunk, lpstrInitialDir is the dir that it starts in to answer your question:
OPENFILENAME OpnFileStruct; // structure for GetOpenFileName
char szFile[256] = "\0";// Buffer for the filename
// Size of structure
OpnFileStruct.lStructSize = sizeof(OPENFILENAME);
// Handle to the parent window
OpnFileStruct.hwndOwner = this->GetSafeHwnd();
// Filters
OpnFileStruct.lpstrFilter = "GIF or JPEG Image\0*.gif;*.jpg";//"GIF Image\0*.gif\0JPEG Image\0*.jpg";
// Index for the filter
OpnFileStruct.nFilterIndex = 2;
// Buffer which will recieve filename
OpnFileStruct.lpstrFile = szFile;
// Size of buffer which will recieve filename
OpnFileStruct.nMaxFile = sizeof(szFile);
// Title of the open dialog
OpnFileStruct.lpstrTitle = "Select a Background Image";
// Flags
OpnFileStruct.Flags = OFN_FILEMUSTEXIST;
OpnFileStruct.hInstance = NULL;
OpnFileStruct.nFileOffset = 0;
OpnFileStruct.nFileExtension = 0;
OpnFileStruct.lpstrDefExt = NULL;
OpnFileStruct.lCustData = NULL;
OpnFileStruct.lpfnHook = NULL;
OpnFileStruct.lpTemplateName = NULL;
OpnFileStruct.lpstrFileTitle = NULL;
OpnFileStruct.nMaxFileTitle = 0;
OpnFileStruct.lpstrInitialDir = "C:\\media\\"; //!!!!! This wot u mean?
OpnFileStruct.lpstrCustomFilter = NULL;
OpnFileStruct.nMaxCustFilter = 0;
// Next line stops read only button showing & stops moving to selected dir
OpnFileStruct.Flags = OFN_NOCHANGEDIR|OFN_HIDEREADONLY;
// Show open dialog box
GetOpenFileName(&OpnFileStruct);
// Update the edit box with the selected file
m_Back_Image=szFile;
UpdateData(false);
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
Cheers, I tried this and it worked a treat. Its great, I can control the 'File Save As Dialog' now and so I have replaced the 'FileSaveAs' from the main menu with my own version.
As there is no help on the function and you have shown me that I can generate the dialog box myself, I wonder if I should have been calling 'CDocument::OnFileSaveAs' at all. I am relatively new to Visual C++ as you have probably guessed and I certainly find it very confusing.
Many Thanks for the great help,
ali p
|
|
|
|
|
CDocument::OnFileSaveAs is just the function that gets called when you click 'on' the 'Save As' button in the 'File' menu. CDocument is the Class that contains it. Im new too, you will pick it up, just keep trying
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
How should i load a DOM object in a MFC application?
I've tried with "add class...from a type library" and some classes are attempting to override the corresponding from msxml2.h. So, it doesn't work this way.
Wish for help!
rechi
|
|
|
|
|
There are multiple examples of this kind of thing available here on CodeProject. However, as in most things C++, the details are rarely easy. In general though:
#include "msxml.h"
#import "msxml3.dll" named_guids raw_interfaces_only
using namespace MSXML2;
IXMLDOMDocument *pDoc;
if ( SUCCEEDED (CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument, reinterpret_cast<void**>(&pDoc))))
{
//
// Tell the "doc" that we're not going to load asynchronously.
//
if ( SUCCEEDED(pDoc->put_async(VARIANT_FALSE)) )
{
CComVariant vFile(strFileName);
VARIANT_BOOL vBool;
pDoc->load(vFile,&vBool);
if ( vBool == VARIANT_TRUE )
{
IXMLDOMNode *pNode;
if ( SUCCEEDED(pDoc->QueryInterface(IID_IXMLDOMNode,
reinterpret_cast<void**>(&pNode))))
{
CTreeCtrl *pTree = static_cast<ctreectrl*>(GetDlgItem(IDC_XMLTREE));
HTREEITEM hItem = pTree->GetChildItem(TVI_ROOT);
while( hItem != NULL )
{
HTREEITEM hNext = pTree->GetNextSiblingItem(hItem);
pTree->DeleteItem(hItem);
hItem = hNext;
}
IterateChildNodes(pNode,pTree);
pNode->Release();
pNode = NULL;
}
}
else
CheckLoad(pDoc);
}
pDoc->Release();
pDoc = NULL;
}
|
|
|
|
|
Thanks!
And a question: is it allways the best to use "import", instead of creating the classes from a type library?
rechi
|
|
|
|
|
Using #import is the easiest way I know of to load a COM object. It's my preferred method. You can load the type library of the COM object you wish to load or the DLL itself (which will contain it's own type library anyway).
|
|
|
|
|
I'm writing a SDI application, which allows users to create models, and then save them. I've implemented most of the create functionalities, and I'm in the progress to working on saving the models.
The problem I'm having is that when I try to add a message handler for 'Save' or 'Save As' from the menu, they don't seem to work??? I mean, the program doesn't even go through those bits of code??? I've put messageboxes, and breakpoints at different places, but the program just never gets there??? I think, is because of some code the MFC wizard has put there, e.g, built in code when using the wizard to create the project.
For some strange reason, 'File Open' works fine???
Any help would be much appreciated
Robert
|
|
|
|
|
Could probably help you out but I'd need to see the code. I don't do well in generalities for these kinds of problems. Up to you.
mphilmon@pobox.com
|
|
|
|
|
hey yaar
in the OnCommand
u can filter your menu command by LOWORD(WPARAM)
all the menu commands will be go there....so try..
sofware behind everything...
Enjoy with the codes...
Renjith Pandalam
|
|
|
|
|
Hi,
Can ne body help me to write an application
which takes a shot from camera and save it
into a file on HDD..
Its a LG camera
Any links or nething that i can read
Sameer
|
|
|
|
|
There's a good example (several actually) in the DirectX 8.1 SDK (available from the MSDN Downloads).
Under Samples\Multimedia\DirectShow\Editing. It's called StillCap and illustrates movie and still capture.
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Hi,
Actually what i want is that in my application
whenever a user presses a button, the camera is
turned on.. takes a shot and saves that in a
JPG or BMP file and frees the resources..
This should be done w/o doing anything on the
screen
I've done it for a Motion (avi - timebased).. but how
to do it for a Shot
Please Help
Sameer
|
|
|
|
|
Then I guess you'll have to get your hands dirty and rip out the frame grabbing stuff and put it into your app.
Sorry, but I don't enough about video capture to help much. I just hacked the example I mentioned to get it to behave how I wanted (but I didn't change the video capture functionality).
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Hi everybody!
I need help to achieve a project at work.
My app is a MFC dialog based. I need to access variables and control between 3 modeless dialog. How can I do that. I've tried everything I know.
I have already a lot of work done in both 3 dialogs...
Let me explain what I've done.
- I have 3 templates : IDD_MainDlg , IDD_Dialog1 , IDD_Dialog2
- IDD_MainDlg's class is CMainDlg (Created with the wizard at startup...)
- IDD_Dialog1's class is CDialog1 and then IDD_Dialog2 is CDialog2.
- I've declared :
CDialog1 m_Dialog1;
CDialog2 m_Dialog2;
inside the CMainDlg header file.
- I've created :
m_Dialog1.Create(IDD_Dialog1,this);
m_Dialog2.Create(IDD_Dialog2,this);
m_Dialog1.ShowWindow(SW_SHOW);
m_Dialog2.ShowWindow(SW_SHOW);
inside the OnInitDialog() of CMainDlg;
Let say that I have a CSliderCtrl object called 'm_Slider' declared inside the CDialog2 header file. When I'm in CMainDlg, I can access this variable by typing m_Dialog2.m_Slider without problem or error. Where I'm confused is when I'm inside CDialog1 and want to access m_Slider.
This is the 'best one' of all codes I've tried :
CDialog2* pWnd;
CMainDlg pdlg;
pWnd = &pdlg.m_Dialog2;
pWnd->m_Slider.SetPos(0);
I always get an assertion error. When debugging it always say that there is no handle
_AFXCMN_INLINE void CSliderCtrl::SetPos(int nPos)
{ ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, TBM_SETPOS, TRUE, nPos); }
(m_hWnd is always 0x00000000 )
What can I do to get all the things working well ?!?!?!
I have a lot of data to pass between theses three dialogs so...
Best regards,
Brind
If coding looks like drugs... I should go on therapy...
|
|
|
|
|
You're code is not working because the window has not been created yet. Always keep in mind that just because you create an instance of an MFC class such as CDialog (or a derived class), the encapsulated window isn't actually there until you tell the class to create it.
With regards to communicating data between these various dialogs, there several ways to achieve this. If you're simply trying to get initialization data to one dialog from another, you can change the constructor to accept this information. Then in the dialog's constructor, you save this information in member variables and finally use it to init the dialog's controls in either the OnInitDialog or DoDataExchange function.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Hi Tom ,
I don't understand what you said when you tell that 'the encapsulated window isn't actually there until you tell the class to create it'. Is this because I create my window inside the main window or what? Would you supply me a small example that will point me in the right direction.
Also, my datas to be communicated aren't only to be passed at initialisation of the dialog, they are to be communicated all the time until I stop the app.
Im newbie in C++ so, there's a lot of thing that confuse me!!
Thanks,
Brind
If coding looks like drugs... I should go on therapy...
|
|
|
|
|
When you instantiate a CDialog, you don't have a window yet. You won't until you specifically tell the class to create its underlying window. In the case of a modal dialog this is done via DoModal. In the case of a modeless dialog, this is done via Create or CreateIndirect. In you situation, you're referring to controls on a dialog that haven't been created because their containing window (the dialog) hasn't been created. Therefore, you'll need to move that code using one of the techniques I described.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
What is this function used for?
No seriously, I have been playing around with CFtpConnection, specifically PutFile, and I have found that i need to specify exacly where the file should be placed on the server. I tried to use SetCurrentDirectory but to no avail. The functions returns success but when I just put the file name in PutFile it transfers it to the root. To me SetCurrentDirectory should let me put just the file name(no path) in PutFile.
So my question is. Am I doing it wrong and SetCurrentDirectory should work the way I want it to, or am I suck with PutFile with the Path\FileName.
Thanks in advance
***********************
Tony Fontenot
Recreational Solutions
tony@recsolutions.com
***********************
|
|
|
|
|
That's definitely strange because I've written a very basic FTP client and it works fine.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
It worked perfectly for me, you tried using GetCurrentDirectory and then set the path relatively with SetCurrentDirectory ? What was the error that GetLastError() reports ?
x = GetLastError();
Better put the variable x on the watch window with the modifier hr like this:
x,hr
what the error says ?
See this on this page for a basic ftp tool using wininet :
Some tips
Cheers,
Joao Vaz
Frustrated TCL programmer,good c++ programmer wannabe
|
|
|
|
|
Got it working thanks all
***********************
Tony Fontenot
Recreational Solutions
tony@recsolutions.com
***********************
|
|
|
|
|
how can i add Explorer's functions ,for example,the list view of the Explorer ,to my program?
i am coming quietly just as i am leaving quietly.
|
|
|
|