Problem Overview
When a pushbutton on a WinCC runtime screen is wired through a direct connection to a binary tag in the automation system (AS), a single accidental click can write a 1 to the motor-start bit. For safety-critical actuators (motors, valves, heaters, conveyors), this one-click behavior is unacceptable. The standard mitigation is a confirmation prompt that requires the operator to explicitly acknowledge the action before the tag is written.
Two implementation paths exist in WinCC:
- A Win32
MessageBox()call from a C script bound to a mouse event (quick to deploy, but officially discouraged by Siemens). - A native WinCC picture-window dialog using two buttons bound to internal tags and a visibility animation (recommended by Siemens for production systems).
This article documents both paths, the exact C code, the API flags involved, the tag wiring, and the commissioning checks required for a motor-start confirmation in WinCC V7.x / TIA WinCC Comfort/Advanced.
Prerequisites
| Requirement | Detail |
|---|---|
| WinCC version | WinCC V7.0 SP3 or later, or WinCC Professional / Comfort / Advanced V13+ (TIA Portal) |
| Tag in AS | Binary tag (BOOL) wired to the motor-start coil, e.g. Motor1_Start (DB10.DBX0.0) |
| WinCC tag | Same BOOL tag, same name, not an internal tag — must be an external tag on the configured AS connection (S7 PROTOCOL SUITE / TCP/IP) |
| Project rights | Local administrator on the engineering station to compile and run the runtime; "C script" scripting rights enabled in User Administrator (WinCC V7) |
| Editor | Graphics Designer (WinCC V7) or HMI screen editor (TIA Portal) |
Option A — Win32 MessageBox C Script (Quick Deployment)
The original solution in the field report uses the Win32 API MessageBox() directly from a WinCC C action. It is compact, requires no extra screen objects, and is sufficient for non-safety HMI prototypes.
MessageBox API flags used
| Flag | Value | Effect |
|---|---|---|
MB_OKCANCEL |
0x00000001 | Renders two buttons: OK and Cancel |
MB_ICONEXCLAMATION |
0x00000030 | Displays the yellow warning icon |
MB_SETFOREGROUND |
0x00010000 | Forces the dialog to the foreground so it cannot be hidden behind the runtime window |
MB_SYSTEMMODAL |
0x00001000 | Modal to the entire system; operator cannot interact with the runtime until the dialog is closed |
Return values: 1 = IDOK (OK pressed), 2 = IDCANCEL (Cancel pressed / dialog closed).
Reference C script
// Event-bound C action on a button "Mouse click" event
// Tags used:
// YOUR_TAG_NAME - BOOL, external WinCC tag connected to the motor-start bit
#pragma code("kernel32.dll")
#pragma code("user32.dll")
#include <windows.h>
if (MessageBox(NULL,
L"Are you sure you want to START Motor 1 ?",
L"Confirm Motor Start",
MB_OKCANCEL | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_SYSTEMMODAL) == 1)
{
BOOL temp;
temp = GetTagBit("YOUR_TAG_NAME");
if (temp == TRUE)
{
SetTagBit("YOUR_TAG_NAME", 0);
}
else
{
SetTagBit("YOUR_TAG_NAME", 1);
}
}
Step-by-step wiring (WinCC V7 Graphics Designer)
- Open the screen containing the motor-start button.
- Right-click the button → Properties → Events → Mouse → Click.
- Right-click the action symbol → C action….
- Paste the script above, replacing
YOUR_TAG_NAMEwith the exact WinCC tag name (case-sensitive). - Compile with Ctrl+F7. The status bar must show 0 errors, 0 warnings.
- Save the picture and trigger a full RT build (Start → WinCC Runtime).
Step-by-step wiring (TIA Portal WinCC)
- Open the HMI screen, select the button.
- In the Inspector → Events → Click, add a function list or call a script.
- For a global C script, declare the function in the Scripts editor and call it from the event.
- For an inline VBS alternative, use
HMIRuntime.Tags("YOUR_TAG_NAME")instead ofGetTagBit/SetTagBit.
Why Siemens Officially Discourages MessageBox in WinCC
Siemens KB entry ID 22906363 states that MessageBox calls from WinCC are not recommended for production runtime. The technical reasons are:
- Language dependency: The literal text is hard-coded in the script; it cannot be translated through WinCC's Text Library or Text Distributor.
-
Modal blocking:
MB_SYSTEMMODALcan freeze the runtime if the dialog is dismissed abnormally (e.g., remote desktop disconnect, focus loss). -
Audit trail gap: The WinCC Audit option cannot log who clicked OK versus Cancel inside a
MessageBoxbecause the click happens in a non-WinCC window. - Redundancy / WebUX: Modal Win32 dialogs are unsupported in WinCC/WebUX and WinCC/Server redundant pairs.
-
Siemens support position: Errors that originate from a Win32
MessageBoxin a C action are classified as customer code, not as a WinCC bug.
Option B — Native WinCC Confirmation Picture (Recommended)
A native dialog is built from standard WinCC picture objects: a picture window containing two buttons (Yes / No), a text field, and an optional warning icon. Visibility is driven by an internal tag triggered on the first button click.
Required tags
| Name | Type | Source | Purpose |
|---|---|---|---|
Motor1_Start |
BOOL, external | AS connection | Actual start bit to the PLC |
Confirm_Req |
BOOL, internal | WinCC internal | Set to 1 by the screen button to open the dialog |
Confirm_Result |
BOOL, internal | WinCC internal | Set to 1 by "Yes", set to 0 by "No" / timeout |
Screen construction
- Create a picture window named
PW_Confirm, configurable size (e.g. 400×200 px), centered, with a "Close on losing focus" option disabled. - Inside the picture window, place a static text "Confirm Motor 1 start?", a Yes button, and a No button.
- Bind the Visible property of the picture window to the tag
Confirm_Reqwith a Dynamic dialog (range 0/1) or, in TIA, an Animation → Visibility linked to the same tag. - On the Yes button Click event, use a direct connection:
Tag:Motor1_Start= 1
Tag:Confirm_Req= 0
This writes the start bit and closes the dialog in one action. - On the No button Click event, direct connection:
Confirm_Req= 0.
On the original start button (C action or direct connection)
// On Click of "Start Motor 1" button — C action
SetTagBit("Confirm_Req", 1); // open confirmation dialog
SetTagBit("Motor1_Start", 0); // ensure bit is low until Yes is pressed
This sequence is critical: resetting Motor1_Start to 0 at the moment the dialog opens prevents a race condition where the PLC sees a stale 1 from a previous operation.
Why this is safer than Option A
- All text is in the WinCC Text Library → translatable.
- The click event is logged by the WinCC Audit option if licensed.
- Visibility, position, and styling are part of the picture; consistent across themes.
- Works on WinCC/WebUX, WinCC/Client, and redundant servers.
- No
kernel32.dll/user32.dlldependency — fully supported runtime.
Tag Configuration Reference
| Parameter | Option A | Option B |
|---|---|---|
| Motor start tag type | External BOOL on S7 connection | External BOOL on S7 connection |
| Confirmation trigger | Implicit (in C script) | Internal BOOL Confirm_Req
|
| Configuration cycle | 500 ms typical (acquisition cycle of the C action) | Same as picture window update cycle (250–500 ms) |
| Acquisition mode | Cyclic on tag change | Cyclic on tag change |
| Limit values | Not required | Limit values on Confirm_Req optional, for color animation |
Direct Connection vs. C Action — When to Use Which
| Aspect | Direct Connection | C Action / VBS |
|---|---|---|
| Deployment effort | Lowest (no code) | Moderate (script + compile) |
| Conditional logic | None — always executes | Full conditional logic (IF / CASE / loops) |
| Confirmation dialog | Requires 2 tags (Option B) | Can do both in one script (Option A) |
| Audit support | Yes (built-in) | Only with manual API call to AUDIT.dll |
| Performance (200 tags/sec target) | Excellent | Good if compiled, poor if interpreted |
Verification and Commissioning Steps
- Compile check: Trigger a full project recompile in WinCC Explorer. Read the Diagnostics window; no syntax errors allowed.
-
Tag simulation: In WinCC Graphics Designer, switch to Runtime with simulation mode and use the tag simulator to force
Motor1_Startto 0. -
Click test — Cancel path: Click the start button. The dialog must appear. Click "Cancel". Verify in the tag simulator that
Motor1_Startis still 0 and the PLC diagnostic buffer shows no write toDB10.DBX0.0. -
Click test — OK path: Click the start button, then "Yes". Verify
Motor1_Start= 1 for the configured pulse time, and that the AS logic starts the motor. - Re-click test: While the dialog is open, click anywhere on the runtime outside the dialog. The dialog must remain modal (Option A) or simply stay visible (Option B). Background clicks must not write to the tag.
- Power-cycle test: Restart WinCC Runtime while the motor is running. Confirm that the start tag defaults to 0 and that the operator must re-confirm to restart.
-
Multi-client test (Option A only): Open the same screen on a second WebUX client.
MessageBoxon client 1 must not block client 2, and vice versa. If it does, the deployment is not scalable to a multi-client setup — switch to Option B.
Troubleshooting Matrix
| Symptom | Likely cause | Remedy |
|---|---|---|
| MessageBox never appears | C action not bound to Click event, only to "Mouse down" | Bind to Click event, not Press |
| MessageBox appears but tag never writes | Tag is internal, not external on AS connection | Check PLC tag connection in Tag Management |
| Tag writes regardless of Cancel | Direct connection on the button is still present and overrides the C action | Remove the direct connection; the C action owns the event |
| MessageBox hidden behind runtime | Missing MB_SETFOREGROUND
|
Add the flag as shown in the script |
| Compile error: "GetTagBit undefined" | Script runs in the wrong trigger type (e.g. "On timer" without global definitions) | Move script to a named C function or use the legacy apdefap.h include |
| Dialog blocks remote desktop sessions |
MB_SYSTEMMODAL in RDP session |
Use Option B for RDP / WebUX deployments |
| Yes button does not start motor (Option B) | PLC expects a rising edge, not a level | Either toggle the bit from a separate C action, or change AS logic to scan for rising edge on Motor1_Start
|
| Picture window never closes | Visibility tag Confirm_Req not reset |
Add the Confirm_Req = 0 direct connection on the Yes button |
Edge Cases and Field-Proven Caveats
- Edge case — operator double-clicks: A double-click on the start button can fire the C action twice. The MessageBox call is modal, so the second call is suppressed by Windows, but a non-modal native dialog will show twice. Mitigate with a 500 ms debounce tag.
- Edge case — language switch at runtime: Option A text is fixed; switching language does not translate it. Option B pulls text from the Text Library, so it follows the active runtime language.
-
Edge case — operator authorization: The dialog asks for confirmation, not authorization. If only Level-4 users may start the motor, gate the action in the AS with the WinCC user authorization, or in the HMI by checking
GetTagBit("@CurrentUserLevel"). - Edge case — touch screens: A "Mouse Click" event does not fire reliably on WinCC RT with a single tap. Bind to Mouse Down for touch, or add a Long touch trigger for safety-critical starts.
-
Edge case — timeouts: Neither option times out by default. A native dialog can implement a 10-second timeout with a global C script on a 1 Hz timer that clears
Confirm_Req.
Security and Authorization Layer
Confirmation is orthogonal to authorization. Recommended stack for a motor start:
- Operator logs in with a valid WinCC user (User Administrator).
- Operator presses Start.
- Authorization check:
UserLevel >= 4— if not, the action is rejected with a status message. - Confirmation dialog appears (this article).
- Operator presses Yes.
- Tag is written to the PLC.
- PLC performs the F-CPU safety check, then energizes the contactor.
Summary
For non-safety prototype HMI screens, the Win32 MessageBox C script is the shortest path to a motor-start confirmation dialog in WinCC, using MB_OKCANCEL | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_SYSTEMMODAL and the GetTagBit/SetTagBit pair. For any production system, multi-client deployment, audited environment, or translated runtime, build a native WinCC picture-window dialog driven by an internal confirmation tag and use direct connections on the Yes / No buttons. Both methods are valid; the Siemens support knowledge base entry 22906363 documents why Option B is the long-term choice.
Which WinCC version supports the C script MessageBox approach?
WinCC V7.0 SP3 and later, including V7.4 / V7.5, support the C action with the Win32 API call shown. TIA Portal WinCC Professional / Comfort / Advanced can run the same logic, but inline C is not exposed — use a global C function or translate to VBS using HMIRuntime.BaseScreenName and HMIRuntime.Tags.
Why is MessageBox not recommended in WinCC runtime?
Siemens KB ID 22906363 lists the reasons: hard-coded text that cannot be translated, no WinCC Audit logging of the OK / Cancel click, modal blocking in RDP and WebUX sessions, and unsupported behavior in redundant server pairs. The native picture-window dialog avoids all of these.
How do I make the dialog text follow the active runtime language?
Use Option B with the Text Library. In TIA Portal, set the text field's Text property to a multi-language Text List entry; in WinCC V7 Graphics Designer, use a Text Distributor entry. Option A's MessageBox literal is a fixed Unicode string and cannot be translated without separate scripts per language.
Can the confirmation dialog enforce a timeout?
Yes, in Option B. Add a global C action on a 1 Hz timer that decrements a counter tag; when the counter reaches 0, set Confirm_Req = 0 to close the dialog. In Option A, a MessageBox cannot enforce a server-side timeout — it must rely on Windows idle policy.
Does the confirmation dialog replace an E-stop or safety interlock?
No. The dialog is an operator-interface safeguard only. Functional-safety requirements (E-stop, guard interlock, two-hand control, safe stop) must be implemented in the F-CPU and F-I/O with PROFIsafe or AS-i Safety. The HMI confirmation is in addition to, not a replacement for, the safety chain.