{"id":41823,"date":"2003-11-14T04:18:00","date_gmt":"2003-11-14T04:18:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2003\/11\/14\/preventing-edit-control-text-from-being-autoselected-in-a-dialog-box\/"},"modified":"2003-11-14T04:18:00","modified_gmt":"2003-11-14T04:18:00","slug":"preventing-edit-control-text-from-being-autoselected-in-a-dialog-box","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20031114-00\/?p=41823","title":{"rendered":"Preventing edit control text from being autoselected in a dialog box"},"content":{"rendered":"<p>\nBy default, when the user TABs to an edit control in a dialog box,\nthe entire contents of the edit control are autoselected.\nThis occurs because the edit control responds with the\n<code>DLGC_HASSETSEL<\/code> flag in response to the\n<code>WM_GETDLGCODE<\/code> message.\nTo prevent it from happening, remove that flag.\n<\/p>\n<pre>\nLRESULT CALLBACK RemoveHasSetSelSubclassProc\n    (HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam,\n     UINT_PTR uIdSubclass, DWORD_PTR dwRefData)\n{\n    switch (uiMsg) {\n    case WM_NCDESTROY:\n        RemoveWindowSubclass(hwnd, RemoveHasSetSelSubclassProc,\n                             uIdSubclass);\n        break;\n    case WM_GETDLGCODE:\n        return DefSubclassProc(hwnd, uiMsg, wParam, lParam)\n                             &amp; ~DLGC_HASSETSEL;\n    }\n    return DefSubclassProc(hwnd, uiMsg, wParam, lParam);\n}\n<\/pre>\n<p>\nAll this subclass procedure does is remove the\n<code>DLGC_HASSETSEL<\/code> flag from the return value\nof the <code>WM_GETDLGCODE<\/code> message.\n<\/p>\n<pre>\nINT_PTR CALLBACK DlgProc(HWND hdlg, UINT uiMsg,\n                         WPARAM wParam, LPARAM lParam)\n{\n    switch (uiMsg) {\n    case WM_INITDIALOG:\n        SetWindowSubclass(GetDlgItem(hdlg, 100),\n                          RemoveHasSetSelSubclassProc, 0, 0);\n        break;\n    case WM_COMMAND:\n        switch (GET_WM_COMMAND_ID(wParam, lParam)) {\n        case IDCANCEL:\n            EndDialog(hdlg, 1);\n            break;\n        }\n    }\n    return FALSE;\n}\n<\/pre>\n<p>\nThe subclass procedure is installed when the dialog box is\ninitialized.\n<\/p>\n<pre>\nint WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,\n                   LPSTR lpCmdLine, int nShowCmd)\n{\n    DialogBox(hinst, MAKEINTRESOURCE(1), NULL, DlgProc);\n    return 0;\n}\n1 DIALOGEX DISCARDABLE  0, 0, 200,200\nSTYLE DS_SHELLFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU\nCAPTION \"sample\"\nFONT 8, \"MS Shell Dlg\"\nBEGIN\n  CONTROL         \"Blah blah\",100,\"Edit\",WS_TABSTOP,7,4,100,10\n    DEFPUSHBUTTON \"&amp;Bye\", IDCANCEL, 7,24,50,14, WS_TABSTOP\nEND\n<\/pre>\n<p>\nAnd here is the dialog box that we display.\n<\/p>\n<p>There really isn&#8217;t much to it, but I figured a complete sample\nprogram might help somebody out. Plus it lets me show off the\n<code>SetWindowSubclass<\/code> function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default, when the user TABs to an edit control in a dialog box, the entire contents of the edit control are autoselected. This occurs because the edit control responds with the DLGC_HASSETSEL flag in response to the WM_GETDLGCODE message. To prevent it from happening, remove that flag. LRESULT CALLBACK RemoveHasSetSelSubclassProc (HWND hwnd, UINT uiMsg, [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-41823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>By default, when the user TABs to an edit control in a dialog box, the entire contents of the edit control are autoselected. This occurs because the edit control responds with the DLGC_HASSETSEL flag in response to the WM_GETDLGCODE message. To prevent it from happening, remove that flag. LRESULT CALLBACK RemoveHasSetSelSubclassProc (HWND hwnd, UINT uiMsg, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/41823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=41823"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/41823\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=41823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=41823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=41823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}