Wednesday, May 23rd 2018, 1:23am UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.



Date of registration: Jul 15th 2014

Posts: 11


Wednesday, August 3rd 2016, 4:19am

Drawing in Windows / Widget

I've been trying to understand how to draw something in a window. I have a STM32F746G-Disco board and started with the STemWin Hello World example. Currently I have used the GUIBuilder to create a Window and inside that window are some images. Which creates this:

C/C++ Source code

WM_HWIN CreateWindow(void);
WM_HWIN CreateWindow(void) {
  WM_HWIN hWin;

  hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  return hWin;

Along with the associated callback function _cbDialog to initiate and "set" the images, which displays correctly.

I have also implemented touch and would like for some actions to happen when they are pressed, so I have added

C/C++ Source code


in my switch case statement for the callback _cbDialog, similar to how a button works. This works for manipulating the images that already exists in the window (redrawing them, set to top, etc).

I now would like to draw a line, or display text. This is where it gets fuzzy for me. Looking at the manual and searches on the forum, it seems I should add the WM_PAINT case to the callback and call a draw function in there. So I try

C/C++ Source code

	case WM_PAINT:
    	GUI_DispStringAt("Hello world",0,0);

but it does not get displayed.

I have looked at: Drawing over widgets , Paint text on top of all existing dialog windows , and Cannot execute line drawing functions in any other window other than the Desktop Window. . I have read through the manual and have not been able to find my answer.

When debugging, I see that it is getting to the WM_NOTIFICATION_CLICKED and WM_PAINT, so they are being reached.

Is there any examples that show how to properly implement this?

Thank you,



Date of registration: Jul 15th 2014

Posts: 11


Wednesday, August 3rd 2016, 7:40pm

From my testing and reading through of the manual I have found that there is one primary window and then any other window created after that summarized (by me) here:

Possible Windows:
1. Background / Desktop Window (WM_HBKWIN)
  • a. This is where any text or 2D graphics draw functions will be normally drawn
  • b. The z-position of this window cannot be changed
2. Any Window / Widget created
  • a. All Windows have a z-position that is stacked in the order of creation
  • b. All Windows can have children, which also are given a z-position stacked in the order of creation
  • c. The z-position can be manipulated by WM_* functions, such as WM_BringToTop()
  • d. The GUIBuilder uses a Dialog Box for a Window that has Widget(s) as children

Therefore what that means is that any draw functions that want to be used with a Widget / Window, needs to be called inside the case WM_PAINT of a widgets callback function (Note 1), which will be clipped by the window's / widget's defined area, otherwise it will get drawn on the Background / Desktop Window and has a change to be drawn over top of.

Can you verify if these assumption / findings are correct?

It then seems to be possible to create a transparent Window that has been brought to the front in order to draw on the most top layer, but I will need to verify this.

Note1: Refer to STemwin528, page 435 17.8 example for assigning a callback function

This post has been edited 3 times, last edit by "amorganPD" (Aug 3rd 2016, 7:42pm)

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 584


Monday, August 8th 2016, 11:48am

Hi amorgan,

Your assumptions are correct.

I have attached a quick sample which should show how to draw in a window.
Drawing into the 'main window' of the dialog and into a window created as child of this dialog.

SEGGER - Schoenen has attached the following file: