The play window process, I guess some people just see stuff related with the process will become excited, huh, huh! Well, take a look at what the API? As follows:
Private Declare Function GetWindowThreadProcessId Lib Thread (thread) Process (procedure) Id (ID), combination: a window to get the process of the current thread ID. As for what the process ID to the use of their own 32 after the in-depth programming to know.
see parameters, ByVal hwnd As Long, ha ha, are familiar with it, an hWnd handle. lpdwProcessId As Long This is the process we need the ID, the old rules, the new standard EXE, add a CommandButton, properties: Caption = Get window process ID. Code is as follows:
Private Declare Function GetWindowThreadProcessId Lib
GetWindowThreadProcessId Me.hwnd, PID
MsgBox the. First look at the first argument, ByVal hwnd As Long, another handle to the (Q: nonsense! A: Do not you taught ah), lpdwProcessId As Long, this will pay attention, look at the parameters passed way is to pass ByRef (Q: Oh, do not know what you mean? A: do not know? back to see the process functions in this chapter), that address is passed ByRef, the process can change the parameters passed value. Got it? Girl, do not understand, then go back and read it! Now understand the transfer mode, which means that we declare the PID is the process used to obtain the window ID, and powerful ah.
F5, to run it, click on Command1, PID out,cheap UGG boots, right? Did not come out I'll jump from the tenth floor.
warm tips ^ _ ^: hWnd handle can be passed to other windows, other windows can also obtain the process ID. Next we look at
Set (set), Set what? Of course, Window (window) easier, the first lists several common API:
SetWindowLong, SetWindowPos, SetWindowRgn, SetWindowText
then the above.
First we look at the SetWindowText, GetWindowText we have said above the API, GetWindowText is used to get the window text, and this just the opposite. You can now look at the surface meaning of Set (set) Window (window) Text (text), good enough to understand this, we already know the API is a set text window, and then we went to the API browser, look for the API , as follows:
Private Declare Function SetWindowText Lib A total of two, the first ByVal hwnd As Long I would not have said, the incoming handle chanting, and the second ByVal lpString As String, which is a string variable declared lpString can imagine, there need to pass a string , Well, to start practice. Create a new Standard EXE, and then add a TextBox control, and then add a CommandButton, write the following code:
Private Declare Function SetWindowText Lib ) As Long
Private Sub Command1_Click ()
SetWindowText Text1.hwnd, seems easier than the previous, but I still have to look long-winded, first passed in the Text1 handle the first parameter, so we need to operate API know which window, and the second is a string variable, so here is what we need to pass the text. Well, F5 to run, click on Command1, OK.
look SetWindowPos, can be said that this API can be seen as setting the window location, but the final effect depends on the realization of the parameters we pass, well, in the API browser, find the API, as follows:
Private Declare Function SetWindowPos Lib ) As Long
Oh! Boy, this API seems a bit complicated ah? But do not worry, I'm here Well, I'll help you make good analysis, here also please do me a person of light, must put themselves into in, we are not more interesting to analyze this? Well, no BS, look at the first argument:
ByVal hwnd As Long Here, I will not say, and pass the window handle
ByVal hWndInsertAfter As Long Well, look this! hwndInstrAfter, you can see which packages are hwnd letter characters, then you may not have said before that I do, as long as the package letter to see a hwnd handle incoming characters should be Well? Oh, yes, you are smart, I remember I had to say it! Here boast about you, Do not be proud ah! Now we Think about what parameters should be passed this place! Open MSDN, I am sorry in English, here I'll note Fangshanglai translated as:
hWndInsertAfter - Long, window handle. The list in the window, the window handle hwnd is placed behind the window. One may also use the following values:
HWND_BOTTOM the bottom of the window in the window list
HWND_TOP Z series will be placed in the top of the window; Z sequences representative hierarchy, the window level for a given sequence of window display the window placed
HWND_TOPMOST top of the list, and any of the top of the window at the front of
HWND_NOTOPMOST the window on top of the list, and the top of the window at the back of any
can see this place for us to choose four parameters, generally we will use the third and fourth constant API API constants, these constants can be API API found in the browser, but the specific functions to achieve what I think we all know, write it behind!
look back a few x, y, cx, cy, respectively, for the Long variable, what I have said before, SetWindowPos to set the window position can be viewed as Well, so here of course is to pass the relevant coordinates, If omitted or 0, they can try it.
ByVal wFlags As Long, this argument, I said, look at the character Flags, Oh, are familiar with it, so here we need to pass the identity of the relevant constants, we previously studied by constant analysis method Analysis, Set (S) Window (W) Pos (P) = SWP_, you can see a constant related to it? Here I note the related constants made up all look down, as follows:
SWP_DRAWFRAME draw a frame around the window to hide the window
SWP_HIDEWINDOW
SWP_NOACTIVATE not activate the window
< br> SWP_NOMOVE to maintain the current position (x and y settings will be ignored)
SWP_NOREDRAW window does not automatically redraw
SWP_NOSIZE maintain the current size (cx and cy are ignored)
< br> SWP_NOZORDER to maintain the current position in the list window (hWndInsertAfter will be ignored)
SWP_SHOWWINDOW display window
SWP_FRAMECHANGED forced a WM_NCCALCSIZE message into the window, even if the window size has not changed
So I said, a concrete realization of such an API function that he depends on the parameters you pass. Suppose we need to achieve here is always set in front of a window function, first create a new Standard EXE, enter the following code:
Private Declare Function SetWindowPos Lib As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = & H2
Private Const SWP_NOSIZE = & H1
Private Sub Form_Load ()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
Now we start the analysis, the first argument to the handle, the second what I have said before, what passed in achieving what function parameters, here we are to achieve a permanent home in front of the window function,Discount UGG boots, so Incoming HWND_TOPMOST constant, in fact, now see the coordinates of the window if you do not want to change the specific location, here from time to 0, and then look behind the wFlags, I passed two constants, the two constants more information, please Look at the top to know, do not change the main window position and size of the window does not change the premise is set before the window, the other constants if we are interested can see for yourself.
last one, look SetWindowRgn, I have to explain about it, the API functions are implemented it is to change the window appearance, which is shaped windows we said, through this API we can change the window into any shape, in the API browser to find the API, as follows:
Private Declare Function SetWindowRgn Lib
Well, the first argument, a handle. The second parameter, Long variables, what we need to pass in here will be mentioned below. Third, Boolean variables, can explain this need to pass a Boolean value, Redraw to redraw the meaning, so if we use this API to change the window shape, where the need for True, said the re-painting the window.
now create a new standard EXE, and then set the Form's ScaleMode 3-Pixel, we know that Windows is in pixels, so use this API to set the time for processing in pixels the window appearance . Then the BorderStyle set to 0-None, so see more clearly. Well, write the following code:
Private Declare Function SetWindowRgn Lib Lib >
Dim hRgn As Long
hRgn = CreateRoundRectRgn (0, 0, Me.ScaleWidth, Me.ScaleHeight, 10, 10)
SetWindowRgn Me.hWnd, hRgn, True
End Sub
I have to say about this I used an API, mainly because of the use SetWindowRgn API and other API is the need to work together, let us look at the API CreateRoundRectRgn . As follows:
overall means: create rounded rectangle. Here we suggest a technique, the general API functions in the package are representative of Rgn characters can change the appearance of the object. Can see we use the two API, one is SetWindowRgn (Rgn), one is CreateRoundRectRgn (Rgn), hope you can understand the common ground.
parameters: x1, y1, x2, y2, x3, y3 These are the coordinates of the specific described in the following:
X1, Y1 ---------- Long , rectangular upper left corner of the X, Y coordinates
X2, Y2 ---------- Long, rectangular bottom right corner of the X, Y coordinates
X3 ----- -------- Long, wide rounded oval. Ranging from 0 (no rounded corners) to the rectangle width (full circle)
Y3 ------------- Long, rounded oval high. Ranging from 0 (no rounded corners) to the rectangle height (full circle)
So the above code is specific to pass CreateRoundRectRgn create a rounded rectangle object, and then to change the window by SetWindowRgn appearance.
Tip: Use CreateRoundRectRgn can create a rounded rectangle, you can use to create an oval CreateEllipticRgn, CreatePolyPolygonRgn create a polygon, CreateRectRgn rectangular, etc., carefully observe their last three characters Rgn Oh, get the idea.
3, to get a handle
other windows that I was going to not speak, but have since made friends here, I had to explain in detail. General access to the other window handle using the following API:
FindWindow, FindWindowEx, WindowFromPoint
two API to sufficient, take a look at the first prototype API:
Private Declare Function FindWindow Lib string variables, so there need to pass a string, the second ByVal lpWindowName As String,Bailey UGG boots, as a string variable, which also need to pass strings. Look at the API for the Function, a return value, it returns the value that we need to handle the. Well, now understand the specific delivery of two types of parameters, we now know that these two parameters must be passed in the end what value? As follows:
ByVal lpClassName As String, lpClassName: class name. Refers to the window class name, if you ignore the incoming vbNullString.
ByVal lpWindowName As String, lpWindowName: window name. Refers to the window text, if ignored, the incoming vbNullString.
now understand what values need to pass two parameters to be easily handled, and a window class name we may not know, but the name of a window easier to handle. Such as: we open the Notepad program, you can see the window title appears as Well, that is we need, now we will get through this window title to the handle of Notepad. Create a new Standard EXE, and enter the following code:
Private Declare Function FindWindow Lib ()
Dim WindowHandle As Long
WindowHandle = FindWindow (vbNullString, >
Well, F5 to run, display a message box MsgBox, if not 0, then we will go to succeed, and if it is 0, then that get failures, this time you need to check the window you want the text to get it found that you have to get the window text (Oh, this sentence is really long!). I do not talk about the specific meaning of the code, and we can under my own analysis.
Tip: this time we have been handle a specific get the handle for? It is up to you. For example, as follows:
SetWindowText WindowHandle, Note, SetWindowText you have to declare the API. Do not forget.
look at the second FindWindowEx, this API is to find the list in the window matches the specified conditions, the first child window, the prototype is as follows:
Private Declare Function FindWindowEx Lib FindWindowExA As Long, there is need to pass the handle, look at the third and fourth: ByVal lpsz1 As String, ByVal lpsz2 As String, here is the string to be passed. Specific meaning as follows:
hWnd1 ---------- Long,UGG boots cheap, in which the child find the parent window. If set to zero, that the use of the desktop window (typically the top-level windows that are considered to be a child of the desktop window, so I will find them)
hWnd2 ---------- Long From this window, look after. This allows multiple calls to use on FindWindowEx to find all the eligible child windows. If set to zero, said first sub-window from the Start Search lpsz1 ---------- String, want to search for class name. Zero means ignore, pay attention to the general passing vbNullString
lpsz2 ---------- String, want to search for class name. Zero means ignore, pay attention to the general practice of passing vbNullString
help with our analysis, here or take note of the surgery. Open a Notepad, create a new Standard EXE, and then create a CommandButton, Caption is set to: set the text. OK, write the following code:
Private Declare Function FindWindow Lib user32 fEnable As Long) As Long
Private Sub Command1_Click ()
Dim WindowHandle As Long, ChildWindowHandle As Long
WindowHandle = FindWindow (vbNullString, )
If WindowHandle Then 'Get a handle if successful
ChildWindowHandle = FindWindowEx (WindowHandle, 0, handle
EnableWindow ChildWindowHandle, False 'disable the child window
Else
MsgBox End If
End Sub
well, to help our analysis. Read the first line: Dim WindowHandle As Long, ChildWindowHandle As Long, to get the handle for storage. WindowHandle = FindWindow (vbNullString,
ChildWindowHandle = FindWindowEx (WindowHandle, 0, We can use Spy + + view of the TextBox class to Notepad, and then you can write the class name.
EnableWindow ChildWindowHandle, False This is a new API, although I have not before been in front, but the API and its simple to use. There are two parameters in this API, the first of course is to pass the window handle, the second for the Long variable, in fact, set the Boolean variable should be better here, mainly to handle the current window is available. True available, False disabled.
F5 to run now, I remember opening the Notepad Oh, and then click Command1, see if you can text in Notepad enter the string? It is disabled?
Tip: EnableWindow all speak out, is to raise public interest in using the API, some of the window is disabled you can use this API to activate it, as to how to use it on your own, here for everyone layout of a job, huh, huh, its own to complete it.
final API, WindowFromPoint, this API is to get the current coordinates of the main window handle, not one wanted to know the current location of the mouse pointer the window handle it? This is a good choice to use the prototype as follows:
Private Declare Function WindowFromPoint Lib One is xPoint (x coordinates), one yPoint (y coordinates), and now you can pass in the other two parameters are the coordinates of the window can obtain a handle to the other windows. Function declarations can be seen as the return value is we need to handle.
function we want to achieve is to get a handle to the current position of the mouse pointer, so here GetCursorPos of course need to use a combination mentioned earlier, create a new Standard EXE, add a Timer Control, Interval set to 100 , Enabled = True, OK, write as the following code:
Private Declare Function WindowFromPoint Lib > Private Sub Timer1_Timer ()
Dim lpPoint As POINTAPI
Dim WindowHandle As Long
GetCursorPos lpPoint 'Get the current mouse pointer coordinates
WindowHandle = WindowFromPoint ( lpPoint.x, lpPoint.y)
Me.Caption = analysis, as GetCursorPos use and that has been mentioned that this is no longer analysis. Look WindowHandle = WindowFromPoint (lpPoint.x, lpPoint.y) phrase, it is through GetCursorPos mouse coordinates for the current mouse coordinates to get a handle. The last sentence I do not have to say, in the program window to get the handle.
Well, API entry has been concluded, in fact, I would like to write down, but many people seemed to respond to fewer people, it is written down against my mood. But we still hope to learn some knowledge from the above. Application specific API I do not say, we can feel yourself slowly. If I told you above all get to know, then prove that you have a basic understanding of API to use, then the following to rely on your own. At this point, I hope I brought a good start to help you understand the API.
'reproduced from a plug-in, please indicate the official forum for the sea, the Post address:
No comments:
Post a Comment