To select text when control gets focus ?
case WM_COMMAND:
switch(HIWORD(wParam)) {
case EN_SETFOCUS:
if (LOWORD(wParam) == IDC_EDIT1 || LOWORD(wParam) == IDC_EDIT2)
{
//SetWindowText(hFrame, "EN_SETFOCUS");
PostMessage((HWND)lParam, EM_SETSEL, 0, -1);
}
break;
}
break;
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define IDC_EDIT1 4001
#define IDC_EDIT2 4002
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
char *szAppName = "TestEditSelAll";
char *szFrameClass = "cTestEditSelAll";
HWND hFrame;
HANDLE hInst;
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wcx;
MSG msg;
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = (WNDPROC) WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
wcx.hbrBackground= (HBRUSH)COLOR_APPWORKSPACE+1;
wcx.lpszMenuName = NULL;
wcx.lpszClassName= szFrameClass;
wcx.hIconSm = 0;
if (!RegisterClassEx(&wcx))
return 0;
hInst = hInstance;
hFrame = CreateWindowEx(0, szFrameClass, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
//CW_USEDEFAULT, CW_USEDEFAULT,
230,160,
NULL, NULL, hInst, NULL);
if(!hFrame)
return 0;
ShowWindow(hFrame, nCmdShow);
UpdateWindow(hFrame);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
switch(wMsg) {
case WM_COMMAND:
switch(HIWORD(wParam)) {
case EN_SETFOCUS:
if (LOWORD(wParam) == IDC_EDIT1 || LOWORD(wParam) == IDC_EDIT2)
{
//SetWindowText(hFrame, "EN_SETFOCUS");
PostMessage((HWND)lParam, EM_SETSEL, 0, -1);
}
break;
}
break;
case WM_CREATE:
{
HWND hEdit;
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "Edit1 test",
WS_CHILD | WS_VISIBLE | ES_NOHIDESEL,
10, 10, 100, 22, hWnd, (HMENU)IDC_EDIT1, hInst, NULL);
SendMessage(hEdit, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "Edit2 test",
WS_CHILD | WS_VISIBLE | ES_NOHIDESEL,
10, 40, 100, 22, hWnd, (HMENU)IDC_EDIT2, hInst, NULL);
SendMessage(hEdit, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
//SetFocus(hEdit);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc(hWnd, wMsg, wParam, lParam);
}