Implement Google Search

Source: Internet
Author: User

Implement Google Search:

Cstring strkeyword = _ T ("msdn"), strgoogle = _ T ("http://www.google.com.hk/search? Sourceid = chrome & Ie = UTF-8 & Q = "), strbrowser = _ T (" C: // program files // Internet Explorer // iexplore.exe "); <br/> // Method 1: <br/> // search by default browser; <br/> // ShellExecute (getsafehwnd (), _ T ("open "), strgoogle + strkeyword, null, null, sw_shownormal); <br/> // search by the specified browser; <br/> // ShellExecute (getsafehwnd (), _ T ("open"), strbrowser, strgoogle + strkeyword, null, sw_shownormal); <br/> // Method 2: <br/> startupinfo Si = {0 }; <br/> Si. CB = sizeof (startupinfo); <br/> Si. wshowwindow = sw_shownormal; <br/> process_information Pi = {0}; <br/> cstring strsite = strbrowser + _ T ("") + strgoogle + strkeyword; <br/> CreateProcess (null, strsite. getbuffer (strsite. getlength (), null, null, false, create_default_error_mode, <br/> null, null, & Si, & PI); <br/> closehandle (Pi. hprocess); <br/> closehandle (Pi. hthread); <br/> 

Startupinfo structure:

 

Typedef struct _ startupinfo

 

{
Dword cb; // contains the number of bytes in the startupinfo structure. If Microsoft expands this structure in the future, it can be used as a version control method. The application must initialize CB to sizeof (startupinfo)
Pstr lpreserved; // reserved. Must be initialized to n u L
Pstr lpdesktop; // The Name Of The desktop where the application is started. If the desktop exists, the new process is associated with the specified desktop.
If the desktop does not exist, create a desktop with the default attribute and use the name specified for the new process.
If lpdesktop is null (this is the most common case), the process will be associated with the current desktop
Pstr lptitle; // used to set the name of the console window. If l p ti t l e is n u l, the name of the executable file will be used as the window name
DWORD dwx; // the X and Y coordinates (in pixels) used to set the position of the application window on the screen ).
DWORD dwy; only when the child process uses cw_usedefault as the X parameter of createwindow to create its first overlapped window,
These two coordinates are used. If you create an application in the console window, these members are used to specify the upper left corner of the console window.

DWORD dwxsize; // used to set the width and length of the application window (in pixels) Only dwysize
DWORD dwysize; when the sub-process uses c w _ u s e d e fa u lt as C r e a t e wi n d o W
These values are used only when the N wi d t h parameter is used to create its first overlapping window.
If you create an application in the console window, these members are used to specify the width of the console window.
DWORD dwxcountchars; // used to set the width and height of the console window of the sub-application (in characters)
DWORD dwycountchars;
DWORD dwfillattri; // used to set the text and background colors used in the console window of the sub-Application
DWORD dwflags; // see the next section and the instructions in Table 4-7.
Word wshowwindow; // It is used to set if the second h o W wi n d o W called by the sub-Application for the first time takes s w _ s h o w d e fa u lt
How should the first overlapping window of the application appear when the n c m d s h o w parameter is passed.
This member can be any s w _ * identifier commonly used for the show wi n d o W Function
Word cbreserved2; // reserved. Must be initialized to 0
Pbyte lpreserved2; // reserved. Must be initialized to n u L
Handle hstdinput; // used to set the cache handle for console input and output.
According to the default settings, h s t d I n P U T is used to identify the keyboard cache,
H s t d o u t p u t and h s t d e r o r are used to identify the cache of the console window
Handle hstdoutput;
Handle hstderror;
} Startupinfo, * lpstartupinfo;

When wi n d o w s creates a new process, it uses the relevant members of this structure. Most applications require that the generated applications only use the default value. At least all members in the structure should be initialized to zero, and then c B members should be set to the size of the structure:
Startupinfo Si = {sizeof (SI )};
CreateProcess (..., & Si ,...);

Table 4-7 logo and meaning of dwflags
Logo meaning
Startf_usesize // use the d w x s I z e and d w y s I Z E members
Startf_useshowwindow // use w s h o w wi n d o W Member
Startf_useposition // use members d w x and D W Y
Startf_usecountchars // use d w x c o u n t c h a r s and dwycount chars members
Startf_usefillattribute // use d w f I l a t r I B u t e Member
Startf_usestdhandles // use h s t d I n P U T, H S T d o u t p U T and H S T d e r o r members
Startf_run_fullscreen // force the console application running on the x 8 6 computer to start running in full screen mode

There are two other signs:Startf_forceonfeedbackAnd startf _ + forceofff-eedback. when starting a new process, they can be used to control the mouse cursor. Because Windows supports real multi-task preemptible running mode, you can start an application and use another program during process initialization. C r
E a t e p r o c e s can temporarily change the system arrow cursor to a new light mark, that is, the hourglass arrow cursor:

The cursor indicates that you can wait for a situation or continue to use the system. When another process is started, the CreateProcess function enables you to better control the cursor. When setStartf_forceonfeedbackC r e a t e p r o c e s does not change the cursor to an hourglass.

Startf_forceonfeedbackAllows CreateProcess to monitor initialization of new processes and change the cursor based on the results. When CreateProcess is called using this flag, the cursor is changed to an hourglass. After 2 s, if the new process does not call g u I, CreateProcess restores the cursor to the arrow.

If the process calls the GUI within 2 s, CreateProcess will wait for the application to display a window. This must occur within 5 s after the process calls g u I. If no window is displayed, CreateProcess restores the original cursor. If a window is displayed, CreateProcess will keep the hourglass cursor for 5 s. If the application calls the g e t m e s a g e function at some time, it indicates that it has completed initialization, then C r e a t e p r o c e s will immediately restore the original cursor and stop monitoring the new process.

Before finishing this section, I would like to talk about the members of w s h o w wi n d o W of S ta RT u p I n f o. You initialize the member as the value of the last parameter n c m d s h o w passed to (w) WI n m a I n. This member shows the value of n c m d s h o w, the last parameter of the (w) WI n m a I n function that you want to pass to the new process. It is one of the identifiers that can be passed to the s h o w wi n d o W function. Generally, the value of n c m d s h o w can be s w _ s h o
W n o r m a L, or SW _ showminnoactive. However, it can sometimes be s w _ s h o w d e fa u lt.

When an application is enabled in e x p l o r e r, the (w) WI n m a I n function of the application is called, s w _ s h o W n o r m a L is passed as n c m d s h o w parameter. If you create a shortcut for the application, you can use the shortcut property page to tell the system how the application window should be displayed at first. Figure 4-3 shows the properties page of the shortcut for running n o t e p a D. Note that you can use the combo box of the r u n option to set how to display the n o t e p a d window.

When you use e x p l o r e r to start this shortcut, e x p l o r e r will correctly prepare the S ta RT u p I n f O structure and call C r e a T E P R o C E S. At this time, n o t e p a d starts to run, in addition, for the n c m d s h o w parameter, the s w _ s h o w m I n o a C t I V E is passed to its (W) wi n m a I n function.

By using this method, you can easily start an application. Its main window can be displayed in the normal, minimum, or maximum status.

Finally, the application can call the following function to obtain a copy of the S ta RT u p I n f O structure initialized by the parent process. The sub-process can view the structure and change its behavior characteristics based on the value of the members of the structure.

Void getstartupinfo (lpstartupinfo pstartupinfo );
Note that although the WI n d o w s documentation does not explicitly describe, before calling the g e t s t a r t I n f o function, the C B Member of the structure must be initialized as follows:
Startupinfo Si = {sizeof (SI )};
Getstartupinfo (& Si );

 

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.