tags:

views:

101

answers:

3

Hi!

This is my first my MFC application, and unfortunately i don't understand, how it works. I found a simple MFC application, which gets the file list of a given path. I modifyed this code for my needs, but now i have one problem. What my application should do is the following. It reads two drive letters from a file. Then gets the file list for both drives, and then compares them. If the primary drive has files which aren't on the secondary drive then it copies it automatically. I did all this, but now i want my application to run without user interacting.It should just show the data. Unfortunately, the original MFC application started when i pressed a button. I want to takes this out, that i shouldn't press any buttons, it just copies the new files automatically. So my problem is the following. Where should i call my function, so i don't need to press a button. I think i should call it in here:

BEGIN_MESSAGE_MAP(CGetFileListDlg, CDialog)  
ON_WM_PAINT()  
ON_WM_QUERYDRAGICON()  
//}}AFX_MSG_MAP  
ON_BN_CLICKED(IDC_BUTTON_GET_FILE_LIST, &CGetFileListDlg::OnBnClickedButtonGetFileList)  //this is the original  
//call my function here
END_MESSAGE_MAP() 

But i don't know, which event i should use. I made all my changes what i needed in CGetFileListDlg::OnBnClickedButtonGetFileList() function, so this is why i want to call it. I don't know if this is important or not, but during the copying i want to show which file am i currently copying.

Please someone help me!

Thanks in advance!

kampi

+1  A: 

Look for the overrides panel when you are in the code file for your dialog. Add an entry for OnInitDialog. Put all of your file processing code in there if you really want it to execute once the dialog is initialized.

Dave
Hi! If i paste my code in OnInitDialog, then it works almost fine, but then the window doesn't appear until the copying hasn't finished. If the copying is done, only then appears my window. Should i create another function only for copy and call that from anywhere else?
kampi
+1  A: 

You should move all your file processing into its own method then you can call that method from wherever you need to.

The benefit of this would be that you can test the code now by calling the method when the button is pressed and then once you are happy that the new method is working correctly you can call it from OnInitDialog or anywhere else that seems appropriate.

mfdoran
he already stated that his code for file processing is in a separate function. **EDIT** ack, he actually mentioned the function name later on, I just saw that. and it's the button handler. whoops!
Dave
+1  A: 

You can simulate a button click for your button within the OnInitDialog() function (just before return TRUE;):

PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_GET_FILE_LIST, BN_CLICKED), 0);

Note: You may need to call UpdateWindow() on your button handler in order to have the window refreshed.

djeidot
Hi!It is, maybe a dumm question, but where should i call the OnCreate() function? This is my first MFC application, so i don't understand much about what you said :( Could you mybe post some code, so i can understand it?
kampi
relevant code added.
djeidot
Hi! Thanks for your code, now i'm trying to understand. Your method is almost working fine, but now, i had comment out very much lines. This is (i think) because my function is called before the window has been created, and so i can't print the lines, what i want. But if i could print, then i wouldn't see anything, because when tge window is created, the copying has been finished. Am i right? I'm just guessing. Do you know a way call my function, after the window has been created? Thanks again!
kampi
Hi. I did some tests and after all the WM_CREATE handler doesn't seem to work. I've posted an alternative answer now. Hope it works.
djeidot
Hi! Man, you are a genius! I can't believe that this is that much simple. I looked for a solution since 3 days, but nobody gaves me a useable answer. Thanks! :) Now i have two more questions. 1.: if i switch to another windows like total commander, and then back to my application, then the window isn't refreshing any more. It shows the last copied file (but in the background it still works, just doesn't updates the window). 2: Is there an easy way, to show the percentage the currently copyied file? Thanks again!
kampi
Sorry, but i have one more question. Do you know why is that, that during the copying, i can't click in my ListBoxes?
kampi
Hi. I think you need to post those as separate questions, other people will be able to answer them better than me.
djeidot
Hi! Ok, i will do that. Thanks for your help!
kampi