SDI里面怎样利用这个win32程序????我手头有一个win32应用程序,作为客户端,实现抓取客户端的屏幕.现在我想在SDI里也要实现这个功能,不知这个win32程序能不能拿来用?????win32的程序如下:#include "stdafx.h"#include "stdlib.h"#include "resource.h"#include "stdio.h"#include "winsock2.h"#include "conio.h"#include "windows.h" DWORD NewThreadId; HWND hWnd1;LRESULT CALLBACKWndProc(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ // TODO: Place code here. MSG msg; int bool1; DialogBox(hInstance, (LPCTSTR)IDD_DIALOG1,NULL, (DLGPROC)WndProc); while ((bool1=GetMessage(&msg, NULL, 0, 0))!=0 && bool1!=-1) { TranslateMessage(&msg);DispatchMessage(&msg); }return 0;}DWORD ThreadFunc(char *IP_value){unsigned long IP_A=(unsigned long)IP_value;WSADATA a;if(WSAStartup(MAKEWORD( 2, 2 ),&a)!=0){MessageBox(NULL,"failure-load winsok", "Error", MB_OK); return 0;}SOCKET client; //The socket used to linksockaddr_in server_add ; //used in the function of connectclient=socket(AF_INET,SOCK_STREAM,IPPROTO_IP);if(client==INVALID_SOCKET){MessageBox(NULL,"failure-create winsok", "Error", MB_OK); return 0;} //Psockaddr_in server_add;server_add.sin_family=AF_INET;server_add.sin_port=htons(5150); server_add.sin_addr.S_un.S_addr=IP_A;//inet_addr("192.168.0.9"); if(connect(client,(sockaddr *)&server_add,sizeof(server_add))==SOCKET_ERROR){MessageBox(NULL,"failure-connect", "Error", MB_OK); return 0;} int count=0; //count the receive number of one time; BITMAP bmp;char *New_start; char buf_recv[20000]; int counter=0; //count the total number of receive char *Mem_real_pointer; char *pointerMem; int all_size; count=recv(client,(char *)&bmp,sizeof(BITMAP),0); if(count!=0 && count!=SOCKET_ERROR) { if(count==sizeof(BITMAP)) { //allocat the buffer to receive the BMP data all_size=bmp.bmWidthBytes*bmp.bmHeight; pointerMem=(char *)GlobalAlloc(GMEM_FIXED,all_size); Mem_real_pointer=(char *)GlobalLock(pointerMem); if(Mem_real_pointer==NULL) { MessageBox(NULL,"Memory allocated failure", "Error", MB_OK); //分配内存失败 } else { //allocate success counter=0; count=0; char *cpy_result; while(counter<all_size) { New_start=(char *)((char *)Mem_real_pointer counter); count=recv(client,(char *)buf_recv,20000,0); if(count==SOCKET_ERROR) //this indicate that the link is break up { break; } cpy_result=(char *)memcpy(New_start,buf_recv,count); if(cpy_result!=New_start) { break; } counter=counter count; } } } } LPBITMAPINFO lpBmpInfo; lpBmpInfo = (BITMAPINFO*) new BYTE[sizeof(BITMAPINFOHEADER)]; lpBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpBmpInfo->bmiHeader.biPlanes =bmp.bmPlanes; lpBmpInfo->bmiHeader.biBitCount = bmp.bmBitsPixel; lpBmpInfo->bmiHeader.biCompression = BI_RGB; lpBmpInfo->bmiHeader.biSizeImage = 0; lpBmpInfo->bmiHeader.biClrUsed = 0; lpBmpInfo->bmiHeader.biWidth = bmp.bmWidth; lpBmpInfo->bmiHeader.biHeight = bmp.bmHeight; HDC hdc = CreateCompatibleDC(NULL); LPVOID lpBits; PBITMAP holdbmp,hbmp; hbmp=(PBITMAP)CreateDIBSection(hdc,lpBmpInfo,DIB_RGB_COLORS,&lpBits,NULL,0); delete lpBmpInfo; DeleteDC(hdc); if(hbmp==NULL) MessageBox(NULL,"create BMP failure", "Error", MB_OK); else { char *cpyresult; cpyresult=(char *)memcpy(lpBits,Mem_real_pointer,all_size); if(cpyresult!=lpBits) { printf("copy mem last failure!"); } HDC dcImage=CreateCompatibleDC(NULL); holdbmp=(PBITMAP)SelectObject(dcImage, hbmp); GetObject(hbmp,sizeof(bmp),&bmp); RECT ScreenSaved; //get IDC_EDIT1 'S screen place coordinate GetWindowRect(GetDlgItem(hWnd1,IDC_EDIT1),&ScreenSaved); StretchBlt(GetWindowDC(GetDlgItem(hWnd1,IDC_EDIT1)),0,0,ScreenSaved.right-ScreenSaved.left,ScreenSaved.bottom-ScreenSaved.top,dcImage,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY); SelectObject(dcImage, holdbmp); DeleteDC(dcImage); }GlobalFree(pointerMem);closesocket(client);WSACleanup(); return 0;}LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{//char string[100];hWnd1=hWnd; switch (message){case WM_INITDIALOG: return TRUE;case WM_COMMAND:if (LOWORD(wParam) == IDC_BUTTON2) {EndDialog(hWnd, LOWORD(wParam));return TRUE;}if(LOWORD(wParam) == IDC_BUTTON1) {unsigned long IP_value; char string_IP[30];GetWindowText(GetDlgItem(hWnd,IDC_EDIT3),string_IP,30);IP_value=inet_addr(string_IP); CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) ThreadFunc,(LPVOID)IP_value,0,&NewThreadId);}break;case WM_DESTROY: PostQuitMessage(0); default:return DefWindowProc(hWnd, message, wParam, lParam);} return 0;}学习了..up当然可以移到SDI上用,只要把截取屏幕那部分代码拿出来再作适当的改动就可以了,另外在SDI里是封闭了DC的,你得先获取VIEW的DC后作为你现在这段代码的DC就可以了!! 参考: HDC hDC = GetDC(m_hWnd)为什么要改成SDK的?基本上不用做改动就可以复用。只需要吧main函数改成别的函数名,然后在你需要调用的地方调用即可。添进去后,似乎把错误改的差不多了。,又出现如下错误:testView.obj : error LNK2001: unresolved external symbol
[email protected] : error LNK2001: unresolved external symbol
[email protected] : error LNK2001: unresolved external symbol
[email protected] : error LNK2001: unresolved external symbol
[email protected] : error LNK2001: unresolved external symbol
[email protected] : error LNK2001: unresolved external symbol
[email protected] : error LNK2001: unresolved external symbol
[email protected] : error LNK2001: unresolved external symbol __imp__inet_addr@4Debug/test.exe : fatal error LNK1120: 8 unresolved externalsError executing link.exe.加#pragma comment( lib, "ws2_32.lib" )keiy() 谢谢你啊困扰我的问题终于解决了。你怎么知道要加#pragma comment( lib, "ws2_32.lib" ),是什么道理清楚嘛??不管怎样,马上分数送上咯咯………………