控件编程
1. GUI编程要素——控件、消息与回调函数是怎样的
(1)GUI程序运行流程MATLAB的GUI程序包含两个部分:一个由GUIDE编辑后生成的.fig文件,以及一个同名的.m文件。前者是一个图形(图6-2),由一个窗口和程序界面所需的各种控件,如按钮、输入框、绘图区、滑动条等组成(事实上,装载这些控件的窗口本身也是一个控件)。后者是与前者配套的,主要包括窗口的生成函数和各控制消息的回调函数。
GUI程序运行的流程如图6-3所示。程序首先生成一个窗口;等待并接收消息;在接收到消息后,寻找并执行与该消息对应的回调函数;重复二、三两步直到窗口关闭。GUI程序的.m文件只列出了窗口生成函数和消息回调函数,而消息检测与响应等内核部分由系统自动完成,无需用户参与,因此并没有体现出来。
MATLABGUI程序的.fig文件
2. WIN32编程,如何添加控件
|添加控件的话 可以用CreateWindow 来创建 所有的控件都可以看成是子窗口
例如创建一个按钮:
CreateWindow("button","name",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
0,0,
100,20,
hWnd,
(HMENU)ID_CLOSE,
GetMoleHandle(NULL),
NULL);
上面是创建一个按钮
第一个参数必须是下面的几个
BUTTON
Designates a small rectangular child window that represents a button the user can click to turn it on or off. Button controls can be used alone or in groups, and they can either be labeled or appear without text. Button controls typically change appearance when the user clicks them. For more information, see Buttons.
For a table of the button styles you can specify in the dwStyle parameter, see Button Styles.
COMBOBOX
Designates a control consisting of a list box and a selection field similar to an edit control. When using this style, an application should either display the list box at all times or enable a drop-down list box. If the list box is visible, typing characters into the selection field highlights the first list box entry that matches the characters typed. Conversely, selecting an item in the list box displays the selected text in the selection field.
For more information, see Combo Boxes. For a table of the combo box styles you can specify in the dwStyle parameter, see Combo Box Styles.
EDIT
Designates a rectangular child window into which the user can type text from the keyboard. The user selects the control and gives it the keyboard focus by clicking it or moving to it by pressing the TAB key. The user can type text when the edit control displays a flashing caret; use the mouse to move the cursor, select characters to be replaced, or position the cursor for inserting characters; or use the BACKSPACE key to delete characters. For more information, see Edit Controls.
For a table of the edit control styles you can specify in the dwStyle parameter, see Edit Control Styles.
LISTBOX
Designates a list of character strings. Specify this control whenever an application must present a list of names, such as file names, from which the user can choose. The user can select a string by clicking it. A selected string is highlighted, and a notification message is passed to the parent window. For more information, see List Boxes.
For a table of the list box styles you can specify in the dwStyle parameter, see List Box Styles.
MDICLIENT
Designates an MDI client window. This window receives messages that control the MDI application's child windows. The recommended style bits are WS_CLIPCHILDREN and WS_CHILD. Specify the WS_HSCROLL and WS_VSCROLL styles to create an MDI client window that allows the user to scroll MDI child windows into view.
For more information, see Multiple Document Interface.
RichEdit
Designates a Microsoft Rich Edit 1.0 control. This window lets the user view and edit text with character and paragraph formatting, and can include embedded Component Object Model (COM) objects. For more information, see Rich Edit Controls.
For a table of the rich edit control styles you can specify in the dwStyle parameter, see Rich Edit Control Styles.
RICHEDIT_CLASS
Designates a Rich Edit 2.0 control. This controls let the user view and edit text with character and paragraph formatting, and can include embedded COM objects. For more information, see Rich Edit Controls.
For a table of the rich edit control styles you can specify in the dwStyle parameter, see Rich Edit Control Styles.
SCROLLBAR
Designates a rectangle that contains a scroll box and has direction arrows at both ends. The scroll bar sends a notification message to its parent window whenever the user clicks the control. The parent window is responsible for updating the position of the scroll box, if necessary. For more information, see Scroll Bars.
For a table of the scroll bar control styles you can specify in the dwStyle parameter, see Scroll Bar Control Styles.
STATIC
Designates a simple text field, box, or rectangle used to label, box, or separate other controls. Static controls take no input and provide no output. For more information, see Static Controls.
For a table of the static control styles you can specify in the dwStyle parameter, see Static Control Styles
上面来自MSDN
你创建的时候 注意要加入WS_VISIBLE 和相应的按钮风格