Many people think that Delphi is a RAD tool, including me in school when the Delphi also biased, now out of the "ivory Tower", involving a wide range of problems encountered, and slowly also have their own little experience. In fact, Delphi is based on the Object Pascal Language development tool, that is, Delphi is essentially a language tool, and is the real object-oriented. The following example I give is a tray with Delphi implementation of a small program. The program is short and clear, and I will explain the key parts in detail. Just like Mr. JJ to peel off the MFC layer by layer, today I have a "Sunding".
In the Delphi involves the system programming aspect to invoke the API function without exception, in the Shellapi.pas unit has to use the API function prototype.
Practical Walkthrough:
A Create a new application: File->new Applicaton defines a message constant in the interface section: const wm_nid=wm_user+1000; The system provides custom messages for users starting with Wm_user.
Two Define a global variable: Notifyicon:tnotifyicondata,notifyicon is a very important variable, the whole program is basically around the variable in the turn. Tnotifyicondata is a record type, hold down the CTRL key, and double-click the Tnotifyicondata to enter the Shellapi.pas cell. (Note: In Delphi, this is a very good source code analysis method, the source code to explain everything, you want to know the inside of the program, the best way is to analyze the source code!) The following assignment statement appears:
Tnotifyicondata = Tnotifyicondataa, which means that tnotifyicondata and tnotifyicondataa are the same data types, and then look down:
TNotifyIconDataA = _NOTIFYICONDATAA,意思与刚才的一样,再往下看:
type
_NOTIFYICONDATAA = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: array [0..63] of AnsiChar;
end;
This is really "long-awaited began to come out, still hold pipa half cover." It is now clear that the global variable NotifyIcon that we have just defined is actually a variable of record type containing 7 components, which is equivalent to a struct variable in C + + (C + + programmers should be more familiar with it). Here we explain each of the 7 parts of the record type individually.