MiniGUI API Reference (MiniGUI-Threads)  v5.0.6
A mature and proven cross-platform GUI system for embedded and smart IoT devices
Functions

You know that we can post or send a message to other windows which may run in another thread under MiniGUI-Threads. The MiniGUI messaging functions such as PostMessage(), SendMessage(), SendNotifyMessage(), and the window callback procedure provide a flexible, efficient, safe, and easy-to-use data transfer and synchronization mechanism for your multithreaded applications. More...

Functions

MG_EXPORT BOOL GUIAPI GetThreadByWindow (HWND hWnd, pthread_t *thread)
 Get the thread identifier which a window belongs to. More...
 
MG_EXPORT BOOL GUIAPI IsWindowInThisThread (HWND hWnd)
 Determine whether a window was created in this thread. More...
 
MG_EXPORT BOOL GUIAPI VirtualWindowCleanup (HWND hVirtWnd)
 Cleanup the system resource associated with a virtual window. More...
 
MG_EXPORT HWND GUIAPI CreateVirtualWindow (HWND hHosting, WNDPROC WndProc, const char *spCaption, LINT id, DWORD dwAddData)
 Create a virtual window. More...
 
MG_EXPORT BOOL GUIAPI DestroyVirtualWindow (HWND hWnd)
 Destroy a virtual window. More...
 

Detailed Description

You know that we can post or send a message to other windows which may run in another thread under MiniGUI-Threads. The MiniGUI messaging functions such as PostMessage(), SendMessage(), SendNotifyMessage(), and the window callback procedure provide a flexible, efficient, safe, and easy-to-use data transfer and synchronization mechanism for your multithreaded applications.

For example, you can send or post a message to a window from a general purpose thread which may download a file from the remote server under MiniGUI-Threads.

But can we use the MiniGUI messaging mechanism under MiniGUI-Processes and MiniGUI-Standalone runtime modes for multithreading purpose? For example, we may download a file in a general thread and inform a window when the file is ready.

Furthermore, if we want to use the MiniGUI messaging mechanism in a general thread to handle messages from other threads, how to do this?

The virtual window provides a solution for the requirements above. A virtual window is a special window object which does not have a visible window area. But after you create a virtual window in a different thread, you can use the MiniGUI messaging mechanism to post or send messages between the current main window thread and the new thread.

In MiniGUI, we call a thread creating a main window as a GUI thread, and a thread creating a virtual window as a message thread.

It is important to know the following key points about virtual window:

A virtual window will get the following system messages in its life life-cycle:

The following functions work for a virtual window:

Since 5.0.0.

Function Documentation

◆ CreateVirtualWindow()

HWND GUIAPI CreateVirtualWindow ( HWND  hHosting,
WNDPROC  WndProc,
const char *  spCaption,
LINT  id,
DWORD  dwAddData 
)

Create a virtual window.

This function creates a virtual window for the purpose of multi-thread messaging.

Parameters
hHostingThe hosting virutal window.
WndProcThe window callback procedure.
spCaptionThe caption of the virtual window.
idThe long integer (pointer size) identifier of the virtual window.
dwAddDataThe additional data for the window.
Returns
The handle to the new virtual window; HWND_INVALID indicates an error.
See also
VirtualWindowCleanup

Example:

/*
* The following code creates a virtual window.
*/
static LRESULT
my_virt_wnd_proc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
switch (message) {
...
}
return DefaultVirtualWinProc (hwnd, message, wparam, lparam);
}
...
HWND new_wnd = CreateVirtualWindow (HWND_NULL, my_virt_wnd_proc,
"A Virtual Window", 0, 0);
if (new_wnd != HWND_INVALID) {
// failed to create the virtual window.
}
// go on...
...

Since 5.0.0.

◆ DestroyVirtualWindow()

BOOL GUIAPI DestroyVirtualWindow ( HWND  hWnd)

Destroy a virtual window.

This function destroys a virtual window.

Parameters
hWndThe handle to the virtual window.
Returns
TRUE on success, FALSE on error.
See also
VirtualWindowCleanup

Example:

/*
* The following code creates a virtual window.
*/
static LRESULT
my_virt_wnd_proc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
switch (message) {
...
}
return DefaultVirtualWinProc (hwnd, message, wparam, lparam);
}
...
HWND new_wnd = CreateVirtualWindow (HWND_NULL, my_virt_wnd_proc,
"A Virtual Window", 0, 0);
if (new_wnd != HWND_INVALID) {
// failed to create the virtual window.
}
// go on...
...

Since 5.0.0.

◆ GetThreadByWindow()

BOOL GUIAPI GetThreadByWindow ( HWND  hWnd,
pthread_t *  thread 
)

Get the thread identifier which a window belongs to.

Parameters
hWndThe handle to a window, which may be a main window, virtual window, or a control.
threadThe buffer to store the thread identifier.
Returns
TRUE on success, otherwise FALSE.

Since 5.0.0

◆ IsWindowInThisThread()

BOOL GUIAPI IsWindowInThisThread ( HWND  hWnd)

Determine whether a window was created in this thread.

Parameters
hWndThe handle to a window, which may be a main window, virtual window, or a control.
Returns
TRUE on success, otherwise FALSE.

Since 5.0.0

◆ VirtualWindowCleanup()

BOOL GUIAPI VirtualWindowCleanup ( HWND  hVirtWnd)

Cleanup the system resource associated with a virtual window.

This function cleans up the system resource such as the message queue associated with the virual window hVirtWnd. DestroyVirtualWindow does not destroy all resource used by the virtual window, therefore, you should call this function after calling DestroyVirtualWindow and skipping out from the message loop. After calling this function, the virtual window object will be destroyed actually.

Parameters
hVirtWndThe handle to the virtual window.
Returns
TRUE on success, otherwise FALSE.
See also
DestroyVirtualWindow

Since 5.0.0

HWND
GHANDLE HWND
Handle to main window or control.
Definition: common.h:407
WPARAM
UINT_PTR WPARAM
A type definition for the first message paramter.
Definition: common.h:706
LRESULT
LONG_PTR LRESULT
Signed result of message processing.
Definition: common.h:583
UINT
unsigned int UINT
A type definition for unsigned integer.
Definition: common.h:664
HWND_INVALID
#define HWND_INVALID
Invalid window handle.
Definition: window.h:6754
HWND_NULL
#define HWND_NULL
Null window handle.
Definition: window.h:6748
LPARAM
UINT_PTR LPARAM
A type definition for the second message paramter.
Definition: common.h:712
CreateVirtualWindow
MG_EXPORT HWND GUIAPI CreateVirtualWindow(HWND hHosting, WNDPROC WndProc, const char *spCaption, LINT id, DWORD dwAddData)
Create a virtual window.
DefaultVirtualWinProc
#define DefaultVirtualWinProc
The default window callback procedure for virtual windows.
Definition: window.h:7432