Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.68 KB | None | 0 0
  1. #include <windows.h>
  2. #include <vector>
  3. #include <string>
  4.  
  5. #define IDC_LIST 1001
  6. #define IDC_BUTTON 1002
  7. #define NMSG WM_USER+1
  8. #pragma comment(lib, "ws2_32.lib")
  9.  
  10. const char ClassName[] = "WindowClass";
  11. HWND hEdit;
  12. HWND hBut;
  13. HWND hwnd;
  14. DWORD dwThreadID;
  15. HANDLE hThread;
  16. std::vector<std::string> buf;
  17. int CloseValue;
  18.  
  19. DWORD WINAPI ThreadFunc(PVOID pvParam){
  20.  
  21.     DWORD dwResult = 0;
  22.    WSADATA wsaData;
  23.    SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  24.    char bufchar[512];
  25.  
  26.    WSAStartup(MAKEWORD(2,0), &wsaData);
  27.  
  28.    sockaddr_in sockAddr;
  29.    sockAddr.sin_family = AF_INET;
  30.    sockAddr.sin_port = htons(6667);
  31.    sockAddr.sin_addr.S_un.S_addr = inet_addr("97.107.133.186"); //IP to irc.purplesurge.net
  32.    if(!connect(hSocket, (sockaddr*)(&sockAddr), sizeof(sockAddr)))
  33.    {
  34.         MessageBox(hwnd,"Failed to connect","Connect",MB_OK);
  35.         return(dwResult);
  36.    }
  37.    MessageBox(hwnd,"Thread Initiated and connected","Thread",MB_OK);
  38.  
  39.    while(CloseValue != 1)
  40.    {
  41.        recv(hSocket,bufchar,512,0);
  42.        buf.push_back((std::string)bufchar);
  43.        //PostMessage(hwnd,NMSG,0,0);
  44.    }
  45.    closesocket(hSocket);
  46.    WSACleanup();
  47.    return(dwResult);
  48. }
  49.  
  50.  
  51. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  52. {
  53.     switch(msg)
  54.     {
  55.         case WM_CLOSE:
  56.             CloseValue = 1;
  57.             DestroyWindow(hwnd);
  58.             break;
  59.         case WM_COMMAND:
  60.             switch(LOWORD(wParam))
  61.             {
  62.                 case IDC_BUTTON:
  63.                 int indexstart = GetWindowTextLength(hEdit);
  64.                 int indexend = GetWindowTextLength(hEdit);
  65.                 ++indexend;
  66.                 SendMessage(hEdit,EM_SETSEL,(WPARAM)indexstart,(LPARAM)indexend);
  67.                 SendMessage(hEdit,EM_REPLACESEL,0,(LPARAM)"This is just to test that i can add strings to the listbox\n");
  68.                 break;
  69.             }
  70.             break;
  71.         case NMSG:
  72.             //SendMessage(hEdit,EM_SETSEL,(WPARAM)GetWindowTextLength(hEdit),(LPARAM)GetWindowTextLength(hEdit)+1);
  73.             //SendMessage(hEdit,EM_REPLACESEL,0,VAL);            NOTE: I havent figured this out so.       
  74.             //buf.erase(buf.begin());                            Delete the first element.
  75.             break;
  76.         case WM_DESTROY:
  77.             CloseValue = 1;
  78.             PostQuitMessage(0);
  79.             break;
  80.         case WM_CREATE:
  81.             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);
  82.             hBut = CreateWindow("BUTTON","",WS_VISIBLE | WS_CHILD, 735,615, 30,30,hwnd,(HMENU)IDC_BUTTON,GetModuleHandle(NULL),NULL);
  83.             hThread = CreateThread(NULL, 0, ThreadFunc, (PVOID)0, 0, &dwThreadID);
  84.             break;
  85.         default:
  86.             return DefWindowProc(hwnd, msg, wParam, lParam);
  87.     }
  88.     return 0;
  89. }
  90.  
  91. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  92. {
  93.     WNDCLASSEX wc;
  94.     MSG Msg;
  95.  
  96.     wc.cbSize        = sizeof(WNDCLASSEX);
  97.     wc.style         = 0;
  98.     wc.lpfnWndProc   = WndProc;
  99.     wc.cbClsExtra    = 0;
  100.     wc.cbWndExtra    = 0;
  101.     wc.hInstance     = hInstance;
  102.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  103.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  104.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  105.     wc.lpszMenuName  = NULL;
  106.     wc.lpszClassName = ClassName;
  107.     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  108.  
  109.     RegisterClassEx(&wc);
  110.  
  111.     hwnd = CreateWindowEx(
  112.         WS_EX_CLIENTEDGE,
  113.         ClassName,
  114.         "TestWindow",
  115.         WS_OVERLAPPEDWINDOW,
  116.         CW_USEDEFAULT, CW_USEDEFAULT, 800, 700,
  117.         NULL, NULL, hInstance, NULL);
  118.  
  119.  
  120.     ShowWindow(hwnd, nCmdShow);
  121.     UpdateWindow(hwnd);
  122.  
  123.     while(GetMessage(&Msg, NULL, 0, 0) > 0)
  124.     {
  125.         TranslateMessage(&Msg);
  126.         DispatchMessage(&Msg);
  127.     }
  128.     return Msg.wParam;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement