SDK编程常见api&消息用法01

1.CheckDlgButton

用于设置按钮状态,这个按钮是广义的按钮,包括BS_PUSHBUTTON BS_RADIO BS_CHECKBOX各种风格的按钮。

//函数原型
BOOL CheckDlgButton(  HWND hDlg,      // handle to dialog box
  int nIDButton,  // button identifier  UINT uCheck     // check state);

第一个是HWND 第二个是控件ID,第三个是设置的状态.

ValueMeaning
BST_CHECKED设置按钮状态被点击
BST_INDETERMINATE设置按钮变灰,Use this value only if the button has the BS_3STATE or BS_AUTO3STATE style.
BST_UNCHECKED设置按钮状态不被点击

返回值是0则成功 其他则失败。

2.GetWindowLong&SetWindowLong

函数检索有关指定窗口的信息。 该函数还将指定偏移量处的 32 位(长)值检索到额外的窗口内存中。

LONG GetWindowLong(  HWND hWnd,  // 窗口句柄
  int nIndex  // 填特定的参数以获取改句柄的不同信息;
下面是第二个参数可以填的一些特定值

ValueAction
GWL_EXSTYLERetrieves the extended window styles. For more information, see CreateWindowEx.
GWL_STYLERetrieves the window styles.
GWL_WNDPROCRetrieves the address of the window procedure, or a handle representing the address of the window procedure. You must use the CallWindowProc function to call the window procedure.
GWL_HINSTANCERetrieves a handle to the application instance.
GWL_HWNDPARENTRetrieves a handle to the parent window, if any.
GWL_IDRetrieves the identifier of the window.
GWL_USERDATARetrieves the 32-bit value associated with the window. Each window has a corresponding 32-bit value intended for use by the application that created the window. This value is initially zero.


常用的就是GWL_STYLE,他会返回改窗体的风格,对于不知道风格来加风格非常有用。

例子:比如我想给一个static窗口类添加一个可以显示图片的风格,却又不想改变他原有的风格,这就十分必要需要GetWindowLong这个函数了

​
LONG nStyle = GetWindowLong(hWndBMP, GWL_STYLE);
        GetWindowLong SetWindowLong很重要
        GetWindowLOng  就是获取原有的窗口风格
        然后不改变原有风格的条件下还能加载
        SetWindowLong(hWndBMP, GWL_STYLE,nStyle|SS_BITMAP);

​


当然,这里用到了SetWindowLong,要和GetWindowLOng对应起来使用.
3.SendDlgItemMessage

SDK编程种十分重要的API,因为SDK种是Windows把控件封装好,类似与我们调用的默认窗口处理函数,因此这些预设好的控件的处理函数是类似黑盒样式的。所以想要使用这些控件,SendDlgItemMessage是必不可少的。

LRESULT SendDlgItemMessage(  HWND hDlg,      // 窗口句柄
  int nIDDlgItem, // control identifier  UINT Msg,       // 消息类型
  WPARAM wParam,  // WParam 依据msg定
  LPARAM lParam   // Lparam 依据msg

另外,SendDlgItemMessage(hDlg,IDdlgItem,message,wParam,lParam)=SendMessage(GetDlgItem(hDlg,IDdlgItem),message,wParam,lParam);

是相同的

4.BM_GETCHECK

这是和按钮配套是使用的,获取按钮的HWND句柄后,直接SendMesaage即可作出反应。

注意 wparam和lparam没用 填0;

注意BM家族的都是这样的。

返回值

ValueMeaning
BST_CHECKEDButton is checked.
BST_INDETERMINATEButton is grayed, indicating an indeterminate state (applies only if the button has the BS_3STATE or BS_AUTO3STATE style).
BST_UNCHECKEDButton is cleared

 5.IsDlgButtonChecked(HWND parantHWND,int IDBUTTON)

这个作用类似与知道按钮HWND,SendMessage给按钮 消息填写BM_GETCHECK,

但是这个更简洁

IsDlgButtonChecked(hDlg, IDC_BMP1);只需要知道父窗口句柄以及按钮ID即可。

返回值和上面的是完全一样的。

6.LB_XXXX

LB家族的消息 就是List控件

使用方法还是进行SendMessage();

7.DialogBox&EndDialog

模式对话框的创建和关闭

DialogBox(INSTANCE,parentHWND,ID,WNDPROC);

EndDialog只需要写出HWND和返回值即可

8.GetDlgItemText、GetDlgItem、GetDlgText、Set....

其实前一个都是后面两个经过封装而来的。推荐使用GetDlgItemText和SetDlgItemText来获取控件的内容和设置控件的内容。因为省去了写控件的HWND;

UINT GetDlgItemText(  HWND hDlg,       // handle to dialog box
  int nIDDlgItem,  // control identifier
  LPTSTR lpString, // pointer to buffer for text
  int nMaxCount    // maximum size of string);
BOOL SetDlgItemText(  HWND hDlg,         // handle to dialog box
  int nIDDlgItem,    // control identifier  LPCTSTR lpString   // text to set);

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值