================================================================================
1、获取窗口句柄
ex1:AfxGetMainWnd()->m_hWnd
ex2:FindWindow
2、获取父窗口指针
GetParent
3、获取窗口的始祖
GetAncestor
4、通过ID获取窗口指针
GetDlgItem
5、获取窗口ID
GetDlgCtrlID
相关:
EnableWindow
IsWindowEnabled
IsWindowVisible
ShowWindow
MoveWindow
GetWindowRect
SetWindowPos
二、创建方法--静态和动态
================================================================================
动态创建:
1、定义资源ID
(方式1:)--在 String Table中 ID编辑框中加入
(方式2:)--在文件中自定义 #define IDC_TEST 100
2、创建控件对象、创建控件
ex1:
CButton *Testbtn = new CButton;
CRect r(50,50,100,100);
Testbtn->Create("Test",BS_CENTER,r,this,IDC_TEST_BUTTON);
Testbtn->ShowWindow(SW_SHOW);
3、改变控件的大小和位置
(方式1:)MoveWindow
(方式2:)SetWindowPos
virtual BOOL SetWindowPos(
const CWnd* pWndInsertAfter,
int x,
int y,
int cx,
int cy,
UINT nFlags
);
参数说明:
pWndInsertAfter,一般设为NULL
三、控件的消息及其处理
================================================================================
1、应用程序向控件发送消息
SendMessage
SendMessage(
(HWND) hWndControl, // handle to destination control
(UINT) BM_SETCHECK, // message ID
(WPARAM) wParam, // = (WPARAM) () wParam;
(LPARAM) lParam // = 0; not used, must be zero
);
wParam
BST_CHECKED
BST_INDETERMINATE
BST_UNCHECKED
设置RadioButton 按钮选中状态
SendMessage(hWndRadioButton,BM_SETCHECK,BST_CHECKED,0);
注意:使用对话框控件,应用程序调用 SendDlgItemMessage 向指定的对话框控件发送消息
LRESULT SendDlgItemMessage(
HWND hDlg,
int nIDDlgItem,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
================================================================================