Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

14
Lecture 12

Transcript of Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Page 1: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Lecture 12

Page 2: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Windows registry

• Structure of the registry

• Loading and storing data in registry

Page 3: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Structure of the registry

• Tree with the following roots:– HKEY_CLASSES_ROOT– HKEY_CURRENT_CONFIG– HKEY_CURRENT_USER– HKEY_LOCAL_MACHINE– HKEY_USERS

Page 4: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Structure of the registry

• Registry structure• Data is stored in tree-like structure• Nodes of the tree are called "Keys"• Key can have any number of sub-keys and any

number of values• For example: ...\YourApplicationKey "WindowPosition" = "10x20x300x350" "DefaultDirectory" = "C:\My Documents"

Page 5: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Structure of the registry

• Some registry keys are used by the system, for example:

• HKLM\Software\Microsoft\Windows\ \

CurrentVersion\Run - contains applications that will be executed at windows startup

• Other keys are used by applications to store their settings

Page 6: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

HKEY_CLASSES_ROOT

• Stores:– file extension - program association– information about COM objects

• class identifiers ({00000010-0000-0010-8000-00AA006D2EA4})

• program identifiers (Word.Document.8)

Page 7: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

HKEY_LOCAL_MACHINE

• Global computer settings (common to all users)

• Applications usually store their settings in "Software" subkey, typically:

HKLM\Software\Company Name\ \Application Name\Version

Page 8: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Registry functions (keys)

• Keys– RegCreateKeyEx() - create key and open– RegOpenKeyEx() - open existing key– RegCloseKey() - close key– RegDeleteKey() - delete registry key– RegEnumKeyEx - enumerate sub keys– RegQueryInfoEx() - get information about the

key

Page 9: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Registry functions (values)

• RegSetValueEx() - set key value

• RegQueryValueEx(), RegQueryMultipleValues() - get key value

• RegDeleteValue() - delete key value

• RegEnumValue() - enumerate key values

Page 10: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Shell functions

• FindExecutable – find executable for document file

• ShellExecute – run application and open document file, run Windows Explorer

• WinHelp – display help for the application

Page 11: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

File drag and drop

• DragAcceptFiles – inform Windows that application window accepts dropped files

• WM_DROPFILES – message sent after file(s) has been dropped on application window

• DragQueryFile – retrieve the name of the file that was dropped

• DragQueryPoint – retrieve the point where the file(s) have been dropped

Page 12: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Windows Tray

• Application that wants to minimize the window to tray should:– Create Windows Tray icon (using Shell_NotifyIcon function)– Hide main application window

• Application that only wants to display icon in the tray should:– Create hidden window (that window will process messages from

the icon)– Create Windows Tray icon (using Shell_NotifyIcon function)

• In order to display windows tray icon, an application must be running

Page 13: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Clipboard• Copying data to clipboard:

– call OpenClipboard()– call EmptyClipboard()– call SetClipboardData() and pass handle to memory

allocated with GlobalAlloc()– call CloseClipboard()

Page 14: Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.

Clipboard• Pasting data from clipboard

– call OpenClipboard()– check data format: IsClipboardFormatAvailable(),

EnumClipboardFormats(), GetPriorityClipboardFormat(), CountClipboardFormats()

– call GetClipboardData()– call CloseClipboard()