Mac OS X Programming读书笔记5 - Controls

Chapter 5 Controls

1 Command Signatures and Control IDs

1. 可以将CommandControl联系起来,但是当你收到事件的时候,你并不知道当时是哪个Control被按下了。事实上,你也不需要关心,因为Command本来被设计成代表命令,至于是点击Button还是选择菜单都没有关系

2. 当你需要知道Control究竟发生了什么事情的时候,你需要给Control分配一个Control ID,包括:

a. Signature:一个4Char的标记,一般来说应该是程序的Creator Code,也就是Application本身的Signature。大部分情况下,单一程序的所有Control IDSignature都是一样的

b. ID:一个整数,真正的独立在此程序中标记该ControlID

2 Buttons

<shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="Picture_x0020_4" style="VISIBILITY: visible; WIDTH: 134.25pt; HEIGHT: 81pt; mso-wrap-style: square" type="#_x0000_t75" o:spid="_x0000_i1028"><imagedata o:title="" src="file:///D:%5Ctmp%5Cmsohtmlclip1%5C01%5Cclip_image001.emz"></imagedata></shape>

1. Bevel Button

2. ImageWell

3 Radio Buttons

<shape id="Picture_x0020_5" style="VISIBILITY: visible; WIDTH: 134.25pt; HEIGHT: 56.25pt; mso-wrap-style: square" type="#_x0000_t75" o:spid="_x0000_i1027"><imagedata o:title="" src="file:///D:%5Ctmp%5Cmsohtmlclip1%5C01%5Cclip_image002.emz"></imagedata></shape>

系统负责维护Radio Button的状态,不需要自己编程处理。

1: ControlHandle numBeepsRadioButtonGroup;

2: ControlID numBeepsControlID = { kControlSignature, kRadioGroupControlID };

3: GetControlByID( window, &numBeepsControlID,

&numBeepsRadioButtonGroup );

SInt32 numBeepsValue;

4: numBeepsValue = GetControl32BitValue( numBeepsRadioButtonGroup );

1. 声明一个ControlHandle

2. 声明ControlControl ID,也就是这个Radio Button GroupID

3. 通过Control ID获得ControlHandle

4. 通过Handle获得Control32-bit整数值,表示哪一个Radio Button被按下了

4 Checkboxes

<shape id="Picture_x0020_3" style="VISIBILITY: visible; WIDTH: 134.25pt; HEIGHT: 51.75pt; mso-wrap-style: square" type="#_x0000_t75" o:spid="_x0000_i1026"><imagedata o:title="" src="file:///D:%5Ctmp%5Cmsohtmlclip1%5C01%5Cclip_image003.emz"></imagedata></shape>

和上面的非常类似,GetControl32BitValue返回0说明没有Check1则为Checked

5 Text Input Fields

<shape id="Picture_x0020_2" style="VISIBILITY: visible; WIDTH: 179.25pt; HEIGHT: 123pt; mso-wrap-style: square" type="#_x0000_t75" o:spid="_x0000_i1025"><imagedata o:title="" src="file:///D:%5Ctmp%5Cmsohtmlclip1%5C01%5Cclip_image004.emz"></imagedata></shape>

应该使用GetcontrolData来获得Text Input Fields所对应的字符串:

OSErr GetControlData(

ControlRef inControl,

ControlPartCode inPart,

ResType inTagName,

Size inBufferSize,

void * inBuffer,

Size * outActualSize );

1. ControlRef inControlControlRef也就是ControlHandle,所以直接传递用GetControlByID的返回值即可

2. ControlPartCode inPart:指定访问Control的哪一部分,部分Control由多个Control组成,由不同的常量代表不同的子控件。如果没有子控件,可以传递kControlEntireControl代表整个控件本身

3. ResType inTagName:数据的类型,对于Text Input Field应该传递kControlEditTextCFStringTag

4. Size inBufferSize:缓冲区大小

5. Void *inBuffer:缓冲区本身

6. Size *outActualSize:实际大小

举例如下:

CFStringRef theString;

GetControlData(

stringInTextEdit,

kControlEntireControl,

kControlEditTextCFStringTag,

sizeof( CFStringRef ),

&theString,

NULL );

同样的,可以用SetControlData来设置Text Input Field的字符串:

OSErr SetControlData(

ControlRef inControl,

ControlPartCode inPart,

ResType inTagName,

Size inSize,

void * inData);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值