This question already has answers here:
How do I update a progress bar in Cocoa during a long running loop?
(4 answers)
Closed 1 year ago.
I'm new to MacOS programming. I'm using Objective-C with XIB interfaces to develop Mac Apps.
I'm making an app that zips and unzips files/folders. I've also implemented a progress bar to show the progress of the task.
But, when the user drops a big file to compress the app freezes, the progress window never gets displayed but the logs are working fine though.
I remember when I was using wxWidgets, in a case like that I'd have to use wxYield() to process the events and update the ui and everything would be fine.
So, what's the way to do this thing on Cocoa?
I worked it using #Willeke's suggestions.
I'm executing the zip_close function on a different thread letting the main one handle the UI updates & events.
Also when the progress callback gets emitted, I'm updating the UI by accessing the main thread (making changes to the UI from another thread will give warnings).
Thank you both #Igor and #Willeke for helping out!
Related
I'm trying to prevent the app from being closed by clicking the Close box on the App Window.
For example, having a text editor with unsaved changes, upon pressing Close Box, I would first display, "Do you want to save changes before exiting?"
How can I detect app wanting to close and prevent that from happening?
I'm using C++, and this needs to be for Windows 10 Universal Apps UWP.
I already know how to do this for Win32.
The comments are correct. There is currently no way for a regular Store app to do this.
However, with the Creators Update (and corresponding SDK) we have included a preview API that you can now check out for this functionality:
The Windows.UI.Core.Preview.SystemNavigationManagerPreview class provides a CloseRequested event that an app can mark as handled. For the event to work the app will need to declare the restricted 'confirmAppClose' capability per:
https://learn.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations
Please let us know your feedback.
Thanks,
Stefan Wick - Windows Developer Platform
I just have a simple question, with a Windows Runtime Component (as in a library) that I am making how do I get the window object for the app? CoreWindow::GetForCurrentThread() throws an exception as it seems that the library runs in a different thread then the app. Any one know how to get the app window?
EDIT: GetForCurrentThread is not the problem, it seems that that it only works on the UI thread not a background thread, I would like a way to get at it from a background thread. Is it possible?
I think Window.Current is what you are looking for.
Hi I am currently writing a windows form application using visual studio 2010, the application I am writing needs to update labels on the form independent of any events happening - I know it is possible to update the form using event handlers but this requires and event to happen to do something.
I am planning to to use some form of main loop to update the form constantly - I just do not know where to place such a loop? I think I've heard of something called the message loop, would it go there? Or would I have to create a separate thread to do so - and if I did create a separate thread , would I have problems accessing controls created in another thread?
Basically I am modelling an elevator system and need to update certain details about the elevator to the form constantly without any buttons being pressed , e.g current floor, going up down ect
I can post code if need be
You almost certainly want to do the background work in a worker thread. Have that worker thread send updated data to the main thread in a way that triggers an event. The main thread then updates the UI based on the updated data in reaction to the event you triggered.
I am currently working on a C++ application with QML files.
I would like to have start screen on my application for a few seconds, and then get my main page. But I can't find any information on a proper way to do so in QML, using a specific event or such :(
My question is: what would be the proper way to do so in QML? If there is non, how could I nicely get this working in C++.
Any help would be greatly appreciated
You can use Timer in QML and load the main screen when it is triggered.
This question already has answers here:
Why does closing a console that was started with AllocConsole cause my whole application to exit? Can I change this behavior?
(4 answers)
Closed 9 years ago.
I needed to be able to output to a console from my GUI-based app written in C++, so I chose to use the AttachConsole(ATTACH_PARENT_PROCESS) API and this code to do so. That method works great, except that when I start my GUI app from a command prompt window the GUI app starts just fine but when I close the command prompt window my GUI app is terminated (note, not closed, but terminated.) Is there any way to prevent this app termination?
You can prevent your application from closing when somebody closes the console window.
It involves calling SetConsoleCtrlHandler to set a HandlerRoutine that intercepts those events.
If you want the console window to close, but leave your app running, you might be able to call FreeConsole in your HandlerRoutine. If that doesn't work, then handle the message to prevent the console window from being destroyed, and set a flag or a timer that will cause your app to call FreeConsole after returning from the handler.
As I recall, you can't prevent the window from closing when the user hits the X on the window. What I did to prevent that is modify the window menu. See http://blog.mischel.com/2008/07/14/going-too-far-back/ for some details.
I was able to resolve this issue by attaching to the parent console right before posting the text to the stdout stream and then by detaching from it. This way the text is posted alright and the console remains separate from my GUI app.
Here's the MFC/C++ class with the full implementation for those who want to use it.