Presentation is loading. Please wait.

Presentation is loading. Please wait.

Window.

Similar presentations


Presentation on theme: "Window."— Presentation transcript:

1 Window

2 Data types

3 Hungarian notation Window API uses hungarian notation.
Name has a suffix showing datat type p – pointer lp – long pointer ...

4 LPVOID – pointer to unknown type „void *“
„LPVOID reserved“ – allways pass NULL Independent from platform data types: QWORD – unsigned 64 bits long (qw) DWORD - unsigned 32 bits long (dw) WORD - unsigned 16 bits long (w) BYTE - unsigned 8 bits long (b) Other types: LONG – long (l) UINT – unsigned integer (ui) CHAR – character (c) STR – zero terminated string (sz) LPSTR – pointer to string (lpsz)

5 CHAR, CCHAR, TCHAR, WCHAR... what?
Legacy UTF-16 CHAR, CCHAR - ANSI character TCHAR – char to describe ANSI, DBCS or UTF-16 chars WCHAR – UTF-16 char UCHAR – unsigned char „This text is written in ANSI“ L„This text is written in UNICODE“

6 HANDLES All objects Windows is responsible for are stored in a table
Every object has an identificator – HANDLE HANDLES are unsigned 32 bits value For interoperability on 64 bits hardware handles uses lower 32 bits Beware some new handles (e.g. HTREEITEM)

7 HACCEL – handle to accelerator table
HBITMAP – handle to bitmap HBRUSH – handle to brush HDC – handle to device context HFILE – handle to file HWND – handle to window HINSTANCE – handle to instance (program) HMENU – handle to menu HPEN – handle to pen etc.

8 Window

9 WinMain main() is gone! What a relief it‘s still there... WinMain
wWinMain

10 Parametrai hThisInstance – ID of this program
hPrevInstance – ID of the earlier instance of this program (16-bit). For NT systems it is allways NULL lpszArgument – command-line arguments as Unicode string nCmdShow – a flag that says whether the main application window will be minimized, maximized or shown normally.

11 How to get a window? Register class Create window Run message loop

12 Notice Every graphical part in Windows is window, meaning window class should have many options!!!

13 WNDCLASS(EX) Window as new class Structure to define window
lpszClassName = „MyClass“ Structure to define window Registration

14 WNDCLASS[EX] structure

15 cbSize - The size, in bytes, of this structure
cbSize - The size, in bytes, of this structure. Set this member to sizeof(WNDCLASSEX). Style - The class style(s). lpfnWndProc - A pointer to the window procedure. cbClsExtra - The number of extra bytes to allocate following the window-class structure. Default is zero. cbWndExtra - The number of extra bytes to allocate following the window instance. Default is zero. hInstance - A handle to the instance that contains the window procedure for the class. hIcon - A handle to the class icon (from resource). If NULL, default icon. hCursor - A handle to the class cursor (from resource). If NULL, default mouse cursor. hbrBackground - A handle to the class background brush. If NULL, default behaviour. lpszMenuName – A Pointer to a string that specifies the resource name (or use MAKEINTRESOURCE for integer id). NULL - no menu. lpszClassName - Specifies the window class name. hIconSm - A handle to a small icon (from resource). If NULL, default behaviour

16 Registering class RegisterClass RegisterClassA (ANSI characters)
RegisterClassW (UNICODE characters) RegisterClassEx RegisterClassExA (ANSI characters) RegisterClassExW (UNICODE characters)

17 Creating window CreateWindow CreateWindowA CreateWindowW
CreateWindowEx CreateWindowExA CreateWindowExW ShowWindow

18

19 Window styles Describes behaviour of window
Unmodifiable after window has been created Few exceptions exists Can be combined trough “|” Some are incompatible Some are already combinations A lot of styles exists

20 Examples WS_BORDER 0x00800000L window has a thin-line border
WS_CAPTION 0x00C00000L window has a title bar (includes the WS_BORDER) WS_CHILD 0x L window is a child window (cannot be used with WS_POPUP) WS_DISABLED 0x L window is initially disabled (EnableWindow function) WS_POPUP 0x L windows is a pop-up (cannot be used with WS_CHILD) WS_VISIBLE 0x L window is initially visible (ShowWindow or SetWindowPos function)

21 Message Loop

22 Message loop System can create a message queue for thread
Message loop must be provided Message loop retrieves messages from thread‘s message queue and dispatches them to appropriate window procedures System directs messages to individual windows in application Messages has MSG data type GetMessage() – reads message from queue or waits new one DispatchMessage() – dispatches message to win procedure TranslateMessage () – translates virtual-key messages into character ones and posts back to message queue

23

24 Windows procedure The name doesn‘t matters but prototype does:
LRESULT – multiple result (depends from message) hwnd – handle to the window msg – message xPARAM – additional message information (depends from message)

25 Example WM_KEYDOWN – keyboard key is pressed down:
WPARAM will keep keys value, for example „A“ LPARAM will keep command keys values (CTRL, ALT, SHIFT and repeat function)

26

27 Messages SendMessage – calls the windows procedure for the specified window and does not return until window procedure processed message PostMessage – posts a message in message queue for specified window and returns without waiting LRESULT WINAPI SendMessage(HWND   hWnd, UINT   Msg, WPARAM wParam, LPARAM lParam ) BOOL WINAPI PostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )

28 More examples WM_CREATE – create window WM_PAINT – redraw window
WM_COMMAND – user action WM_CLOSE – this command is passed to procedure DefWindowProc, which sends WM_DESTROY message

29 Macrocommands Few macros for parameters:
WORD LOWORD(DWORD) – returns low-order word WORD HIWORD(DWORD) – returns high-order word BYTE LOBYTE(WORD) – returns low-order byte BYTE HIBYTE(WORD) – returns high-order byte Second byte from wParam - HIBYTE(LOWORD(wParam)); In 64 bits system only lower 32 bits are used

30 WPARAM, LPARAM... why? 16-bits
Parameters can be passed by WORD (16 bit) or LONG (32 bits) formats WPARAM means 16 bits LPARAM means 32 bits Today both are of 32 bits long


Download ppt "Window."

Similar presentations


Ads by Google