⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmcopyclient.cpp

📁 这是一本学习 window编程的很好的参考教材
💻 CPP
字号:
// WMCOPYClient.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "WMCOPYHDRS.h"

DWORD pID;
HWND hServer;

BOOL WINAPI TransferData(DWORD dwMsg, const _TCHAR *Buffer, DWORD dwBytes) 
{
  BOOL bSend;
  COPYDATASTRUCT cpStructData;
  LPWM_DATASTRUCTURE lpMsg;
  cpStructData.cbData = dwBytes + _WM_HEADER_SIZE;
  lpMsg = (LPWM_DATASTRUCTURE)LocalAlloc(LPTR,cpStructData.cbData);
  lpMsg->hClient = NULL;
  lpMsg->iMessage = dwMsg;
  lpMsg->cbSize = dwBytes;
  cpStructData.lpData = lpMsg;
  if(Buffer!=NULL){
	  SETSTRLEN(lpMsg->Data,dwBytes);
	  MEMCPY(lpMsg->Data,Buffer,dwBytes); 
  }

  bSend = SendMessage(hServer,WM_COPYDATA, (WPARAM)hServer,(LPARAM)&cpStructData);
  return(bSend);
}  

int main(int argc, char* argv[])
{
	_TCHAR szWndName[256];	
	_TCHAR szData[256];
	_TCHAR szSort[5];
	
	pID = GetCurrentProcessId();
	STPRINTF(szWndName,_T("PROCESSID %.X"),pID);
	SETCONSOLETITLE(szWndName);
	if((hServer = FINDWINDOW(SERVERWNDCLASSNAME, NULL)) == NULL){
		TPRINTF(_T("WMCOPYCLIENT: Please launch the server!\n"));
	}
	else
	{
		while(TRUE) {
				TPRINTF(_T("Enter 1 to sort in ascending order:\n"));		
				TPRINTF(_T("Enter 2 to sort in descending order:\n"));		
				TPRINTF(_T("Enter 3 to display the entered value on the server:\n"));
				TPRINTF(_T("Enter 4 to stop the server:\n"));
				_getts(szSort);
				if(TCMP(szSort,_T("1")) == 0){
					
#if UNICODE && _UNICODE
					TPRINTF(_T("This option is invalid for UNICODE and _UNICODE.\n"));
#else
					TPRINTF(_T("Enter the data to be sorted in an ascending order:\n"));
					_getts(szData);
					TransferData(WM_ASCENDING,szData,STRLEN(szData));
#endif
				}
	            
				if(TCMP(szSort, _T("2")) == 0) {
#if UNICODE && _UNICODE
					TPRINTF(_T("This option is invalid for UNICODE and _UNICODE.\n"));
#else
					TPRINTF(_T("Enter the data to be sorted in an descending order:\n"));
					_getts(szData);
					TransferData(WM_DESCENDING,szData,STRLEN(szData));
#endif
				}

				if(TCMP(szSort, _T("3")) == 0) {
					TPRINTF(_T("Enter the data to be displayed on the server:\n"));
					_getts(szData);
#if UNICODE && _UNICODE
					TransferData(WM_DISPLAY_TEXT,szData,STRLEN(szData)*2);
#else
					TransferData(WM_DISPLAY_TEXT,szData,STRLEN(szData));
#endif
				}

				if(TCMP(szSort, _T("4")) == 0) {
					TPRINTF(_T("Quiting the server and the client:\n"));
					TransferData(WM_QUIT_SERVER,szData,STRLEN(szData));
					break;
				}
         }
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -