A solution to the cumbersome ID copying and splicing links when selecting products for an e-commerce project

  • Since the recent e-commerce project needs to copy the product ID on a certain platform during the product selection process and then paste it into the table splicing link and put it on the shelf, it is very cumbersome and complicated, so I decided to write a software to replace this annoying process.

     


  • Product ID
    Product ID

During the product selection process, you need to copy a product ID of the platform first.

Click the copy button

 

Move the mouse to the product ID and a "Copy" button will be displayed. Click Copy.

Product ID copied successfully

It prompts that after the product ID is copied successfully, the content will be stored in the clipboard. 

splice link

 

Then splice the links so that they can be used for subsequent product listings of the software.


So far, the cumbersome operation problem has arisen. If you need to select hundreds of products every day, and copying, pasting, and splicing all the time, wouldn't it be a waste of your hands? So I thought of the following method!

Since the product ID is stored in the clipboard when you click the "Copy Button", wouldn't it be more effective if we write a small program to supervise the clipboard?

 Just do it! Code first!


 Window registration class

 
// 注册窗口类。

ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.hInstance = hInstance;
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wcex.lpszClassName = "RainbowTools";

	return RegisterClassEx(&wcex);
}

 Create a thread and loop to read windows messages, then create a window and hide it

 
// 循环读取windows消息 线程模块

static DWORD WINAPI GetMessage(LPVOID pParam)
{
	// 注册窗口类
	HINSTANCE hInst;
	hInst = GetModuleHandle(0);

	MyRegisterClass(hInst);

	// 创建窗口
	HWND hWnd = CreateWindow("RainbowTools", "Clipboard Monitor", WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);

	// 隐藏窗口
	ShowWindow(hWnd, SW_HIDE);

	// 循环接收消息
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return (int)msg.wParam;
}

 Process the main window's messages (monitor the clipboard content), determine the content format and detect whether it is pure numbers.

 
//  处理主窗口的消息(监控剪贴板内容)
//
//  WM_DRAWCLIPBOARD	-	粘贴板内容监控

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HWND hwndNextViewer;
	switch (message)
	{
	case WM_DESTROY:
		// 设置Viewer链,移除本Viewer。
		ChangeClipboardChain(hWnd, hwndNextViewer);
		PostQuitMessage(0);
		break;
	case WM_CREATE:
		// 在窗口创建时,在粘贴板Viewer链中增加一个Viewer
		hwndNextViewer = SetClipboardViewer(hWnd);
		break;
	case WM_CHANGECBCHAIN: // Viewer链中的节点变化时会收到此消息
						   // 在链中增加本Viewer后,位于链的第一个节点
						   // 当链中有Viewer移除时,链中的第一个Viewer会收到此消息
						   // 如果是本Viewer的下一个Viewer移除,那么更新
		if ((HWND)wParam == hwndNextViewer)
			hwndNextViewer = (HWND)lParam;
		// 否则将消息向下一个Viewer传递
		else if (hwndNextViewer != NULL)
			SendMessage(hwndNextViewer, WM_CHANGECBCHAIN, wParam, lParam);
		break;
	case WM_DRAWCLIPBOARD: // 剪贴板的内容改变时执行此处代码
		// 打开剪贴板
		if (OpenClipboard(hWnd))
		{
			// 判断数据格式
			if (IsClipboardFormatAvailable(CF_TEXT))
			{
				HGLOBAL hClip1 = NULL;
				// 读取数据
				hClip1 = GetClipboardData(CF_TEXT);
				TCHAR *pBuf1 = NULL;
				pBuf1 = (TCHAR*)GlobalLock(hClip1);

				GlobalUnlock(hClip1);

				if (pBuf1 != '\0') 
				{
					CString Targets = NULL;
					Targets.Format(TEXT("%s"), pBuf1);

					// 判断 Targets 变量是否为数值
					if (Targets.SpanIncluding(_T("0123456789")) == Targets)
					{
						CString Links = NULL;
						Links.Format(TEXT("https://mobile.yangkeduo.com/goods.html?goods_id=%s\r\n"), Targets);

						CString Files = NULL;
						Files.Format(TEXT("%s\\%s-ID.txt"), szSelfPath, Times);

						CFile file(Files, CFile::modeWrite | CFile::modeCreate | CFile::modeNoTruncate);
						//将文件指针指向末尾
						file.SeekToEnd();
						//写入文件
						file.Write(Links, Links.GetLength());
						//关闭文件
						file.Close();
					}
				}
			}
		}
		// 关闭剪贴板
		CloseClipboard();
		// 将消息发送给Viewer链中的下一个窗口
		SendMessage(hwndNextViewer, WM_DRAWCLIPBOARD, wParam, lParam);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

Effect demonstration


Complete tool download

[Download address 1] icon-default.png?t=N6B9https://wwrd.lanzoum.com/iqMHR148jsvc
[Download address 2] icon-default.png?t=N6B9https://download.csdn.net/download/qq_39190622/88152958

Guess you like

Origin blog.csdn.net/qq_39190622/article/details/131894822