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
|
#define _WINSOCKAPI_
#include <WinSock2.h>
#include <Windows.h>
#include <string>
#include <stdint.h>
#include "winClude.h"
using namespace std;
int32_t winClude::winStart (HINSTANCE hInstance, int32_t nShowCmd)
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
int32_t screenWidth = 800;
int32_t screenHeight = 600;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = winClude::StaticWinProc;
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 = "myWinClass";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
return 0;
}
int32_t winLeft;
int32_t winTop;
winLeft = (GetSystemMetrics(SM_CXSCREEN) / 2) - (screenWidth / 2);
winTop = (GetSystemMetrics(SM_CYSCREEN) / 2) - (screenHeight / 2);
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
"myWinClass",
"Window",
WS_OVERLAPPEDWINDOW,
winLeft, winTop, screenWidth, screenHeight, NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd);
while(true)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// runtime loop code
}
}
return msg.wParam;
}
LRESULT CALLBACK winClude::StaticWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
winClude *wnd = 0;
if(msg == WM_NCCREATE)
{
wnd = (winClude *)((LPCREATESTRUCT)lParam)->lpCreateParams;
::SetWindowLong(hwnd, GWL_USERDATA, reinterpret_cast<long>(wnd));
}
else
wnd = reinterpret_cast<winClude *>(::GetWindowLong(hwnd, GWL_USERDATA));
return wnd->myWinProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK winClude::myWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch ( msg )
{
case WM_KEYDOWN:
{
switch(wParam)
{
case VK_F1:
{
ws.Startup();
ws.AsyncSelect(hwnd);
ws.wsConnect("216.239.138.52", 80);
ws.SendMsg("GET /index.php HTML/1.0", lParam);
}
case VK_ESCAPE:
{
PostQuitMessage( 0 );
}
}
}
case 104: // WM_SOCKET
{
if(WSAGETSELECTERROR(lParam))
break;
switch(WSAGETSELECTEVENT(lParam))
{
case FD_READ:
{
}
case FD_CLOSE:
{
}
}
}
case WM_CLOSE:
{
ws.Shutdown();
DestroyWindow( hwnd );
break;
}
case WM_DESTROY:
{
PostQuitMessage( 0 );
break;
}
default:
return DefWindowProc( hwnd, msg, wParam, lParam );
}
return 0;
}
|