Introduction to WIN32 Development (21): Copy, paste, and clipboard operations

Source: Internet
Author: User
Tags win32

I would like to remind you, read my Bo literature to the knowledge, do not use for actual development, or you will be your boss scolded: "Damn, where these things come, no one has ever done so." "If you don't believe it, the manager or technical director who froze the brain cells would say that," he said.

If a programmer with X years ' work experience (X will never be greater than 100) would say, "Why are you so immature?" "If you're being told that, don't you know you're not going to be sad or angry?" said the man.

I have been so educated by n individuals, but you guess my mood, I am very happy, joy. Why, then?

You might as well think about it, when a person said you are immature, you say what he really said, he is actually saying that he is very mature, because he cooked quickly rotten, full of stench, will appear to you immature, think carefully, is this the thing?

So, is it good to be mature? I believe that elementary school students have such common sense, when a fruit is ripe, what will happen? It will fall from the branches of the sky, and then the ruthless to the ground, smashed to pieces. Oh, so, you understand now, when others say I am immature, I will be very happy, I thought: "Fast faster, you are almost finished." ”

Well, after the cowhide is blown, music is a pleasure. Now let's get down to business, and today we'll get to know how to operate the pasteboard, that is, copy and paste the data. I don't know if people watch horror movies, anyway, I have to scare you now. This pasteboard operation, in fact, very painful, so, if in the actual development, I definitely use the CLR class to get, yes, this is my principle of doing things, which method is the easiest to use what kind of, what is this called? Efficiency is maximized, only people who have nothing to do is complicated by simple problems.

However, after all, we have to understand the Win32 under the operation of the pasteboard, so, I still use the API to solve, as for the CLR method, I believe you more than I will use, you do not believe, anyway, I believe, I am not a rookie, but I am a vegetable crane.

Read and write Pasteboard as we go to the toilet, first open the toilet door (call the OpenClipboard function), then the Big Bang (SetClipboardData or GetClipboardData), finished, Turn off the toilet door (call CloseClipboard).

I say it's a bit painful because of the 睺 of the operation, and we usually read and write some data different, the data written to the Clipboard by the operating system to take over, during which you can not read and write, like a public toilet is provided for you, you can not in the interior of the decoration, demolition of others.

I. Replication of data

I don't get too complicated here, just copy a bunch of text, which is also common. Look at the code first.

Copy content     
//Open clipboard     
openclipboard (HDLG);     
Empty the Clipboard     
EmptyClipboard ();     
Put something in the Clipboard     
HWND Hedt = GetDlgItem (hdlg, idc_edtcpy);     
WCHAR ntext[100];     
SendMessage (Hedt, Wm_gettext, (WPARAM), (LPARAM) ntext);     
Allocating memory     
hglobal Hgl = GlobalAlloc (gmem_moveable, sizeof));     
LPWStr lpstrcpy = (LPWSTR) globallock (HGL);     
memcpy (lpstrcpy, ntext, sizeof (WCHAR));     
GlobalUnlock (HGL);     
SetClipboardData (Cf_text, lpstrcpy);     
Close clipboard     
CloseClipboard ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.