Code:
#include <windows.h>
#include <tchar.h>
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
static HWND hEdit;
switch (uMsg)
{
case WM_CREATE:
hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T("0123456789"),
WS_CHILD|WS_VISIBLE,
10,10,200,30,hwnd,0,GetModuleHandle(0),0);
/*highlight 5th character*/
SendMessage(hEdit,EM_SETSEL,4,5);
SetFocus(hEdit);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR pStr,int nCmd)
{
HWND hwnd;
MSG msg;
TCHAR classname[]=_T("kenf's_wnd");
WNDCLASSEX wcx={0};
wcx.cbSize =sizeof(wcx);
wcx.lpfnWndProc =WndProc;
wcx.hInstance =hInst;
wcx.hIcon =(HICON)LoadImage(0,IDI_APPLICATION,IMAGE_ICON,0, 0,LR_SHARED);
wcx.hCursor =(HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0, LR_SHARED);
wcx.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
wcx.lpszClassName=classname;
if (RegisterClassEx(&wcx))
{
hwnd=CreateWindowEx(0,classname,
_T("Highlight Single Character in Edit Control"),
WS_OVERLAPPEDWINDOW,
GetSystemMetrics(SM_CXSCREEN)/4,
GetSystemMetrics(SM_CYSCREEN)/4,
GetSystemMetrics(SM_CXSCREEN)/2,
GetSystemMetrics(SM_CYSCREEN)/2,
0,0,hInst,0);
if (hwnd)
{
ShowWindow(hwnd,nCmd);
UpdateWindow(hwnd);
while (GetMessage(&msg,0,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
else
{
MessageBox(0,_T("Wnd creation failure"),_T("Error"),MB_OK|MB_ICONERROR);
return 0;
}
}
MessageBox(0,_T("Wnd registration failure"),_T("Error"),MB_OK|MB_ICONERROR);
return 0;
}
Hope that's of some use to you.