Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24

11/21/2023 Windows Programming 1

WINDOWS
PROGRAMMING
Dương Xuân Hiệp
Email: hiepbk789@gmail.com
MVS
11/21/2023 Windows Programming 2

Content
o Windows API

o What is API ?

o Type and popular API Examples

o Windows API

o Windows Messages

o Events

o The Message Loop


11/21/2023 Windows Programming 3

Content
o MFC Programming

o Programming Interface

o Example

- Dialog example

- Menu example

- Message example

o Homework
11/21/2023 Windows Programming 4

What is API ?

• API (Application Program Interface), is a set of routines,


protocols, and tools for building software applications.

• The API specifies how software components should


interact and APIs are used when programming graphical
user interface (GUI) components
11/21/2023 Windows Programming 5

What is API ?

• A good API makes it easier to develop a program by


providing all the building blocks.

• A programmer then puts the blocks together.


11/21/2023 Windows Programming 6

Type and popular API Examples

• There are many different types of APIs for operating


systems, applications or for websites.

• Google Maps API: Google Maps APIs lets developers


embed Google Maps on webpages using a JavaScript or
Flash interface. The Google Maps API is designed to work
on mobile devices and desktop browsers
11/21/2023 Windows Programming 7

Type and popular API Examples

• YouTube APIs: lets developers integrate YouTube videos


and functionality into websites or applications. YouTube
APIs include the YouTube Analytics API, YouTube Data
API, YouTube Live Streaming API, YouTube Player APIs
and others

• Flickr API: The Flickr API is used by developers to


access the Flick photo sharing community data. The Flickr
API consists of a set of callable methods, and some API
endpoints.
11/21/2023 Windows Programming 8

Type and popular API Examples

• Twitter APIs: Twitter offers two APIs. The REST API


allows developers to access core Twitter data and the
Search API provides methods for developers to interact
with Twitter Search and trends data.

• Amazon Product Advertising API: Amazon's Product


Advertising API gives developers access to Amazon's
product selection and discovery functionality to advertise
Amazon products to monetize a website.
11/21/2023 Windows Programming 9

Windows API

• Windows has many API sets that are used by system


hardware and applications — when you copy and paste
text from one application to another, it is the API that
allows that to work.

• Most operating environments, such as MS-Windows,


provide an API so that programmers can write
applications consistent with the operating environment
11/21/2023 Windows Programming 10

Windows API

• Developer support is available in the form of the


Windows Software Development Kit (SDK), providing
documentation and tools necessary to build software
based upon the Windows API and associated Windows
interfaces.

• The Windows API (Win32) is primarily focused on the C


programming language
11/21/2023 Windows Programming 11

Windows API
11/21/2023 Windows Programming 12

Windows Messages
A GUI application must respond to events from the user
and from the operating system.
• Events from the user include all of the ways that
someone can interact with your program: mouse clicks,
key strokes, touch-screen gestures, and so forth

• Events from the operating system include anything


"outside" of the program that can affect how the program
behaves. For example, the user might plug in a new
hardware device, or Windows might enter a lower-power
state (sleep or hibernate).
11/21/2023 Windows Programming 13

Windows Messages
11/21/2023 Windows Programming 14

Windows Messages
• A message is simply a numeric code that designates a
particular event. For example, if the user presses the left
mouse button, the window receives a message with the
following message code

#define WM_LBUTTONDOWN 0x0201

• To pass a message to a window, the operating system


calls the window procedure registered for that window.
(And now you know what the window procedure is for.)
11/21/2023 Windows Programming 15

The Message loop


• For each thread that creates a window, the operating
system creates a queue for window messages.

• This queue holds messages for all of the windows that


are created on that thread.

• The queue itself is hidden from your program.


11/21/2023 Windows Programming 16

MFC Programming
• An MFC program is an executable application for
Windows that is based on the Microsoft Foundation Class
(MFC) Library.

• The MFC starter program will include C++ source (.CPP)


files, resource (.RC) files, header (.H) files, and a project
(. vcproj) file. The code generated in these starter files is
based on MFC.
11/21/2023 Windows Programming 17

MFC Programming
• Programming Interface
11/21/2023 Windows Programming 18

MFC Programming
• Message example
11/21/2023 Windows Programming 19

MFC Programming
• Menu example
11/21/2023 Windows Programming 20

Homework
• 1. Xây dựng một main dialogue
như sau:
• Có thanh Menu
• Quản lý các bạn theo từng
nhóm
• Có avatar
• Hiển thị status ứng với mỗi bạn

( sử dụng MFC )
11/21/2023 Windows Programming 21

Homework
• 2. Xây dựng giao diện cho phép Add/Block Friend
(Giao diện tùy ý)

• - Cho phép Add hoặc Block friend

( sử dụng MFC )
11/21/2023 Windows Programming 22

Homework
• 3. Xây dựng giao diện chat như hình. ( sử dụng MFC )
• - Thực hiện được việc tự chat và hiển thị lên dialog của
mình. ( có avatar )
- Thực hiện việc chat giữa 2 người ( sử dụng Windows
Message).
- Chat sử dụng Emotion.
11/21/2023 Windows Programming 23

Homework
• Các yêu cầu khác:
• Quản lý danh sách friend/block của mỗi người theo database ( Đã
học )
• Quản lý Message ( tin nhắn đã nhận hoặc lịch sử chat phải được
lưu lại vào database)
• Thời hạn: 23/11/2015 – 04/12/2015

• Tham khảo:
• www.google.com
• MFC examples:
https://msdn.microsoft.com/en-us/library/482ck6x8(v=vs.90).aspx
11/21/2023 Windows Programming 24

Thank for listening!

You might also like