Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <vector>
- #include <string>
- #define IDC_LIST 1001
- #define IDC_BUTTON 1002
- #define NMSG WM_USER+1
- #pragma comment(lib, "ws2_32.lib")
- const char ClassName[] = "WindowClass";
- HWND hEdit;
- HWND hBut;
- HWND hwnd;
- DWORD dwThreadID;
- HANDLE hThread;
- std::vector<std::string> buf;
- int CloseValue;
- DWORD WINAPI ThreadFunc(PVOID pvParam){
- DWORD dwResult = 0;
- WSADATA wsaData;
- SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- char bufchar[512];
- WSAStartup(MAKEWORD(2,0), &wsaData);
- sockaddr_in sockAddr;
- sockAddr.sin_family = AF_INET;
- sockAddr.sin_port = htons(6667);
- sockAddr.sin_addr.S_un.S_addr = inet_addr("97.107.133.186"); //IP to irc.purplesurge.net
- if(!connect(hSocket, (sockaddr*)(&sockAddr), sizeof(sockAddr)))
- {
- MessageBox(hwnd,"Failed to connect","Connect",MB_OK);
- return(dwResult);
- }
- MessageBox(hwnd,"Thread Initiated and connected","Thread",MB_OK);
- while(CloseValue != 1)
- {
- recv(hSocket,bufchar,512,0);
- buf.push_back((std::string)bufchar);
- //PostMessage(hwnd,NMSG,0,0);
- }
- closesocket(hSocket);
- WSACleanup();
- return(dwResult);
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch(msg)
- {
- case WM_CLOSE:
- CloseValue = 1;
- DestroyWindow(hwnd);
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_BUTTON:
- int indexstart = GetWindowTextLength(hEdit);
- int indexend = GetWindowTextLength(hEdit);
- ++indexend;
- SendMessage(hEdit,EM_SETSEL,(WPARAM)indexstart,(LPARAM)indexend);
- SendMessage(hEdit,EM_REPLACESEL,0,(LPARAM)"This is just to test that i can add strings to the listbox\n");
- break;
- }
- break;
- case NMSG:
- //SendMessage(hEdit,EM_SETSEL,(WPARAM)GetWindowTextLength(hEdit),(LPARAM)GetWindowTextLength(hEdit)+1);
- //SendMessage(hEdit,EM_REPLACESEL,0,VAL); NOTE: I havent figured this out so.
- //buf.erase(buf.begin()); Delete the first element.
- break;
- case WM_DESTROY:
- CloseValue = 1;
- PostQuitMessage(0);
- break;
- case WM_CREATE:
- hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","",WS_VISIBLE | WS_CHILD | ES_MULTILINE | WS_VSCROLL | WS_HSCROLL, 5,5,770,600,hwnd,(HMENU)IDC_LIST,GetModuleHandle(NULL),NULL);
- hBut = CreateWindow("BUTTON","",WS_VISIBLE | WS_CHILD, 735,615, 30,30,hwnd,(HMENU)IDC_BUTTON,GetModuleHandle(NULL),NULL);
- hThread = CreateThread(NULL, 0, ThreadFunc, (PVOID)0, 0, &dwThreadID);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- MSG Msg;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = ClassName;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- RegisterClassEx(&wc);
- hwnd = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- ClassName,
- "TestWindow",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 800, 700,
- NULL, NULL, hInstance, NULL);
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while(GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement