Code:
#include <windows.h>
#include <tchar.h>
#include <string>
#include <iostream>
#include <richedit.h>
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"Gdi32.lib")
using namespace std;
#define IDB_TEXT2 101
#define IDB_TEXT3 102
#define GetF 103
HWND hwnd, Win_1, Win_2, Send;
MSG Msg;
HDC hdc;
PAINTSTRUCT ps;
TCHAR *buf;
int length;
size_t found ;
string Text, str;
void GetIt()
{
hdc = BeginPaint(Win_1, &ps);
length = GetWindowTextLength(Win_2);
buf = new TCHAR[length+1];
GetWindowText(GetDlgItem(hwnd,IDB_TEXT3), buf, length+1);
str = buf;
found = str.find("\r\n");
Text = str.substr(0,found);
TextOut(hdc, 10, 10, Text.c_str(), strlen(Text.c_str()));
EndPaint(Win_1, &ps);
delete[] buf;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
switch(msg){
case WM_CREATE:
Win_1 = CreateWindowEx(0,"Edit","",
WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_VSCROLL |
ES_AUTOHSCROLL | ES_WANTRETURN | ES_MULTILINE,
20, 20, 550, 460,hwnd,(HMENU) IDB_TEXT2,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
Win_2 = CreateWindowEx(0,"Edit","hello",
WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_VSCROLL |
ES_AUTOHSCROLL | ES_WANTRETURN | ES_MULTILINE,
20, 500, 550, 180,hwnd,(HMENU) IDB_TEXT3,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
Send = CreateWindowEx(0,"Button","Send",
WS_CHILD | WS_VISIBLE | WS_BORDER,
20, 700, 550, 20,hwnd,(HMENU)GetF,0,NULL);
EnableWindow(Send ,TRUE);
break;
case WM_PAINT:
GetIt();
break;
case WM_COMMAND:
switch(wParam)
{
case GetF:
InvalidateRect(hwnd,0,FALSE);
break;
}
case WM_TIMER:
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX wc;
wc.hInstance = hInstance;
wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(100,100,100));
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "Class";
wc.lpszMenuName = NULL;
wc.style = 0;
wc.hIconSm = NULL;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_LEFT|WS_EX_LTRREADING|WS_EX_WINDOWEDGE,
"Class",
" The_Chatter",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 600, 800,
HWND_DESKTOP, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0;
}
SetTimer(hwnd,1,125,NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}