-
There's a funtion MainWindow::GetHWND in implementation::MainWindow.xmal.cpp. I want to use a button in HomePage.xmal to trigger the function to get the handle of MainWindow. But if the code is:
Method 1 occurred an error: A non static member reference must be relative to a specific object.
If I'm trying to instantiate the MainWindow class, method 2 occurred another error: Objects of abstract class type are not allowed.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Use a global flag solve the problem. |
Beta Was this translation helpful? Give feedback.
-
The thing to remember is that the default application class stores an instance of the main window. It stores this when the application is launched, during the OnLaunched handler. What this means is that it is always possible to use this to get an instance of the main window. By default, you should see the App class is similar to:
There are namespace differences, but this is the basic implementation. There is nothing stopping you adding a member function to retrieve the window instance.
This would just simply return window. You can then get your application instance using Application.Current:
From there, you can use as to get your main window and get the HWND. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much! Nice method for the question!
|
Beta Was this translation helpful? Give feedback.
Use a global flag solve the problem.