1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
#define _WINSOCKAPI_
#include <WinSock2.h>
#include <Windows.h>
#include <string>
#include <stdint.h>
#include <fstream>
#include "winClude.h"
using namespace std;
winBase::winBase( HINSTANCE hinst, int showCommand, string title )
{
hwnd = NULL;
hinstance = hinst;
setWinTitle(title);
className = title;
}
winBase::~winBase(){}
bool winBase::create()
{
WNDCLASSEX wcx;
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = winBase::messageRouter;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hinstance;
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wcx.lpszMenuName = NULL;
wcx.lpszClassName = className.c_str();
wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wcx))
return false;
int32_t winLeft;
int32_t winTop;
int32_t screenWidth = 800;
int32_t screenHeight = 600;
winLeft = (GetSystemMetrics(SM_CXSCREEN) / 2) - (screenWidth / 2);
winTop = (GetSystemMetrics(SM_CYSCREEN) / 2) - (screenHeight / 2);
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, className.c_str(), windowTitle.c_str(), WS_OVERLAPPEDWINDOW,
winLeft, winTop, screenWidth, screenHeight,
NULL, NULL, hinstance, (void *)this);
if(hwnd == NULL)
return 0;
ShowWindow(hwnd, ShowCommand);
UpdateWindow(hwnd);
return (hwnd != NULL);
}
LRESULT CALLBACK winBase::messageRouter(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
winBase * Wnd;
if (msg == WM_NCCREATE)
{
SetWindowLong(hwnd, GWL_USERDATA, (long)((LPCREATESTRUCT(lparam))->lpCreateParams));
}
Wnd = GetObjectFromWin(hwnd);
if (Wnd)
return Wnd->messageHandler(hwnd, msg, wparam, lparam);
else
return DefWindowProc(hwnd, msg, wparam, lparam);
}
window::window( HINSTANCE hinst, int showCommand, string title ) : winBase( hinst, showCommand, title )
{
bool success = false;
ShowCommand = showCommand;
success = create();
active = true;
}
window::~window(){}
LRESULT CALLBACK window::messageHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
string output;
switch (msg)
{
case WM_CREATE:
break;
case WM_KEYDOWN:
{
switch(wparam)
{
case VK_ESCAPE:
{
active = false;
::PostQuitMessage(0);
return 0;
}
case VK_F1:
{
SOCKET ls;
string input;
input = "GET /index.php HTTP/1.1\r\n";
input += "Host: www.yunaco.com\r\n";
input += "Connection: close\r\n";
input += "\r\n";
wsa.Startup();
wsa.Socket(ls);
wsa.AsyncSelect(ls, hwnd);
wsa.Connect(ls, "216.239.138.52", 80);
wsa.SendMsg(ls, input, lparam);
//Sleep(100);
wsa.Receive(ls, output);
wsa.KillSwitch(ls);
}
}
break;
}
case WM_LBUTTONDOWN:
break;
case WM_LBUTTONUP:
break;
case WM_RBUTTONDOWN:
break;
case WM_RBUTTONUP:
break;
case WM_MOUSEMOVE:
break;
case WM_PAINT:
break;
case WM_DESTROY:
active = false;
::PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
}
bool window::msgPump()
{
static MSG Msg;
if (PeekMessage(&Msg, hwnd, 0, 0, PM_REMOVE))
{
if (Msg.message == WM_QUIT)
return false;
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return true;
}
int window::run()
{
while(active)
{
if(!msgPump())
active = false;
}
return 0;
}
|