?? wwclient.cpp
字號:
// WWClient.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "WWClient.h"
#include <windows.h>
#include <commctrl.h>
#include <winsock2.h>
#define MAX_LOADSTRING 100
HINSTANCE hInst; // current instance
char buffer[10240];
TCHAR string[64];
static unsigned int * b;
int h=0;
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
HWND hWnd;
HWND hWndListView;
HWND hMenuBar; // menu bar handle
WSADATA wsaData;
SOCKET sendsock;
SOCKADDR_IN addr_Sock;
PHOSTENT pHost;
struct ReadBmp
{
BYTE* dwBuff;
DWORD dwSize;
};
#include "imgdecmp.h"
#include "imaging.h"
#include "initguid.h"
#include "imgguids.h"
#include <connmgr.h>
#pragma comment( lib, "cellcore.lib" )
CONNMGR_CONNECTIONINFO ConnInfo;
HANDLE hConnection;
GUID GUID_Network;
HRESULT hr;
HBITMAP hSShotBMP=0;
HDC hDC;
HDC hMemDC;
RECT lpr;
PAINTSTRUCT ps;
HGDIOBJ OldObj;
int ImageSize;
DWORD CALLBACK GetImageData(LPSTR pBuf,
DWORD dwBufMax,
LPARAM lParam)
{
ReadBmp* pRb = (ReadBmp*) lParam;
DWORD dwBytesRead = 0,
dwToRead = 0;
//
// Check if there is anything left to read from the file.
//
if(pRb->dwSize > 0)
{
//
// Calculate what amount to read
//
if(pRb->dwSize > dwBufMax)
dwToRead = dwBufMax;
else
dwToRead = pRb->dwSize;
//
// Read the buffer
//
dwBytesRead = pRb->dwSize;
//
// Decrease the amount to read for the next pass
//
pRb->dwSize -= dwBytesRead;
}
return dwBytesRead;
}
BOOL decodeImage1(BYTE* pBuf, int imgLength)
{
ReadBmp rbmp;
HDC hDC;
DecompressImageInfo dii;
rbmp.dwBuff = pBuf;
rbmp.dwSize = imgLength;
hDC = GetDC(NULL);
dii.dwSize = sizeof(dii);
dii.pbBuffer = pBuf; //szBuffer;
dii.dwBufferMax = imgLength; //sizeof(pBuf);
dii.dwBufferCurrent = 0;
dii.phBM = &hSShotBMP;
dii.ppImageRender = NULL;
dii.iBitDepth = GetDeviceCaps(hDC,BITSPIXEL);
dii.lParam = (LPARAM) &rbmp;
dii.hdc = hDC;
dii.iScale = 100;
dii.iMaxWidth = 10000;
dii.iMaxHeight = 10000;
dii.pfnGetData = GetImageData;
dii.pfnImageProgress = 0;
dii.crTransparentOverride = (UINT) -1;
HINSTANCE hDll = LoadLibrary(TEXT("imgdecmp.dll"));
if (!hDll) return false;
typedef HRESULT (*DecompressImageIndirect_t)(DecompressImageInfo *pParams);
DecompressImageIndirect_t DecompressImageIndirectProc = (DecompressImageIndirect_t)GetProcAddress(hDll, TEXT("DecompressImageIndirect"));
if (! DecompressImageIndirectProc)
{
FreeLibrary(hDll);
return 0;
}
HRESULT hr = DecompressImageIndirectProc(&dii);
if(SUCCEEDED(hr))
{
ReleaseDC(NULL, hDC);
return TRUE;
}
else
{
hSShotBMP = NULL;
return FALSE;
}
return FALSE;
}
BOOL decodeImage2(BYTE* pBuf, int imgLength)
{
IImagingFactory *pImgFactory = NULL;
IImage *pImage = NULL;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
hSShotBMP=0;
if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IImagingFactory,
(void **)&pImgFactory)))
{
ImageInfo imageInfo;
if (SUCCEEDED(pImgFactory->CreateImageFromBuffer(pBuf, imgLength, BufferDisposalFlagNone,&pImage))&& SUCCEEDED(pImage->GetImageInfo(&imageInfo)))
{
hMemDC=CreateCompatibleDC(GetDC(hWnd));
hSShotBMP = CreateCompatibleBitmap(GetDC(hWnd), imageInfo.Width, imageInfo.Height);
lpr.right=imageInfo.Width;
lpr.bottom=imageInfo.Height;
if (hSShotBMP)
{
OldObj=SelectObject(hMemDC,hSShotBMP);
pImage->Draw(hMemDC, &lpr, NULL);
SelectObject(hMemDC,OldObj);
}
DeleteDC(hMemDC);
pImage->Release();
}
pImgFactory->Release();
}
CoUninitialize();
return TRUE;
}
BOOL decodeImage(BYTE* pBuf, int imgLength)
{
OSVERSIONINFO vi;
memset(&vi, 0, sizeof(vi));
vi.dwOSVersionInfoSize = sizeof(vi);
VERIFY(GetVersionEx(&vi));
if (vi.dwMajorVersion>=5)
{
return decodeImage2(pBuf,imgLength);
}
else
{
return decodeImage1(pBuf,imgLength);
}
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
WSAStartup (MAKEWORD(2,2), &wsaData);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DeleteObject(hSShotBMP);
WSACleanup();
return (int) msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WWCLIENT));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
TCHAR szTitle[MAX_LOADSTRING]; // title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
hInst = hInstance;
SHInitExtraControls();
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WWCLIENT, szWindowClass, MAX_LOADSTRING);
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}
if (!MyRegisterClass(hInstance, szWindowClass))
{
return FALSE;
}
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
if (hMenuBar)
{
RECT rc;
RECT rcMenuBar;
GetWindowRect(hWnd, &rc);
GetWindowRect(hMenuBar, &rcMenuBar);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
wsprintf(string,TEXT("http://nuts.homeip.net"));
DWORD i=0;
hr=ConnMgrMapURL(string, &GUID_Network, &i);
ConnInfo.cbSize=sizeof(ConnInfo);
ConnInfo.dwParams=CONNMGR_PARAM_GUIDDESTNET;
ConnInfo.dwFlags=0;
ConnInfo.dwPriority=CONNMGR_PRIORITY_USERINTERACTIVE ;
ConnInfo.guidDestNet = GUID_Network;
hr=ConnMgrEstablishConnection(&ConnInfo, &hConnection);
return TRUE;
}
HWND CreateListView (HWND hWndParent)
{
HWND hWndList; // handle to list view window
RECT rcl; // rectangle for setting size of window
LV_COLUMN LVC; // list view column structure
InitCommonControls();
GetClientRect(hWndParent, &rcl);
hWndList= CreateWindow(WC_LISTVIEW, NULL,
WS_CHILD | WS_VISIBLE | LVS_REPORT ,
rcl.left, rcl.top, rcl.right - rcl.left, rcl.bottom - rcl.top - 20,
hWndParent, (HMENU)NULL, hInst,NULL);
if (hWndList == NULL )
return NULL;
LVC.mask=LVCF_TEXT | LVCF_WIDTH;
LVC.pszText=string;
LoadString(hInst, IDS_PID, string, 64);
LVC.cx=70;
SendMessage (hWndList, LVM_INSERTCOLUMN, 0, (LONG)&LVC);
LoadString(hInst, IDS_PROC, string, 64);
LVC.cx=120;
SendMessage (hWndList, LVM_INSERTCOLUMN, 0, (LONG)&LVC);
return (hWndList);
}
int SendCommand(char cmd)
{
int RDbytes,i,j;
//addr_Sock.sin_addr.s_addr = inet_addr((const char *)"89.109.18.29");
pHost=gethostbyname( (const char *)&"nuts.homeip.net" );
memmove(&addr_Sock.sin_addr.s_addr,*pHost->h_addr_list,sizeof(PCHAR));
addr_Sock.sin_family = AF_INET;
addr_Sock.sin_port = htons(333);
sendsock=socket (AF_INET,SOCK_STREAM,0);
connect(sendsock,(struct sockaddr *)&addr_Sock,sizeof(addr_Sock));
buffer[0]=cmd;
send(sendsock,buffer,1,0);
RDbytes=recv(sendsock, buffer, 2, 0);
RDbytes=*(WORD *)buffer;
if (RDbytes)
{
ZeroMemory(&buffer,RDbytes);
i=0;
j=0;
while (i!=RDbytes)
{
j=recv(sendsock, buffer+i, RDbytes-i, 0);
if (j==SOCKET_ERROR) break;
i+=j;
}
}
closesocket(sendsock);
return RDbytes;
}
void Refresh(void)
{
LPSTR CurChar;
LVITEM IT;
byte a;
ShowWindow(hWndListView,SW_SHOW);
SendCommand('P');
ListView_DeleteAllItems(hWndListView);
CurChar=(char *)&buffer;
a=*CurChar;
while (a!=0)
{
IT.mask= LVIF_TEXT;
IT.iItem=0;
IT.iSubItem=0;
IT.pszText=string;
mbstowcs((wchar_t *)&string, CurChar, 64);
SendMessage (hWndListView,LVM_INSERTITEM, 0, (LONG)&IT);
while (a!=0)
{
a=*CurChar;
CurChar++;
}
wsprintf((LPWSTR)&string,TEXT("%d"),*(DWORD __unaligned *)CurChar);
IT.pszText=string;
IT.iSubItem=1;
SendMessage(hWndListView,LVM_SETITEMTEXT,0,(LONG)&IT);
CurChar+=4;
a=*CurChar;
}
}
void Screen()
{
ShowWindow(hWndListView,SW_HIDE);
if (hSShotBMP)
{
DeleteObject(hSShotBMP);
hSShotBMP=0;
}
ImageSize=SendCommand('S');
if (ImageSize) decodeImage((byte *)buffer, ImageSize);
InvalidateRect(hWnd,NULL,false);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
static SHACTIVATEINFO s_sai;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDPM_REFRESH:
Refresh();
break;
case IDPM_SCREEN:
Screen();
break;
case IDPM_EXIT:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = hInst;
mbi.dwFlags |= SHCMBF_HMENU;
if (!SHCreateMenuBar(&mbi))
{
hMenuBar = NULL;
}
else
{
hMenuBar = mbi.hwndMB;
}
// Initialize the shell activate info structure
memset(&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
hWndListView = CreateListView( hWnd );
ShowWindow(hWndListView,SW_HIDE);
break;
case WM_PAINT:
{
GetClientRect( hWnd,&lpr);
hDC=BeginPaint( hWnd, (LPPAINTSTRUCT)&ps);
if (hSShotBMP)
{
hMemDC=CreateCompatibleDC(hDC);
OldObj=SelectObject(hMemDC,hSShotBMP);
BitBlt(hDC,0,0,lpr.right-lpr.left,lpr.bottom-lpr.top,hMemDC,0,0,SRCCOPY);
SelectObject(hMemDC,OldObj);
DeleteDC(hMemDC);
}
//wsprintf((LPWSTR)&string,TEXT("%d"),ImageSize);
//ExtTextOut(hDC,0,0,0,NULL,string,lstrlen(string), NULL);
EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
CommandBar_Destroy(hMenuBar);
PostQuitMessage(0);
break;
case WM_ACTIVATE:
// Notify shell of our activate message
SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -