000
09.04.2017, 18:50 Uhr
qwertzui
|
Ich wollte CPP lernen, und nun bin ich bei meinem ersten Projekt. Mein Ziel ist es, den Text, welcher in eine Textbox eingegeben wird, in einem Textfeld sichtbar zu machen.
Was ich bei folgendem Code, den ich zusammengebastelt habe, nicht verstehe: Wenn ich im unteren Textfeld eine Zeile geschrieben habe, dann kann ich die nächste Zeile nicht beschreiben, d. h. wie kann ich erreichen, dass das Textfeld auf mehreren Zeilen beschrieben werden kann?
Zudem verstehe ich nicht, wieso ich bei der Scrollbar bereits scrollen kann, wenn ich noch gar nichts geschrieben habe. Hier mein Code:
C++: |
#include <windows.h>
HWND TextBox, SendButton, TextField;
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch (Message) { case WM_CREATE:
TextField = CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_READONLY | WS_VSCROLL, 30, 20, 620, 200, hwnd, (HMENU) 3, NULL, NULL);
TextField = CreateWindow("EDIT", "", WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL, 30, 220, 620, 150, hwnd, (HMENU) 1, NULL, NULL);
SendButton = CreateWindow("BUTTON", "Send", WS_VISIBLE | WS_CHILD | WS_BORDER, 600, 390, 60, 20, hwnd, (HMENU) 2, NULL, NULL); break; case WM_COMMAND: switch(LOWORD(wParam)) { case 1: //Bei Click... break; } break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, Message, wParam, lParam); } return 0; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; /* A properties struct of our window */ HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */ MSG msg; /* A temporary location for all messages */
/* zero out the struct and set the stuff we want to modify */ memset(&wc,0,sizeof(wc)); wc.cbSize = sizeof(WNDCLASSEX); wc.lpfnWndProc = WndProc; /* This is where we will send messages to */ wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszClassName = "WindowClass"; //wc.lpszMenueName = wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */ wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */
if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK); return 0; }
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","",WS_VISIBLE|WS_OVERLAPPEDWINDOW, 100, /* x */ 100, /* y */ 700, /* width */ 480, /* height */ NULL,NULL,hInstance,NULL);
if(hwnd == NULL) { MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK); return 0; }
/* This is the heart of our program where all input is processed and sent to WndProc. Note that GetMessage blocks code flow until it receives something, so this loop will not produce unreasonably high CPU usage */ while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */ TranslateMessage(&msg); /* Translate key codes to chars if present */ DispatchMessage(&msg); /* Send it to WndProc */ } return msg.wParam; }
|
|