SlideShare a Scribd company logo
Win32 Programming Basic Concepts
Ping-Lun Liao
Outline
● Windows Message
● Resources
● Samples Demo
Windows and Applications
• Mechanisms to starts/terminate the application
Windows Application Components
Message Everywhere
● Event-Driven
● Message-Based Action
What is Windows Message?
● System-Defined Message
● Application-Defined Message
System-Defined Message
● The system sends or posts a system-
defined message when it communicates
with an application.
● It uses these messages to control the
operations of applications and to provide
input and other information for
applications to process.
System-Defined Message
● An application can also send or post syste
m-defined messages.
● Applications generally use these message
s to control the operation of control windo
ws created by using preregistered window
classes.
System-Defined Message
Application-Defined Message
● An application can create messages to be
used by its own windows or to
communicate with windows in other
processes.
● If an application creates its own messages,
the window procedure that receives them
must interpret the messages and provide
appropriate processing.
Steps For Creating A Window
● Step 1: Registering the Window Class
● Step 2: Creating the Window
● Step 3: The Message Loop
● Step 4: the Window Procedure
A Simple Window
● A Simple Window
Message Handling
● Message Loop
● Window Procedure
The Message Loop
• retrieves message from
the message queue
• sends message to the
Windows procedure
where the messages are
processed
• loops back and repeats
the procedure
The Message Loop
• Programs generally don't call window procedures directly.
• The window procedure is almost always called from Windows itself.
• A program can indirectly call its own window procedure by calling a function named
SendMessage().
The Message Loop
• Messages come
through in an orderly
and synchronized
manner.
• While processing one
message in a window
procedure, the
program will not be
suddenly interrupted
by another message.
Message Handling
WM_LBUTTONDOWNWM_DESTROYWM_PAINTWM_CREATE
The Message Loop
• Message loop retrieves a message from its
message queue
• Call DispatchMessage() to send the message off
to the window procedure
• DispatchMessage() does not return until the
window procedure has returned control back to
Windows.
The Message Loop
Windows Class and Registration
Windows Dialog Box
Windows Application Lifecycle
Resources
• Standard - icon, cursor, menu, dialog box,
bitmap, enhanced metafile, font, accelerator
table, message-table entry, string-table entry,
or version
• Custom - any kind of data that doesn't fall into
the previous category (for example a mp3 file
or a dictionary database).
Three dynamic-link libraries
● Kernel32.dll
– File I/O, System,…
● User32.dll
– User Interface…
● Gdi32.dll
– Fonts, Brushes…
First Windows Program
• Win32 API
● Win32ASM
● Visual C++
– MFC (Microsoft Foundation Classes)
● BCB (Borland C++ Builder)
– VCL (Visual Component Library)
● VB(???)
● .Net(C#, J#, C++, VB.NET)
– Windows Form
• 但是不論用那種方式,都是可以呼叫 Win32 API
Numeric identifiers
● In header file (always called resource.h)
● Example
– #define IDMAINMENU 300
– #define IDM_FILE_NEW 301
– #define IDM_FILE_OPEN 302
– #define IDM_FILE_SAVE 303
– #define IDM_FILE_EXIT 304
– #define IDM_HELP_ABOUT 305
Something about GetMessage
• Warning : Because the return value can be
nonzero, zero, or -1, avoid code like this:
while (GetMessage( lpMsg, hWnd, 0, 0)) ...
Solution
BOOL bRet;
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Reference
● 深入淺出 MFC
● theForger's Win32 API Programming Tutorial

More Related Content

Similar to Win32 視窗程式設計基礎

Windows programming ppt
Windows programming pptWindows programming ppt
Windows programming ppt
SAMIR CHANDRA
 
Windows programming
Windows programmingWindows programming
Windows programming
Bapan Maity
 
Caim ppt
Caim pptCaim ppt
Caim ppt
ravi kant
 
VC++ Fundamentals
VC++ FundamentalsVC++ Fundamentals
VC++ Fundamentals
ranigiyer
 
Group#4 Ali-Hamza --Sufian abid-- umer naseem -- adeel akhtar.pptx
Group#4 Ali-Hamza --Sufian abid-- umer naseem -- adeel akhtar.pptxGroup#4 Ali-Hamza --Sufian abid-- umer naseem -- adeel akhtar.pptx
Group#4 Ali-Hamza --Sufian abid-- umer naseem -- adeel akhtar.pptx
AliHamza515454
 
os_1.pdf
os_1.pdfos_1.pdf
os_1.pdf
HemantBorse6
 
Software introduction
Software introductionSoftware introduction
Software introduction
Saddam Hussain Soomro
 
EclipseCon Eu 2012 - Build your own System Engineering workbench
EclipseCon Eu 2012 - Build your own System Engineering workbenchEclipseCon Eu 2012 - Build your own System Engineering workbench
EclipseCon Eu 2012 - Build your own System Engineering workbench
melbats
 
4 various operating systems
4 various operating systems4 various operating systems
4 various operating systems
myrajendra
 
Introduction to Operating Systems - Mary Margarat
Introduction to Operating Systems - Mary MargaratIntroduction to Operating Systems - Mary Margarat
Introduction to Operating Systems - Mary Margarat
Mary Margarat
 
ICT Presentation operating system and types.pptx
ICT Presentation operating system and types.pptxICT Presentation operating system and types.pptx
ICT Presentation operating system and types.pptx
Shehlafaiz1
 
Presentation on windows
Presentation  on windowsPresentation  on windows
Presentation on windows
Jenish Prajapati
 
Unit 1 operating system
Unit 1 operating systemUnit 1 operating system
Unit 1 operating system
Meeta
 
DA8_presentation
DA8_presentationDA8_presentation
DA8_presentation
Evgeny Zolotarenko
 
Comp Project (V).pptx
Comp Project (V).pptxComp Project (V).pptx
Comp Project (V).pptx
AayushPawar12
 
Computer software and operating system.pptx
Computer software and operating system.pptxComputer software and operating system.pptx
Computer software and operating system.pptx
AayushAryal2
 
cse581_03_EventProgramming.ppt
cse581_03_EventProgramming.pptcse581_03_EventProgramming.ppt
cse581_03_EventProgramming.ppt
tadudemise
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
Shaina Mavreen Villaroza
 
ICT Skills.pdf
ICT Skills.pdfICT Skills.pdf
ICT Skills.pdf
TENZING LHADON
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
Anshumali Singh
 

Similar to Win32 視窗程式設計基礎 (20)

Windows programming ppt
Windows programming pptWindows programming ppt
Windows programming ppt
 
Windows programming
Windows programmingWindows programming
Windows programming
 
Caim ppt
Caim pptCaim ppt
Caim ppt
 
VC++ Fundamentals
VC++ FundamentalsVC++ Fundamentals
VC++ Fundamentals
 
Group#4 Ali-Hamza --Sufian abid-- umer naseem -- adeel akhtar.pptx
Group#4 Ali-Hamza --Sufian abid-- umer naseem -- adeel akhtar.pptxGroup#4 Ali-Hamza --Sufian abid-- umer naseem -- adeel akhtar.pptx
Group#4 Ali-Hamza --Sufian abid-- umer naseem -- adeel akhtar.pptx
 
os_1.pdf
os_1.pdfos_1.pdf
os_1.pdf
 
Software introduction
Software introductionSoftware introduction
Software introduction
 
EclipseCon Eu 2012 - Build your own System Engineering workbench
EclipseCon Eu 2012 - Build your own System Engineering workbenchEclipseCon Eu 2012 - Build your own System Engineering workbench
EclipseCon Eu 2012 - Build your own System Engineering workbench
 
4 various operating systems
4 various operating systems4 various operating systems
4 various operating systems
 
Introduction to Operating Systems - Mary Margarat
Introduction to Operating Systems - Mary MargaratIntroduction to Operating Systems - Mary Margarat
Introduction to Operating Systems - Mary Margarat
 
ICT Presentation operating system and types.pptx
ICT Presentation operating system and types.pptxICT Presentation operating system and types.pptx
ICT Presentation operating system and types.pptx
 
Presentation on windows
Presentation  on windowsPresentation  on windows
Presentation on windows
 
Unit 1 operating system
Unit 1 operating systemUnit 1 operating system
Unit 1 operating system
 
DA8_presentation
DA8_presentationDA8_presentation
DA8_presentation
 
Comp Project (V).pptx
Comp Project (V).pptxComp Project (V).pptx
Comp Project (V).pptx
 
Computer software and operating system.pptx
Computer software and operating system.pptxComputer software and operating system.pptx
Computer software and operating system.pptx
 
cse581_03_EventProgramming.ppt
cse581_03_EventProgramming.pptcse581_03_EventProgramming.ppt
cse581_03_EventProgramming.ppt
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
ICT Skills.pdf
ICT Skills.pdfICT Skills.pdf
ICT Skills.pdf
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 

More from PingLun Liao

Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
PingLun Liao
 
給沒有程式設計經驗的人
給沒有程式設計經驗的人給沒有程式設計經驗的人
給沒有程式設計經驗的人
PingLun Liao
 
陣列與指標
陣列與指標陣列與指標
陣列與指標
PingLun Liao
 
Perl For Bioinformatics
Perl For BioinformaticsPerl For Bioinformatics
Perl For Bioinformatics
PingLun Liao
 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
PingLun Liao
 
C++ Function
C++ FunctionC++ Function
C++ Function
PingLun Liao
 
C 檔案輸入與輸出
C 檔案輸入與輸出C 檔案輸入與輸出
C 檔案輸入與輸出
PingLun Liao
 
Matlab 在機率與統計的應用
Matlab 在機率與統計的應用Matlab 在機率與統計的應用
Matlab 在機率與統計的應用
PingLun Liao
 
Android 2D 遊戲設計基礎
Android 2D 遊戲設計基礎Android 2D 遊戲設計基礎
Android 2D 遊戲設計基礎
PingLun Liao
 
Android 介面設計
Android 介面設計Android 介面設計
Android 介面設計
PingLun Liao
 
Java 網路程式
Java 網路程式Java 網路程式
Java 網路程式
PingLun Liao
 
Android introduction
Android introductionAndroid introduction
Android introduction
PingLun Liao
 
RESTful
RESTfulRESTful
RESTful
PingLun Liao
 
Web service
Web serviceWeb service
Web service
PingLun Liao
 
How toprogram
How toprogramHow toprogram
How toprogram
PingLun Liao
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
PingLun Liao
 
Object-Oriented Programming
Object-Oriented ProgrammingObject-Oriented Programming
Object-Oriented Programming
PingLun Liao
 
Object-Based Programming Part II
Object-Based Programming Part IIObject-Based Programming Part II
Object-Based Programming Part II
PingLun Liao
 
Object-Based Programming Part One
Object-Based Programming Part OneObject-Based Programming Part One
Object-Based Programming Part One
PingLun Liao
 
Git server account management
Git server account managementGit server account management
Git server account management
PingLun Liao
 

More from PingLun Liao (20)

Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
 
給沒有程式設計經驗的人
給沒有程式設計經驗的人給沒有程式設計經驗的人
給沒有程式設計經驗的人
 
陣列與指標
陣列與指標陣列與指標
陣列與指標
 
Perl For Bioinformatics
Perl For BioinformaticsPerl For Bioinformatics
Perl For Bioinformatics
 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
C 檔案輸入與輸出
C 檔案輸入與輸出C 檔案輸入與輸出
C 檔案輸入與輸出
 
Matlab 在機率與統計的應用
Matlab 在機率與統計的應用Matlab 在機率與統計的應用
Matlab 在機率與統計的應用
 
Android 2D 遊戲設計基礎
Android 2D 遊戲設計基礎Android 2D 遊戲設計基礎
Android 2D 遊戲設計基礎
 
Android 介面設計
Android 介面設計Android 介面設計
Android 介面設計
 
Java 網路程式
Java 網路程式Java 網路程式
Java 網路程式
 
Android introduction
Android introductionAndroid introduction
Android introduction
 
RESTful
RESTfulRESTful
RESTful
 
Web service
Web serviceWeb service
Web service
 
How toprogram
How toprogramHow toprogram
How toprogram
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 
Object-Oriented Programming
Object-Oriented ProgrammingObject-Oriented Programming
Object-Oriented Programming
 
Object-Based Programming Part II
Object-Based Programming Part IIObject-Based Programming Part II
Object-Based Programming Part II
 
Object-Based Programming Part One
Object-Based Programming Part OneObject-Based Programming Part One
Object-Based Programming Part One
 
Git server account management
Git server account managementGit server account management
Git server account management
 

Recently uploaded

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 

Recently uploaded (20)

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 

Win32 視窗程式設計基礎

  • 1. Win32 Programming Basic Concepts Ping-Lun Liao
  • 2. Outline ● Windows Message ● Resources ● Samples Demo
  • 3. Windows and Applications • Mechanisms to starts/terminate the application
  • 6. What is Windows Message? ● System-Defined Message ● Application-Defined Message
  • 7. System-Defined Message ● The system sends or posts a system- defined message when it communicates with an application. ● It uses these messages to control the operations of applications and to provide input and other information for applications to process.
  • 8. System-Defined Message ● An application can also send or post syste m-defined messages. ● Applications generally use these message s to control the operation of control windo ws created by using preregistered window classes.
  • 10. Application-Defined Message ● An application can create messages to be used by its own windows or to communicate with windows in other processes. ● If an application creates its own messages, the window procedure that receives them must interpret the messages and provide appropriate processing.
  • 11. Steps For Creating A Window ● Step 1: Registering the Window Class ● Step 2: Creating the Window ● Step 3: The Message Loop ● Step 4: the Window Procedure
  • 12. A Simple Window ● A Simple Window
  • 13. Message Handling ● Message Loop ● Window Procedure
  • 14. The Message Loop • retrieves message from the message queue • sends message to the Windows procedure where the messages are processed • loops back and repeats the procedure
  • 15. The Message Loop • Programs generally don't call window procedures directly. • The window procedure is almost always called from Windows itself. • A program can indirectly call its own window procedure by calling a function named SendMessage().
  • 16. The Message Loop • Messages come through in an orderly and synchronized manner. • While processing one message in a window procedure, the program will not be suddenly interrupted by another message.
  • 18. The Message Loop • Message loop retrieves a message from its message queue • Call DispatchMessage() to send the message off to the window procedure • DispatchMessage() does not return until the window procedure has returned control back to Windows.
  • 20. Windows Class and Registration
  • 23. Resources • Standard - icon, cursor, menu, dialog box, bitmap, enhanced metafile, font, accelerator table, message-table entry, string-table entry, or version • Custom - any kind of data that doesn't fall into the previous category (for example a mp3 file or a dictionary database).
  • 24. Three dynamic-link libraries ● Kernel32.dll – File I/O, System,… ● User32.dll – User Interface… ● Gdi32.dll – Fonts, Brushes…
  • 25. First Windows Program • Win32 API ● Win32ASM ● Visual C++ – MFC (Microsoft Foundation Classes) ● BCB (Borland C++ Builder) – VCL (Visual Component Library) ● VB(???) ● .Net(C#, J#, C++, VB.NET) – Windows Form • 但是不論用那種方式,都是可以呼叫 Win32 API
  • 26. Numeric identifiers ● In header file (always called resource.h) ● Example – #define IDMAINMENU 300 – #define IDM_FILE_NEW 301 – #define IDM_FILE_OPEN 302 – #define IDM_FILE_SAVE 303 – #define IDM_FILE_EXIT 304 – #define IDM_HELP_ABOUT 305
  • 27. Something about GetMessage • Warning : Because the return value can be nonzero, zero, or -1, avoid code like this: while (GetMessage( lpMsg, hWnd, 0, 0)) ...
  • 28. Solution BOOL bRet; while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } }
  • 29. Reference ● 深入淺出 MFC ● theForger's Win32 API Programming Tutorial

Editor's Notes

  1. 問在場