#include <Windows.h> #include <iostream> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK BtnProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { setlocale(LC_ALL, "Russian"); static LPCWSTR szAppName = TEXT("MyWindowApp"); HWND hwnd; MSG msg; WNDCLASSEX wndclass; // Структура настройки класса wndclass.cbSize = sizeof(wndclass); // Размер структуры wndclass.style = CS_HREDRAW | CS_VREDRAW; // Cтиль окна (перекрашивать при изменении размера) wndclass.lpfnWndProc = WndProc; // Указатель для callback wndclass.cbClsExtra = 0; // Количество дополнительных байт windowinstance wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; // Хэндл окна wndclass.hIcon = LoadIcon(nullptr, IDI_APPLICATION); wndclass.hCursor = LoadCursor(nullptr, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(COLOR_BACKGROUND); wndclass.lpszMenuName = nullptr; wndclass.lpszClassName = szAppName; wndclass.hIconSm = LoadIcon(nullptr, IDI_APPLICATION); RegisterClassEx(&wndclass); // Регистрация класса окна hwnd = CreateWindow(szAppName, TEXT("Лабораторная работа №2"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, hInstance, nullptr); ShowWindow(hwnd, iCmdShow); // Показать окно UpdateWindow(hwnd); // Перекрасить окно while (GetMessage(&msg, nullptr, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } TCHAR* ToUpperCase(TCHAR *input) { static TCHAR buffer[1000]; TCHAR *s = input; TCHAR *t = buffer; while (*s != '\0') { *t = toupper(*s); s++; t++; } return buffer; } HWND editHwnd; HMENU editIdentifier = (HMENU)10000; TCHAR string[100]; TCHAR* upperString = nullptr; WNDPROC OldBtnProc; LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; GetWindowRect(hwnd, &rect); // Cообщения обработки switch (iMsg) { case WM_CREATE: editHwnd = CreateWindow( L"EDIT", // Предопределенный класс (+юникод) L"", // Текст поля ввода (пусто) WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | WS_TABSTOP, // Стили 100, // x (абсцисса) 100, // y (ордината) 400, // Ширина поля 25, // Высота поля hwnd, // Родительское окно editIdentifier, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); // Указатель не требуется // Подкласс кнопки управления OldBtnProc = reinterpret_cast<WNDPROC>(static_cast<LONG_PTR>( SetWindowLongPtr(editHwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(BtnProc)))); // Сохранить оригинал, кнопка оконной процедуры по умолчанию в качестве // кнопки управления пользовательскими данными SetWindowLongPtr(editHwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(OldBtnProc)); break; case WM_PAINT: if (upperString != nullptr) { hdc = BeginPaint(hwnd, &ps); DrawText(hdc, upperString, -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); EndPaint(hwnd, &ps); } return 0; break; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, iMsg, wParam, lParam); } LRESULT CALLBACK BtnProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // Оконная процедура подкласса для кнопки static HWND hEdit; // Восстановить ранее сохраненную кнопку процедуры окна static WNDPROC OrigBtnProc = reinterpret_cast<WNDPROC>(static_cast<LONG_PTR>( GetWindowLongPtr(hwnd, GWLP_USERDATA))); switch (uMsg) { case WM_KEYDOWN: switch (wParam) { case VK_RETURN: GetWindowText(editHwnd, string, 100); upperString = ToUpperCase(string); SendMessage(hwnd, WM_PAINT, 0, 0); break; } default: // Вызов хэндла по умолчанию для управления процессом return CallWindowProc(OrigBtnProc, hwnd, uMsg, wParam, lParam); } } 

I would be extremely grateful for the help (:

Closed due to the fact that off-topic participants Abyx , aleksandr barakin , Vladimir Martyanov , user194374, Nicolas Chabanovsky Mar 10 '16 at 7:04 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Abyx, aleksandr barakin, Vladimir Martyanov, Community Spirit, Nicolas Chabanovsky
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Put the code in the post body - if the code is removed with pastebin, your question will be useless for further visitors. - Denis

1 answer 1

This site does not do laboratory for students, so I will give only a part of the code responsible for creating and adding a line to the ListBox.

This is how we create a ListBox that will contain the lines:

 hListBox = CreateWindow(TEXT("listbox"), NULL, WS_CHILD | WS_VISIBLE | LBS_STANDARD | LBS_HASSTRINGS, 7, 35, 300, 200, hWnd, (HMENU)(1), (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL); 

And this is how we add a line to the ListBox:

 TCHAR string[] = TEXT("просто строка для примера"); SendMessage(hListBox, LB_ADDSTRING, NULL, reinterpret_cast<LPARAM>(string)); 

Then, I hope, you will figure it out yourself, if you still have questions, ask.