创建函数: INT_PTR CALLBACK Dlg1(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: Dlg1_Init(hDlg); return (INT_PTR)TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: Dlg1_GetResult(hDlg); break; case IDCANCEL: EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; }
void Dlg1_Init(HWND hDlg) { HWND tf1 = GetDlgItem(hDlg, IDC_EDIT1); HWND tf2 = GetDlgItem(hDlg, IDC_EDIT2); SendMessage(tf1, WM_SETTEXT, NULL, (LPARAM)L"abcdef"); SendMessage(tf2, WM_SETTEXT, NULL, (LPARAM)L"d45"); }
void insert(wchar_t *s1, wchar_t *s2) { int f = 0; int len1 = wcslen(s1); int len2 = wcslen(s2); wchar_t *p1 = s1; wchar_t *p2 = s1 + len1 - 1; while (*p1 != '\0' && *p1 != *s2) p1++; if (*p1 != '\0') { for (; p2 > p1; p2--) *(p2 + len2 - 1) = *p2; f = 1; } while (*s2) *p1++ = *s2++; *(s1 + len1 + len2 - f) = '\0'; }
void Dlg1_GetResult(HWND hDlg) { HWND tf1 = GetDlgItem(hDlg, IDC_EDIT1); HWND tf2 = GetDlgItem(hDlg, IDC_EDIT2); HWND tf3 = GetDlgItem(hDlg, IDC_EDIT3); wchar_t s1[100]; wchar_t s2[100]; GetWindowText(tf1, s1, 500); GetWindowText(tf2, s2, 500); insert(s1, s2); SendMessage(tf3, WM_SETTEXT, NULL, (LPARAM)s1); }
|