Geeks With Blogs
Doug Moore All Things WM / CE5 / CE6 / WEC7 / WEC2013
Working on a CE device that presented a kiosk application I wanted to find a way to suppress the following Windows CE Networking DHCP popups:

"DHCP was unable to obtain an IP address. If the netcard is removable, then you can remove/reinsert it to have DHCP make another attempt to obtain an IP address for it. Otherwise, you can statically assign an address."

"Your IP address lease has expired. DHCP was unable to renew your lease."

"A DHCP Server could not be contacted. Using cached lease information."

These popups were obtrusive and the end user of the device had no idea how to resolve the issues that these popups were bringing to light. The device depends upon a reliable network infrastructure and these popups should really never ... pop up ... but when they did they did nothing more than confuse the user and get in the way of the kiosk application / user interface the user was trying to use.

Typically the popups were quickly ignored by the user and closed, but in some cases a call or ticket was created with their IT department for resolution, wasting everyone's time.

The network attached device is smart enough to buffer the readings it was responsible for taking, simply sending them when the networking issue was resolved naturally by being carried to where there was network coverage, so the popups only served as an annoyance to the user, not to mention the IT department who would have to deal with any users bringing up the fact that this strange popup popped up, making them explain to the user what should do about it.

This post alluded to the solution but did not follow through with the specifics so I am doing that here.

If you want to suppress these or any of the other of the multitude of popups the NETUI supports start by following the instructions in the blog post by Michel Varhagen of GuruCE, Cloning publc code: An example.

Add the following new function, SuppressNetMsgBox, in between the two functions you'll find @:

netui.c(139):GetNetString (UINT uID, LPTSTR lpBuffer, int nBufferMax)

and

netui.c(165): BOOL WINAPIV NetMsgBox (HWND hParent, DWORD dwFlags, TCHAR *szStr)

BOOL SuppressNetMsgBox(DWORD dwId, TCHAR *szStr)
{
#define MAXCMP 76
TCHAR szBuffer[MAXCMP] = {0};
DWORD dwMaxCount = sizeof(szBuffer)/sizeof(szBuffer[0]);
if (!GetNetString(dwId, szBuffer, (int)dwMaxCount)) return FALSE;
if (!_tcsncmp(szBuffer, szStr, (size_t)(dwMaxCount-1)))
{
NKDbgPrintfW(_T("Networking Pop-up: \"%s\"... suppressed.\r\n"), szBuffer); 
return TRUE;
}
return FALSE;
}

Add calls to SuppressNetMsgBox inside the NetMsgBox function, where shown, as shown:

BOOL WINAPIV NetMsgBox (HWND hParent, DWORD dwFlags, TCHAR *szStr)
{
    TCHAR szTitle[200];
    DWORD dwStyle, dwId;
    int iRet;
    HCURSOR hCur;

    // verify the incoming window handle and fail is not null and invalid
    if (hParent && !IsWindow(hParent)) {
        SetLastError(ERROR_INVALID_WINDOW_HANDLE);
        return FALSE;
    }

if (
(SuppressNetMsgBox(NETUI_GETNETSTR_NO_IPADDR, szStr)) // "DHCP was unable to obtain an IP address. If the netcard is removable, then you can remove/reinsert it to have DHCP make another attempt to obtain an IP address for it. Otherwise, you can statically assign an address."
|| (SuppressNetMsgBox(NETUI_GETNETSTR_LEASE_EXPIRED, szStr)) // "Your IP address lease has expired. DHCP was unable to renew your lease."
|| (SuppressNetMsgBox(NETUI_GETNETSTR_CACHED_LEASE, szStr)) // "A DHCP Server could not be contacted. Using cached lease information."
)
{
return FALSE;
}

    // Default title is "Windows CE Networking"
    if (dwFlags & NMB_FL_TITLEUSB)
        dwId = IDS_USB_CAPTION;
    else
        dwId = IDS_NETMSGBOX_TITLE;

...
}

Adapt this to your needs.
My needs have been met.

Debug Output Example:
Networking Pop-up: "DHCP was unable to obtain an IP address. If the netcard is removable, then "... suppressed.

I'd like to mention that a caveat to cloning and modifying NETUI is that you can tweak netui.rc to your liking and make some of the somewhat ugly, somewhat clunky user interface "sample code" work better for you and your platform's display resolution and orientation.

The device I am working on has a portrait orientation QVGA display (240x360) and NETUI was developed in the days of the first Pocket PCs that has 240x480 displays. Therefore the wrong dialogs are presented on QVGAP displays. The fix is simple.

Search and replace all "480" with UNIT_LANDSCAPE_WIDTH
in, "fPortrait = (GetSystemMetrics(SM_CXSCREEN) < 480)", for example
and define:
C:\WINCE600\3rdParty\CLONED\NETUI\quickconfigui.h(34):
#define UNIT_LANDSCAPE_WIDTH            320

Cloning this project will give you a way to correct and beautify the NETUI dialogs to your liking.

I personally chose to clone and modify NETUI in the 3rdParty tree @ WINCE600\3rdParty\CLONED\NETUI, instead of cloning into the BSP's source tree.

This way I can create a catalog item for my NETUI replacement and add it to or remove it from any OS design based on any BSP made by any vendor, quickly and easily and, my work is then portable as I go from working one platform to another.

Since I work on devices running on WEC7 I can also make my changes work there by comparing the WEC7 code base to the NETUI I cloned from CE6 and, by adding some conditionals around the code that is different between the two OS, make the one cloned NETUI replacement catalog item work for either OS.

Let me know if you need or want to see more.
I don't know if there is even any interest in this topic.
I just wanted to share in case there was.
Posted on Sunday, March 12, 2017 12:37 PM | Back to top


Comments on this post: How To Suppress DHCP Popups In NETUI

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Doug Moore | Powered by: GeeksWithBlogs.net