LRESULT CALLBACK EditBoxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_KEYDOWN: { if (LOWORD(wParam) == VK_RETURN) { if (serverConnection) { static char buf[50000]; SendMessage(editBoxHwnd, WM_GETTEXT, sizeof buf, reinterpret_cast<LPARAM>(buf)); buf[(sizeof buf) - 1] = '\0'; commandHistory.push_back(buf); currentCommandHistoryPos = commandHistory.end(); Words words; tokenize(buf, words); serverConnection->sendRequest(words); SendMessage(editBoxHwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>("")); } return TRUE; } else if (LOWORD(wParam) == VK_UP) { if (currentCommandHistoryPos != commandHistory.begin()) { currentCommandHistoryPos--; const char* command = currentCommandHistoryPos->c_str(); SendMessage(editBoxHwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(command)); size_t commandLength = strlen(command); SendMessage(editBoxHwnd, EM_SETSEL, commandLength, commandLength); } return TRUE; } else if (LOWORD(wParam) == VK_DOWN) { if (currentCommandHistoryPos != commandHistory.end()) { currentCommandHistoryPos++; const char* command = (currentCommandHistoryPos != commandHistory.end()) ? currentCommandHistoryPos->c_str() : ""; SendMessage(editBoxHwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(command)); size_t commandLength = strlen(command); SendMessage(editBoxHwnd, EM_SETSEL, commandLength, commandLength); } return TRUE; } } break; } return CallWindowProc(editBoxOriginalWndProc, hWnd, message, wParam, lParam); }