Common Controls - IP Address
A dialog demo for the IP address common control, loaded with ICC_INTERNET_CLASSES.
The four-part dotted-decimal IP editor is a common control you have to opt into: InitCommonControlsEx with ICC_INTERNET_CLASSES registers it, then you drop an IPAddress control into your dialog template. The dialog procedure here just reads the entered value back out as text when OK is pressed. Use it whenever you need validated IP input in a Win32 dialog without writing your own parsing and range checks.
#include <Windows.H>
#include <WindowsX.H>
#include <Windows.H>
#include <WindowsX.H>
#include <CommCtrl.H>
#include <Wincon.h>
#include <ShellAPI.H>
#include <Stdio.H>
#include <Stdlib.H>
//---------------------------------------------------------------------------
/* Library Headers Begin */
#include "Headers/NSWFL.H"
/* Library Headers End */
#include "Headers/Definitions.H"
#include "Headers/Functions.H"
#include "Dialogs/MainDialog.H"
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR Cmd , int CmdShow)
{
MainInstance = hInstance;
/*
ICC_ANIMATE_CLASS
Load animate control class.
ICC_BAR_CLASSES
Load toolbar, status bar, trackbar, and ToolTip control classes.
ICC_COOL_CLASSES
Load rebar control class.
ICC_DATE_CLASSES
Load date and time picker control class.
ICC_HOTKEY_CLASS
Load hot key control class.
ICC_INTERNET_CLASSES
Load IP address class.
ICC_LINK_CLASS
Load a hyperlink control class.
ICC_LISTVIEW_CLASSES
Load list-view and header control classes.
ICC_NATIVEFNTCTL_CLASS
Load a native font control class.
ICC_PAGESCROLLER_CLASS
Load pager control class.
ICC_PROGRESS_CLASS
Load progress bar control class.
ICC_STANDARD_CLASSES
Load one of the intrinsic User32 control classes. The user controls include button, edit, static, listbox, combobox, and scrollbar.
ICC_TAB_CLASSES
Load tab and ToolTip control classes.
ICC_TREEVIEW_CLASSES
Load tree-view and ToolTip control classes.
ICC_UPDOWN_CLASS
Load up-down control class.
ICC_USEREX_CLASSES
Load ComboBoxEx class.
ICC_WIN95_CLASSES
Load animate control, header, hot key, list-view, progress bar, status bar, tab, ToolTip, toolbar, trackbar, tree-view, and up-down control classes.
*/
INITCOMMONCONTROLSEX ICEX;
ICEX.dwSize = sizeof(ICEX);
ICEX.dwICC = ICC_INTERNET_CLASSES;
InitCommonControlsEx(&ICEX);
DialogBox(MainInstance,MAKEINTRESOURCE(100),0,MainDialog);
return 0;
}
BOOL CALLBACK MainDialog(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
static HWND IPAddress_hWnd;
for(;;)
{
if(Msg==WM_INITDIALOG)
{
MainDialog_hWnd = hDlg;
SendMessage(MainDialog_hWnd, WM_SETTEXT, FALSE,(LPARAM)TitleCaption);
SendMessage(MainDialog_hWnd, WM_SETICON, TRUE,(LPARAM)LoadIcon(GetWindowInstance(MainDialog_hWnd), MAKEINTRESOURCE(1)));
IPAddress_hWnd = GetDlgItem(MainDialog_hWnd, 1000);
CenterWindow(MainDialog_hWnd);
break;
}
if(Msg==WM_COMMAND)
{
if(wParam==100) // Ok Button
{
char *IpAddress = NULL;
IpAddress = Get_Text(IPAddress_hWnd);
MessageBox (NULL, IpAddress , TitleCaption, 0 + MB_ICONASTERISK + MB_SYSTEMMODAL);
}
if(wParam==200) // Exit Button
{
EndDialog(MainDialog_hWnd,0);
}
}
if(Msg==WM_CLOSE)
{
EndDialog(MainDialog_hWnd,0);
}
break;
}
return 0;
}