The 10th lecture - PowerPoint PPT Presentation

Loading...

PPT – The 10th lecture PowerPoint presentation | free to download - id: 7af921-NTJiY



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

The 10th lecture

Description:

Computers and programming The 10th lecture Ji ebesta TOPIC programming in MSVS for Windows Basic definitions Form application Examples Basic definitions (1 ... – PowerPoint PPT presentation

Number of Views:7
Avg rating:3.0/5.0
Slides: 25
Provided by: jmeno
Learn more at: http://www.urel.feec.vutbr.cz
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: The 10th lecture


1
Computers and programming
  • The 10th lecture
  • Jirí Šebesta

2
TOPIC programming in MSVS for Windows
  1. Basic definitions
  2. Form application
  3. Examples

3
Basic definitions (1/4)
  • Project for Windows
  • header files
  • files xxx.h
  • source code files
  • files xxx.c or xxx.cpp
  • resources above all graphic objects determined
    by set of properties and behavior
  • files xxx.rc (xxx.ico)

4
Basic definitions (2/4)
  • Resources
  • menus
  • shortcuts
  • bit rasters, icons, cursors
  • character strings
  • tool panels
  • dialog windows
  • Dialog window
  • fundamental objekt (each window is dialog
    window)
  • control objects in dialog window are again
    dialog windows with special properties
  • applied principle parents vs. childs dialogs

5
Basic definitions (3/4)
  • Dialog window (resp. object)
  • properties variables define a visual
    characteristic and behavior of window (object)
    and events, i.e. functions called if an events in
    window (object) occurs, e.g. click by mouse
  • window modality
  • modal window, cannot be leaved without closing
    (style attribute WS_VISIBLE is set)
  • unmodal window can be whenever leaved (defocused)

6
Basic definitions (4/4)
  • Fundamental sorts of Win applications
  • using MFC (Microsoft Foundation Class Library)
  • SDI (Single-document interface) application
    using one document
  • MDI (Multiple-document interface) application
    using more documents at the same time (e.g. MS
    Visual Studio is MDI application)
  • Dialog application single dialog window for
    simple programs
  • using standard resources from Windows
  • Form application for Windows

7
Form application (1/10)
  • Form project establishment (MSVS 2008/10/12)

8
Form application (2/10)
  • Form creating (setting of properties
    inserting of standard graphic objects to design
    Form1.hdesign)

9
Form application (3/10)
  • Automatically generated code for setting of
    graphic object properties in Form1.h

this-gtColorBox-gtBackColor systemDrawingCo
lorTransparent this-gtColorBox-gtControls-gtAdd(th
is-gtRB_blue) this-gtColorBox-gtControls-gtAdd(this-gt
RB_green) this-gtColorBox-gtControls-gtAdd(this-gtRB_
red) this-gtColorBox-gtForeColor
systemDrawingSystemColorsControlText thi
s-gtColorBox-gtLocation SystemDrawingPoint(2,
86) this-gtColorBox-gtName L"ColorBox" this-gtCol
orBox-gtSize SystemDrawingSize(88,
100) this-gtColorBox-gtTabIndex
1 this-gtColorBox-gtTabStop false this-gtColorBox
-gtText L"Color"
  • this is pointer to this form

10
Form application (4/10)
  • Function generation for event processing
  • in Form1.h a header of function for events is
    generated, required code can be written into the
    body of this function

private SystemVoid RB_blue_Click(SystemObje
ct sender, SystemEventArgs e)
this-gtMy_text-gtForeColor
SystemDrawingColorBlue
11
Form application (5/10)
  • Function main() in Ex76.cpp

include "stdafx.h" include "Form1.h" using
namespace Ex76 STAThreadAttribute int
main(arrayltSystemString gt args) //
Enabling Windows XP visual effects before any
controls are created ApplicationEnableVisualSty
les() ApplicationSetCompatibleTextRenderingDef
ault (false) // Create the main window and
run it ApplicationRun(gcnew Form1()) return
0
Code Ex76
12
Form application (6/10)
  • Windows Form application in MSVS2013 new project
  • A form application can not be established
    directly
  • It needs to insert an empty project of type CLR
    Empty Project with adequate name

13
Form application (7/10)
  • A form application required an adding UI
    Windows Form with adequate name, e.g. MyForm.h or
    Form.h, by Project Add (use right mouse
    button)

14
Form application (8/10)
  • Insert to MyForm.cpp following code

include "MyForm.h" using namespace System using
namespace SystemWindowsForms STAThread vo
id Main(arrayltSystemString gt
args) ApplicationEnableVisualStyles() Appl
icationSetCompatibleTextRenderingDefault
(false) Ex76MyForm form ApplicationRun(
form) return 0
  • Modify code according to project name and form
    name

15
Form application (9/10)
  • Set in Project Properties Linker - System

16
Form application (10/10)
  • Set Linker Advanced Entry Point to name of
    starting function, e.g. Main

17
Examples (1/7)
  • 1) Create a form application for a simple
    calculator adding, subtracting, multiplying and
    division of two rational numbers.
  • Visual design of form

18
Examples (2/7)
Function for text reading from the TextBox and
conversion to double
double get_A(void) return SystemConvertToD
ouble(this-gttext_A-gtText) double
get_B(void) return SystemConvertToDouble(t
his-gttext_B-gtText)
object of form TextBox named as text_B
conversion method calling
variable of TextBox
pointer to this form
19
Examples (3/7)
Event processing pressing of particular buttons
private SystemVoid bt_plus_Click(SystemObject
sender, SystemEventArgs e)
this-gtRes-gtText SystemConvertToS
tring(get_A()get_B()) private
SystemVoid bt_div_Click(SystemObject
sender, SystemEventArgs e) this-gtRes-gtText
SystemConvertToString(get_A()/get_B
())
conversion method calling
function for inputs reading calling
pointer to this form
function of class System
Code Ex77
20
Examples (4/7)
  • 2) Create an form application for simple database
    of computers (items producer, price and memory
    capacity) with record up to 20 computers using
    dynamic access.
  • Visual design of form

21
Examples (5/7)
Building-up of own function library computer.h
include ltstdlib.hgt include ltstring.hgt typedef
struct t_pc char prod 20 // name of the
producer int price // price of the
computer float mem // RAM capacity in GB
a_pc void add(char _prod, int _price, float
_mem) // adding new
computer void sort(void) // sorting according
to the price t_pc get_fwd(void) // point out to
the next computer t_pc get_bwd(void) // point
out to the prev. computer int show_price(void)//
get price of an added pc int show_cheap(void)//
get price of the cheapest pc
22
Examples (6/7)
Array of pointers to records declaration
solution example of the function add() in
computer.cpp
include "computer.h" // definition of the struct
t_pc t_pc register20 // array of pointers to
computers int index0 // first free position in
the katalog int ptrindex-1 // pointer to a pc
displayed in edits void add(char _prod, int
_price, float _mem) t_pc my_pc my_pc
(t_pc) malloc(sizeof(t_pc)) strcpy(my_pc-gtprod,
_prod) my_pc-gtprice _price my_pc-gtmem
_mem registerptrindex my_pc
23
Examples (7/7)
Adding the library pocitac.h and processing of
event for pressing button Add in Form1.h
pragma once include "computer.h" using
namespace SystemRuntimeInteropServices namesp
ace Ex78 . private SystemVoid
AddBtn_Click(SystemObject sender,
SystemEventArgs e) add((char)MarshalStri
ngToHGlobalAnsi(ProdEdit-gtText).ToPointer(),
SystemConvertToInt32(PriceEdit-gtText),
SystemConvertToDouble(MemEdit-gtText)) ShowLbl
-gtText SystemConvertToString(show_price())

conversion method VisualString gt char calling
Code Ex78
24
TOPIC OF THE NEXT LECTURE
  1. FINAL TEST

THANK YOU FOR YOUR ATTENTION
About PowerShow.com