Menu

Win32 API programming

2007-12-17
2012-09-26
  • Yamil Taler

    Yamil Taler - 2007-12-17

    Hi everybody!
    I'm starting with c++ programing using the API of windows, and i have some questions. I hope that you will help me. Thanks a lot for your time.
    1) I wrote a program using API. The program is continuosly monitoring a folder, and if a file appear, run a task.
    The problem begin when the window lost the focus, because the program wait that i' give back the focus. I try detecting the WA_INACTIVE message, but if i call a function under a while loop the program hangup, i think becouse never back to be active or never detect that the focus come back.
    Now, the question is: is rigth my idea? or i should be use multi-thread processing?
    In the case of using multi-thread processing, do you know where i can find information about of this? The solution of the problem could be: to create two threads?
    Further than this, i don't know how to create/manipulate threads!!!! :)
    Again, thanks a lot for your time, and sorry for my english of beginner.

     
    • cpns

      cpns - 2007-12-17

      You are making this far more difficult that you need to (as well as making your program behave in an unusual, and to most users irritating manner).

      Now you could simply use a WM_TIMER event and poll the folder periodically, but even that is not necessary, the OS can be asked to notify your application whenever a particular file or folder has been changed:

      http://msdn2.microsoft.com/en-us/library/aa364417.aspx
      http://www.codeproject.com/file/DirCheck.asp

      Clifford

       
    • Yamil Taler

      Yamil Taler - 2007-12-23

      sorry for my ignorance, it was not my intention to be an irritant.
      Anyway already solved my problem: I created a thread that monitors the specified folder and find a file when it performs its task, and I communicate with the main application using sendmessage

       
      • cpns

        cpns - 2007-12-23

        I was not suggesting that either you or your post as an "irritant". I merely meant that if you wrote a program that continuously tried to grab the focus, or which sat in a loop hogging the processor wuthout yielding it would not 'play well' with other Windows applications and users would dislike it. I would check your process' CPU usage in Task Manager to make sure that it is not unnecessarily hogging the CPU just to perform this task. If using a separate thread a Sleep() call between checks would be a good idea to avoid excessive load. Of course if you do that you have gained little over using a WM_TIMER but added a lot of complexity.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.