1 CS1253 VISUAL PROGRAMMING UNIT I WINDOWS PROGRAMMING Windows environment – a simple windows program – windows and messages – creating the window – displaying the window – message loop – the window procedure – message processing – text output – painting and repainting – introduction to GDI – device context – basic drawing – child window controls
48
Embed
1 CS1253 VISUAL PROGRAMMING UNIT I WINDOWS PROGRAMMING Windows environment – a simple windows program – windows and messages – creating the window – displaying.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
CS1253 VISUAL PROGRAMMING
UNIT I WINDOWS PROGRAMMINGWindows environment – a simple windows program – windows and messages – creating the window – displaying the window – message loop – the window procedure – message processing – text output – painting and repainting – introduction to GDI – device context – basic drawing – child window controls
2
CS1253 VISUAL PROGRAMMING
UNIT II VISUAL C++ PROGRAMMING – INTRODUCTION
Application Framework – MFC library – Visual C++ Components – Event Handling – Mapping modes – colors – fonts – modal and modeless dialog – windows common controls – bitmaps
3
CS1253 VISUAL PROGRAMMING
UNIT III THE DOCUMENT AND VIEW ARCHITECTURE
Menus – Keyboard accelerators – rich edit control – toolbars – status bars – reusable frame window base class – separating document from its view – reading and writing SDI and MDI documents – splitter window and multiple views – creating DLLs – dialog based applications
4
CS1253 VISUAL PROGRAMMING
UNIT IV ACTIVEX AND OBJECT LINKING AND EMBEDDING (OLE)
ActiveX controls Vs. Ordinary Windows Controls – Installing ActiveX controls – Calendar Control – ActiveX control container programming – create ActiveX control at runtime – Component Object Model (COM) – containment and aggregation Vs. inheritance – OLE drag and drop – OLE embedded component and containers – sample applications
5
CS1253 VISUAL PROGRAMMING
UNIT-V ADVANCED CONCEPTS
Database Management with Microsoft ODBC – Structured Query Language – MFC ODBC classes – sample database applications – filter and sort strings – DAO concepts – displaying database records in scrolling view – Threading – VC++ Networking issues – Winsock – WinInet – building a web client – Internet Information Server – ISAPI server extension – chat application – playing and multimedia (sound and video) files
6
CS1253 VISUAL PROGRAMMING
TEXT BOOKS
1.Charles Petzold, “Windows Programming”, Microsoft press, 1996 (Unit I – Chapter 1-9)
2.David J.Kruglinski, George Shepherd and Scot Wingo, “Programming Visual C++”, Microsoft press, 1999 (Unit II – V)
REFERENCES
1.Steve Holtzner, “Visual C++ 6 Programming”, Wiley Dreamtech India Pvt. Ltd., 2003.
7
UNIT – I
Windows Programming
Text Book :
Charles Petzold, “Windows Programming”, Microsoft press, 1996
(Unit I – Chapter 1-9)
8
Windows ProgrammingHistory of Windows:
IBM PC – 1981
OS – MSDOS ( Microsoft Disk Operating System)
– MS DOS was minimal operating system.
– For the user, it provided a command-line interface to
commands such as DIR and TYPE and loaded
application programs into memory for execution.
9
Windows ProgrammingHistory of Windows:
• For the application programmer, MS-DOS offered little more
than a set of function calls for doing file input/output (I/O).
• For other tasks—in particular, writing text and sometimes
graphics to the video display—applications accessed the
hardware of the PC directly.
10
Windows ProgrammingHistory of Windows:
Apple Computer – Jan 1983
• OS - Lisa
• set a standard for graphical environments with
Macintosh in Jan 1984.
Windows
• announced by Microsoft corporation in Nov 1983 (post-Lisa but
pre-Macintosh)
11
Windows ProgrammingHistory of Windows:
Windows1.0
• Nov 1985.
• with several updates to support the international market.
• with additional drivers for additional video displays and
printers.
12
Windows ProgrammingHistory of Windows:
Windows2.0
• Nov 1987.
• with several changes to the user interface.
• also enhancements to the keyboard and mouse interface,
particularly for menus and dialog boxes.
13
Windows ProgrammingHistory of Windows:
Windows2.0
• requires only Intel 8086 or 8088 microprocessor running in
"real mode" to access 1 megabyte (MB) of memory.
Windows/386
• released shortly after Windows 2.0
• used the "virtual 86" mode of the Intel 386 microprocessor to
window
• multitask many DOS programs that directly accessed
hardware.
14
Windows ProgrammingHistory of Windows:
Windows/286
• Windows 2.1 was renamed Windows/286.
Windows3.0
• May 22, 1990.
• Windows/286 and Windows/386 versions were merged into one
product with this release.
15
Windows ProgrammingHistory of Windows:
Windows3.1 – April 1992
• several significant features included the TrueType font
technology, multimedia (sound and music), Object Linking and
Embedding (OLE), and standardized common dialog boxes.
• ran only in protected mode.
• required a 286 or 386 processor with at least 1 MB of memory.
16
Windows ProgrammingHistory of Windows:
WindowsNT – July 1993
• was the first version of Windows to support the 32-bit mode of
the Intel 386, 486, and Pentium microprocessors.
• Programs that run under Windows NT have access to a 32-bit
flat address space and use a 32-bit instruction set.
• required a 286 or 386 processor with at least 1 MB of was also
designed to be portable to non-Intel processors.
• it runs on several RISC-based workstations.
17
Windows ProgrammingHistory of Windows:
Windows95 – Aug 1995
• also supported the 32-bit programming mode of the Intel 386
and later microprocessors.
• Adv - requiring fewer hardware resources.
• Dis adv - lacked some of the features of Windows NT, such as
It is declared in WINBASE.H like so (line breaks and all):
int
WINAPI
WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
); LPSTR & PSTR are two data types defined in WINNT.H as pointers
to character strings. The LP prefix stands for "long pointer“.
33
Simple Windows ProgramPrefix Data Typeb BOOLc or ch charclr COLORREFcx, cy Horizontal or vertical distancedw DWORDh Handlel LONGn intp Pointersz Zero-terminated stringw WORDwnd CWndstr CStringm_ class member variable
Hungarian Notation
Note:Prefixes can be combined:
pszNamem_nAge
34
Simple Windows ProgramProgram Entry Point:
WinMain Parameters:
First parameter -
• It is something called an "instance handle“.
• In Windows programming, a handle is simply a number that an
application uses to identify something.
• In this case, the handle uniquely identifies the program.
35
Simple Windows ProgramProgram Entry Point:
WinMain Parameters:
Second parameter -
• A program could determine if other instances of itself were
running by checking the hPrevInstance parameter.
• It could then skip certain chores and move some data from the
previous instance into its own data area.
• In the 32-bit versions of Windows, this concept has been abandoned. The second parameter to WinMain is always NULL (defined as 0).
36
Simple Windows ProgramProgram Entry Point:
WinMain Parameters:
Third parameter -
• is the command line used to run the program.
• Some Windows applications use this to load a file into memory
when the program is started.
Fourth parameter –
• indicates how the program should be initially displayed—either
normally or maximized to fill the window, or minimized to be
displayed in the task list bar.
37
Simple Windows ProgramMessageBox Function:
It is designed to display short messages.
The little window that MessageBox displays is actually considered
to be a dialog box, although not one with a lot of versatility.
For example,
MessageBox (NULL, TEXT ("Hello, Windows 98!"),
TEXT("HelloMsg"), 0) ;
38
Simple Windows ProgramMessageBox Function:
Parameters:
First Parameter - is normally a window handle.
Second Parameter - is the text string that appears in the body
of the message box.
Third Parameter - is the text string that appears in the caption bar of the message box.
39
Simple Windows ProgramMessageBox Function:
Parameters:
Fourth Parameter - can be a combination of constants beginning with the prefix MB_ that are defined in WINUSER.H.
• can pick one constant from the first set to indicate what buttons you
wish to appear in the dialog box:
40
Simple Windows ProgramMessageBox Function:
Buttons:
#define MB_OK 0x00000000L
#define MB_OKCANCEL 0x00000001L
#define MB_ABORTRETRYIGNORE 0x00000002L
#define MB_YESNOCANCEL 0x00000003L
#define MB_YESNO 0x00000004L
#define MB_RETRYCANCEL 0x00000005L
Note: When set the fourth argument to 0, only the OK button
appears in the message box.
41
Simple Windows ProgramMessageBox Function:
Buttons:
can use the OR (|) operator to combine one of the constants
shown above with a constant that indicates which of the buttons is
the default:
#define MB_DEFBUTTON1 0x00000000L
#define MB_DEFBUTTON2 0x00000100L
#define MB_DEFBUTTON3 0x00000200L
#define MB_DEFBUTTON4 0x00000300L
42
Simple Windows ProgramMessageBox Function:
Buttons:
can also use a constant that indicates the appearance of an icon in the message box: