Taskbar program -01
The popularity here is really not prosperous. I will add a firewood, I hope to drive everyone's programs. This is my first time to write a tutorial, and everyone will bear more. I plan to write two times a Sidebar listed on the right side (Chinese name I don't know what to call, it seems to be a taskbar, because the main sense comes from the Desktop Sidebar program, you can read the weather forecast from the Internet, you can display the current clock Wait for basic functions (you can join your own feature). My programming environment is Windows 2003 Delphi 7. Other versions of Delphi and Windows I want to be no problem, please see attachments. I want a reader to take a little Delphi, mainly take care of some beginners twice. OK, Let's Go!
// ----------- Text start -------------------
I don't know if you have noticed it? In fact, the desktop (Desktop) and Form1 are all forms (Window), the difference is that the desktop is behind all windows, we can completely have this property that makes our own form.
Procedure TForm1.FormCreate (Sender: Tobject); Var HDesktop: Thandle; Begin HDESKTOP: = FindWindow ('Progman', 'Program Manager'); Windows.SetParent (Handle, HDesktop);
END;
Try it in accordance with the code above, see WIN D will minimize this FORM1 form to the taskbar? The answer is of course negative because it already has the same attribute as the desktop. This is one of the skills of this tutorial. Sidebar should rely on the right or elsewhere on the desktop, which is very simple in delphi. Set the borderstyle of Form1 in Object Inspector to bsnone; width is 195; in FormCreate, you are as follows:
Procedure TForm1.FormCreate (Sender: Tobject); Var HDesktop: Thandle; R: TRECT; Begin R: = Screen.DesktopRect; // Read Desktop Resolution Self.top: = 0; Self.Left: = R.right- R.Left-self.width; // On the right Self.Height: = R.Bottom -r.top; // and desktop contour
HDESKTOP: = FindWindow ('progman', 'program manager'); Windows.SetParent (Handle, HDesktop);
END;
It is fun to establish Sidebar against the right side (press Alt F2), very fun. This time, here, you will see you next time. For beginners, the system hotkey (Hotkey) seems to be a difficult technology, in fact in Delphi, can be easily completed. In accordance with this example, two Atom type global variables AF9 and AF10 are declared. VAR AF9, AF10: Atom; Drag and drop a webbrowser control on Form1 (in the Internet), the name is Web1. In the form of event create add the following code: procedure TForm1.FormCreate (Sender: TObject); begin aF9: = GlobalAddAtom ( 'MyhotkeyF9'); // define elements aF10: = GlobalAddAtom ( 'MyhotkeyF10'); RegisterHotKey (Handle, aF9, MOD_SHIFT, VK_F9); // Register Hotkey Shift F9 RegisterhotKey (Handle, AF10, MOD_SHIFT, VK_F10); // Register Hot Key Shift F10
END;
This defines the hotkey and the function of the corresponding hotkey is also required. For Windows Message Delivery Mechanism, please refer to the relevant book, I just talk about the means of Delphi. Add the following publicProcedure WMHOTKEYHANDLE (VAR MSG: TMESSAGE); Message WM_HOTKEY; / / Response Sensitive Key button message
Add: procedure tform1.wmhotkeyhandle (var msg: tmessage); begin if (msg.lparamhi = vk_f9) and (msg.lparamlo = mod_shift) THEN Web1.naviGate ('http: // appnews .qq.com / cgi-bin / news_qq_search? city = Changchun ') Else if (msg.lparamhi = vk_f10) and (msg.lparamlo = mod_shift) THEN SELF.CLOSE;
Try it, press SHIFT F9 to connect to the weather forecast; SHIFT F10 will exit.
So our sidebar already has a prototype, and there is still the beautiful clock. The BMPCLOCK control is a national, very good, just more expenses, it is easy to find online. You can also display digital clocks in what clocks or LEDs.
The last point is important to install a transparent control, put it on the top of Web1, so that there will be no hateful right-click menu. The source code of the transparent control is as follows (I am Yuzhan in 9CBS):
{Welcome to transparent control v1.0 development by Yuzhan (9CBS) inherited from TwinControl, the main function is to block some things that don't want others, but will still keep it.
UNIT TRANSPARENT;
Interface
Uses sysutils, classes, controls, windows;
Type TTRANSPARENT = Class (TwinControl) private {private declarations} protected
Public Constructor Create (Aowner: Tcomponent); Override; Procedure CreateParams; OVERRIDE; Published {Published Declarations} End; Procedure Register
IMPLEMentation
Constructor TTRANSPARENT.CREATE (AOWNER: TComponent); Begin ControlStyle: = ControlStyle - [Csopaque]; inherited;
procedure TTransparent.CreateParams (var Params: TCreateParams); begin inherited CreateParams (Params); with Params do begin {redrawn completely} Style: = Style and not WS_CLIPCHILDREN; Style: = Style and not WS_CLIPSIBLINGS; {increase transparent} ExStyle: = EXSTYLE or WS_EX_TRANSPARENT; END;
Procedure Register; Begin RegisterComponents ('Win32', [TTRANSPARENT]); END;
End.