VB mouse drawing basic data summary
In view of the programs of the mouse drawing in the first half of the year, the previously collected information will be summarized, and the VB enthusiasts who have been searching for the same time before and I have been convenient, while welcome to communicate and correct. Here I have to write to Luo Wei, I hope everyone should not blame me. Because many of our information is too poor, practical or speaking, it is too weak. I hope to be able to understand. I am also a person who has just got to be entry and writes a limited experience and sharing everyone.
The prodigal comparison can be said to be a project that every VB programmer wants to try and exercise. Learn the mouse drawing, you learn the Windows mouse operation, screen mode mapping mode, plot mode, Windows GDI (graphics device interface). You will know that the computer's equipment is limited, that is, resources are limited, the resources here, that is, the memory, computer screen, mouse also have a keyboard, and some GDI objects, such as brush, painting brush, Palette. Some resources, you use others (other applications here), you can't use it, for example, your app captures the mouse (as for caught the mouse, then say it later), but does not release the mouse, so others The application does not know the mouse message (people who don't understand the Windows message mechanism should learn about Windows messages, and the message response mechanism. The mouse drawing is not to pass the message to our program, and then have our program processing. ..), someone else's application has no way to operate with a mouse. So the application of the system resources should be a programmer to avoid it. It is also not allowed by the operating system. The operating system is a big program for adjustment applications, also a management hardware, the underlying program for allocating resources, and its level is higher than your program level, so it can manage your application. You have to use system resources, you must request the operating system to get allocated, you can use it. The mouse drawing is in a canvas (your application's customer area), using the mouse drawing. Drawing is a vector pattern of vector mode, you can also convert images to grid mode. Here, what you have to understand is: What is a customer area, I believe that many people have been programmed for a long time, and I don't know what is a customer area. What is a vector pattern of graphics, what is the image of the grid mode, and so on. VB programming has a benefit, that is, the starting point is high, unlike the VC, you have to get yourself, a little thing will not, you will kill death. How is the control drag and drop, every programmer should stand on the shoulders of others and write their own procedures. In the process of writing the program, based on the procedure of others, by improved or modify, use the basic idea of integrated and analyzing, and edit their own procedures. This is called "brought". Of course, as a programmer, after using someone else, you must have basic respect for others, such as keeping others' copyright statements (if any, or if you know); send an email to him, tell him You use his own things, ask him questions; in the process of the program, you will express your gratitude to those who provide all kinds of help from free or paid; also state your copyright, reserve the right, make a warning, etc.
Below, I will make a summary of the materials you have collected about the mouse drawing, and summarize your experience in the process of compiled programs.
First, give you a directory index. 1, interface production 2, mouse function and operation 3, customer area, window, screen 4, scrolling drawing area 5, screen mapping mode, drawing mode, principle of rubber band box, GDI and drawing function, brush, brush, padding mode , Drawing steps, the preservation of drawing results, the production of the syndrome is always upset, you can write your code one day, but your interface you may consume you a week. So here I have given the problem of interface production. Similarly, making good interfaces, you can do on the basis of others, you can do it yourself (if you have time and tolerance). Since the production interface is not a text to be explained, I will provide you with your own interface. Very simple, don't laugh. Also provide source code, don't send me an email, because I may have no time to reply you to the demand for source code. Please visit my email: @. CoM, password is:. After logging in, enter the delivery box, write down your own mailbox in the email address, forward it to your own mailbox. But please don't change your password, it is not your own one. My interface is as follows:
The mouse function and operation of the mouse generally have two keys, which may not be considered because of the mouse drawing process. It is because there are two keys, so we have to move your brain, think about how to use all of them. In the program, when we use the color tool, use the left button to get the foreground color, right click on the background color, very good to take the two keys. Its function is to click, drag, move. You click, maybe it is to draw points, more big, just look at your brush, the size of the painting brush. Drag, generally used to draw lines, rectangles, and ellipses. You move it, you have to change your drawing, draw the size of the graph or draw the mouse casual draw. The operation of the mouse is of course to see the user's intention, click which click may be to choose, to draw, drag may be to choose the range, draw graphics; mobile is you have to do something else. So you are in the process of use, of course, I don't want your mouse to not listen to you, when you want to point, you can't get it, you release the mouse, but the program is still drawing (as long as you move the mouse) . So we have to completely control your mouse in the app, you have to judge the state of your mouse, it is pressed, which button is pressed, there is no move, there is no, wait, right These situations and then respond correctly in the mouse message. However, because there are many tools, we have to set some variables to mark the tools we are using, so that different effects are drawn according to the tool in response to the various messages of the mouse. For example, draw points, spray guns, color tools, filling tools, selection tools, etc.
The reason is to talk about the mouse operation because each drawing is carried out in a certain step, and the message responds to each step is different. In my program, I think it should be drawing operations in the mouse. There are three steps for painting lines. The first step, first click (respond to the mouse to press the message) to determine a starting point, the second step is moved to the destination location (respond to the message moved by the mouse), the third step click to determine the end point (respond to the mouse, Loosen message). It can be seen that in such a simple painted straight line operation, several messages in the mouse have a response. So after we select every drawing tool, we should consider how to respond to three basic messages in each step (press, move, release), this is a more important issue. The problem of mouse cursor: I believe some people still have doubts, so here is Luo. If you want to use the default cursor different from Windows on a control of your window, do this: MousePointer = VBCUSTOM (it's worth 99, said it is user-defined, so you can also Use mousepointer = 99 in the program, then change Mouseicon's icon to your own cursor file ("icon ..." button next to you, then select a cursor file). Of course, you can also change the mousemove message of this control: mousepointer = vbcustommouseicon = loadPicture ("cursor.cur") Don't forget to change in the Form's Mousemove message, as long as this sentence is enough: mousepoint = vbdefault, otherwise Your Form is always only the cursor you define your own.
Exterior: If you have four mouse, how do you respond to your mouse message, Windows needs you to respond? (Individuals think that it will not be required to handle the message of each mouse). Maybe one day, you may draw with others (maybe your lover), so you don't have to grab the mouse. . .
Customer area, window, screen in the VB program, generally using the PictureBox control to do the plot area. Due to the toolbar, the status bar and other controls include the drawing toolbox, the existence of the pigment box, Picturebox generally does not spend all customer districts. As far as I understand, the customer area is the window part of the user freely. That is, in addition to the title bar, menu, scroll bar, border, toolbar, and status bar outside. In addition to these areas, because you draw in the drawing program, Windows will not let you draw graphics to the top of these windows. The text handler is also like this. Because these ranges are not part of the user who can freely operate, the client area is called the window portion other than these areas. Sometimes, the customer area may also include the part of the toolbar, and the part of the status bar, because the toolbar and status bar occupying the toolbar and status bar will be used by the user, so I I feel that the client area should include the partial window occupied by the toolbar and status bar, because these can be freely used by the user, after all, there is no toolbar and status bar, we also use the program, and the area of the drawing is larger. Understanding the customer district, the understanding of the window is easy, that is, the part of your application takes up the screen, and anything in your window will not draw to the window of other applications. Others will not draw into your window. That is to say, you can't see the contents of other applications in the window of your application. As for the screen, this is not explained, you only use one screen (the display of the monitor), you must not see something outside the screen. However, if you have two monitors, you move the window to the edge of the screen, you will see the part of the window you can't see in this screen in another screen. If you have three screens, Hoho, it's cool! ! ! There are so many, the purpose is that system resources are limited, and each window will occupy a part of the screen, the client area, and each control (visible) will also take a part of the window. These things will use light (if I don't say it). Scrolling the drawing area I said, in VB is the PictureBox control, but Picturebox does not support scrolling. The picture is big, and some parts are not displayed, so we must let him scroll to display the contents of the Picturebox size. I don't know what method is the best, but after some things, I think that the method of completing the task is the best way. Sometimes, you might waste a lot of time, have not achieved the goal in order to find an efficient, fast way, or more technically content. In this time, if you use the most stupid method, you may have realized your function. Here, odd kinemics is what I don't advocate. After all, the method skills are not the purpose, just to complete the means of tasks. I will find a way and can roll it.
Screen mapping mode, drawing mode screen mapping mode is what it is: The graphic display metrics. Your monitor may be a 17-inch flattening (this 17-inch refers to the length of the diagonal), how many centimeters are 17 inches? 43.18 cm (1 inches equal to 2.54 cm). So how many pixels? If your monitor is using 1024 * 960 pixel mode, you should calculate how much pixels of 17 inches, if the resolution is 800 * 600 pixel mode, then calculate. If your straight line has 3 cm long, but on the screen, the display always uses pixel to measure, so it is converted to the metric, about. Moreover, the most favorite unit of foreign is in inch, and the aspect of the control inside VB is always used (TWIPS) (: Metrology unit, equal to "pound" 1/20, inch 1/14440. Centimeter has 567 缇. Pixels: Monitor or Printer resolution minimum unit. If you click on the desktop, select Properties, select the Settings card, click the Advanced button. There will be a DPI settings in it. General "Normal size (96 dpi)". The meaning of DPI is DPI (DOTS Per inch). So we can get the following conversion formula: 1 twip = 1440 TPI / 96 DPI = 15 Pixels. By the way, point other unit: pound : Refers to the high metric unit of the printed character. 1 pound equal to 1/72 inches, or approximately 1 cm 1/28. In case: 2.54 cm screen mapping mode is the length of the pixel, if it is 1: 1 If the pixels are shown as a square, if not, it is a rectangular. There is also a mapping mode to use a centimeter instead of one meter (or even more), because our monitors are only so big, you are so small The world is displayed on the screen, which is only mapped to small by mapping. This is very similar to the scale of the map, 1 to how many thousand. Drawing mode is another thing. In VB The PictureBox's DrawMode property is set. To learn how to draw a picture, you have to say the foreground color and background color. The foreground color is the color of the drawing on the canvas, the background color is the color of the canvas, if the foreground color and background color is The same, you will not see the graphic drawn. As for how to choose the foreground color and background color, you will see your artwork and appreciation. It is assumed that the foreground color is black, the background color is white, when you use the mouse When drawing, for the copy mode (DrawMode = VBCopy, you draw a black line is a black line, the foreground is changed to green, painting a green line is a green line; for reverse draw mode (drawmode = vbinvert), you The foreground color is black or red, the line you draw is always the background color reversal color - black, that is, no matter what the foreground color is color, you draw straight, see all on the screen It is black (background color inversion color, the background color is white). Using this feature, we can basically implement the technique of rubber bands (see later described later).
The function of the rubber band box is like this: the start position in the mousetap, hold the mouse button, move the mouse, then the current location of the mouse off is offset from the starting position, then use the Picturebox's line function A rectangular box is drawn between the starting position of the mouse and the current position. The term "rubber band" is because this frame will be named with the movement and decrease of the mouse. When you release the mouse button, this box will remain on the screen. This prompt tells you how to create a rubber band in Visual Basic. It is easy to draw a box in the form or the Picture box control, but the function of the rubber band needs you to disappear when you move in the mouse and draw a new frame. The method of solving this problem is in the DrawMode property. DrawMode's default setting is VBCopypen, drawing a solid line, but this does not meet our requirements. Instead, we will use vbinvert this setting, which means that the line operation like the LINE method uses the color tone opposite to the form or the Picture Box control. Therefore, if the background color is white, then vbinvert will draw a black line, which is the same. Any colors in the palette are like this, which solves two problems:
This box is always visible relative to the background. If we draw again again, then the color will reverse again, be the same value as the original color, so that the window is gone.
Then, the method is the following: When the user presses the mouse button, the current coordinates of the mouse will be recorded. This will be used for the angle of the positioning box. At the same time, set the "Drawing" tag (FLAG) to true (TRUE). When the mouse moves, the previous box will be re-draw once to be deleted. This step is not in the first binfoot, but this step is needed. When the mouse moves, draw a box between the start coordinates and the new coordinates. When the mouse button is released, set the "Drawing" tag to false.
(Yet notked ...)