A few days ago on the internet to see a software called sncopy, used to help fill in the serial number (SN). The idea is still very good. Install the software often to fill in the serial number, and many series number should be divided into sections to fill out, can not use CTRL + C and CTRL + V (copy and paste) to a one-time fix, only section of the copy and paste, very troublesome. Sncopy is here to help us solve this problem. Feel this is not very difficult to do, that is, from the Clipboard to get the entire serial number, and then decompose, and then fill in. So you do it yourself!
First, create an application snpaste based on the dialog box.
Second, write code
We use Shift+v as a shortcut to quickly fill in the entire serial number at once. A hotkey is registered first. In InitDialog (), add the following code:
if(!::RegisterHotKey(this->GetSafeHwnd(),0x3333,MOD_SHIFT,0x56))
{
::AfxMessageBox("热键注册失败!");
this->CloseWindow();
}
The hotkey must be logged off before the program exits. In OnClose ():
::UnregisterHotKey(this->GetSafeHwnd(),0x3333);
Response Hotkey:
Lresult Csnpastedlg::onhotkey (WPARAM wparam,lparam LPARAM)
{if (! OpenClipboard ())
{:: AfxMessageBox ("Unable to open the Pasteboard!") ");
return-1;
}
CString str=cstring (char*):: GetClipboardData (Cf_text));
? CString oldstr=str;//Save the original string
CloseClipboard ();
Str. Trim ();
CString strtemp;
int FIND_I=STR. Find ('-');
if (FIND_I!=-1)//series number has "-" in order to divide the serial number string
{
while (Find_i!=-1)
{
Strtemp=str. Left (find_i);
Str=str. Mid (find_i+1);
Find_i=str. Find ('-');
Sleep (100);//Because the Clipboard operation is slow, must add a certain delay, otherwise the data will be wrong.
This->sendstrtoclipboard (strtemp);//Copy the decomposed bar string to the Clipboard
THIS->PERFORMCTRLV ()//imitate keyboard keystroke Ctrl + V
This->performclicktab ()//Imitate Keyboard keystroke tab
}
if (!str. IsEmpty ())
{This->sendstrtoclipboard (str);
This->performctrlv ();
This->performclicktab ();
}
}
There is no "-" in the else//serial number string, which is divided by pre-set lengths.
{
while (!str. IsEmpty ())
{
Strtemp=str. Left (This->m_spinctrl. GetPos ());
Str=str. Mid (This->m_spinctrl. GetPos ());
Sleep (100);
This->sendstrtoclipboard (strtemp);
This->performctrlv ();
This->performclicktab ();
}
}
Sleep (100);
This->sendstrtoclipboard (OLDSTR)//Restore the data on the original clipboard
return 1;
}