开发者

How to avoid using a button in an MFC application?

开发者 https://www.devze.com 2022-12-19 14:35 出处:网络
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,

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 follow开发者_如何学Pythoning. 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


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消