对话框常用方法

BOOL Create( LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL );

BOOL Create( UINT nIDTemplate, CWnd* pParentWnd = NULL );

lpszTemplateName:标识资源模板名称。

pParentWnd:标识父窗口的指针。

nIDTemplate:标识对话框资源ID。

void NextDlgCtrl( ) const;

该方法是对话框上一个控件获得焦点。If the focus is at the last control in the dialog box, it moves to the first control

void PrevDlgCtrl( ) const;

Sets the focus to the previous control in the dialog box. If the focus is at the first control in the dialog box, it moves to the last control in the box.

void GotoDlgCtrl( CWnd* pWndCtrl );

Moves the focus to the specified control in the dialog box.call the CWnd::GetDlgItem member function, which returns a pointer to a CWnd object.

void SetDefID( UINT nID );

该方法是将某个按钮设置为窗口的默认按钮。

void EndDialog( int nResult );

该方法用来关闭一个模态对话框

virtual BOOL OnInitDialog( );

当窗口响应WM_INITDIALOG消息时,系统将调用OnInitDialog( )方法。WM_INITDIALOG消息在对话框创建之后,显示之前产生。

返回值:当窗口为对话框中的控件获得焦点时,返回值为非0,否则为0

virtual void OnOK( );

该方法在用户单击“OK”按钮(按钮ID为IDOK)时调用。OnOk方法在 内部调用了EndDialog方法,因此,用户单击“OK”按钮时关闭对话框。通常情况下,用户需要改写该方法,禁止调用基类的ONOK方法。

virtual void OnCancel( );

该方法是一个虚拟方法,用户可以改写该方法,实现自己的动作,默认情况下,OnCancel方法在内部调用EndDialog方法。如果用户在一个非模态对话框中实现OnCancel方法,需要在内部调用DestroyWindow方法,不要调用基类的OnCancel方法,因为它调用EndDialog方法将使对话框不可见,但不销毁对话框。

virtual BOOL DestroyWindow( );

该方法销毁窗口,但不释放窗口对象。如果窗口是一个父窗口,调用该窗口的DestroyWindow方法时,将销毁所有的子窗口。

virtual BOOL PreCreateWindow( CREATESTRUCT& cs );

该方法在关联CWnd对象的窗口被创建之前调用。用户通过该写该方法,可以修改窗口的风格。

cs:标识窗口结构的信息

typedef struct tagCREATESTRUCT {
   LPVOID    lpCreateParams;
   HANDLE    hInstance;
   HMENU     hMenu;
   HWND      hwndParent;
   int       cy;
   int       cx;
   int       y;
   int       x;
   LONG      style;
   LPCSTR    lpszName;
   LPCSTR    lpszClass;
   DWORD     dwExStyle;
} CREATESTRUCT;

BOOL Attach( HWND hWndNew );

该方法关联一个窗口句柄到CWnd对象上。

HWND Detach( );

该方法将窗口句柄从CWnd对象上分离出去。

static CWnd* PASCAL FromHandle( HWND hWnd );

该方法根据窗口句柄返回一个窗口对象

hWnd:标识一个窗口句柄。如何窗口句柄没有关联窗口对象,一个临时对象将被创建。

static CWnd* PASCAL FromHandlePermanent( HWND hWnd );

该方法根据窗口句柄返回一个窗口对象。与FromHandle方法不同的是,如果窗口句柄没有关联窗口对象,返回值为NULL,该方法不创建临时窗口对象。

static void PASCAL DeleteTempMap( );

该方法有应用程序自动调用,在系统空闲时,调用该方法删除由FromHandle方法创建的临时对象

HWND GetSafeHwnd( ) const;

Returns m_hWnd, or NULL if the this pointer is NULL.

BOOL IsWindowEnabled( ) const;

Determines whether the window is enabled for mouse and keyboard input

BOOL EnableWindow( BOOL bEnable = TRUE );

确定窗口是否可用。

static CWnd* PASCAL GetActiveWindow( );

该方法用于获得当前活动的窗口。

CWnd* SetActiveWindow( );

该方法将窗口设置为当前活动窗口。

返回值:返回值是之前的活动窗口。

static CWnd* PASCAL GetCapture( );

该方法用于获取鼠标捕捉的窗口。如果没有鼠标捕捉的窗口,返回值为NULL

在指定的时刻,,只能有一个窗口被捕捉。

CWnd* SetCapture( );

该方法将一系列鼠标输入发送到CWnd对象,而不考虑鼠标的当前位置

返回值:函数返回值是之前鼠标捕捉的窗口。

CWnd* SetFocus( );

该方法使窗口获得焦点

返回值:函数调用前获得焦点的窗口。

static CWnd* PASCAL GetFocus( );

该方法返回当前获得焦点的窗口。

static CWnd* PASCAL GetDesktopWindow( );

返回Windows桌面窗口。

static CWnd* PASCAL GetForegroundWindow( );

返回顶层窗口的指针。

HICON SetIcon( HICON hIcon, BOOL bBigIcon );

该方法用于设置窗口图标。

hIcon:标识图标句柄。

bBigIcon:标识是否设置大图标。

返回值:返回前窗口的图标句柄。

BOOL ModifyStyle( DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0 );

dwRemove,被移除的窗口风格

dwAdd:添加的窗口风格。

nFlags:标识是否调整窗口位置

SWP_NOSIZE:保留当前的大小。

SWP_NOMOVE:保留当前位置

SWP_NOZORDER:保留当前的z轴顺序

SWP_NOACTIVE:不激活这个窗口

void MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );

void MoveWindow( LPCRECT lpRect, BOOL bRepaint = TRUE );

该方法用于改变窗口的大小和位置

x,y:标识窗口左上角坐标

nHeight,nWidth:标识窗口宽度和高度

lpRect:标识窗口的显示区域。

bRepaint:标识窗口是否重画

BOOL SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );

该方法用于设置窗口的大小和位置。

pWndInsertAfter:标识那个窗口之后显示该窗口

x,y:标识窗口的左上角坐标。

cx,cy:标识窗口的宽度和高度。

nFlags:窗口的位置和大小选项。

void GetClientRect( LPRECT lpRect ) const;

该方法用于获得窗口的客户区域。

static CWnd* PASCAL WindowFromPoint( POINT point );

该方法根据坐标点返回一个窗口。

point:以屏幕像素为单位标识一个坐标点。

CWnd* GetDlgItem( int nID ) const;

void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;

nID:标识窗口ID。

phWnd:用于返回窗口指针。

BOOL UpdateData( BOOL bSaveAndValidate = TRUE );

该方法用于获得或设置对话框相关控件的数据。

bSaveAndValidate :标识是设置数据还是获取数据,如果为FALSE,将设置对话框数据,若为TRUE获取对话框数据。‘

void Print( CDC* pDC, DWORD dwFlags ) const;

该方法在指定的设备上绘制窗口。

pDC:标识一个设备的指针,通常为打印机画布指针。

DwFlags:绘制窗口的标识,可选值如下:

PRF_CHECKVISIBLE:如果窗口可见,进行绘制

PRF_CHILDREN:绘制所有可见的子窗口

PRF_CLIENT::绘制窗口的客户区域

PRF_ERASEBKGND:绘制窗口前,擦除窗口的背景色。

PRF_NONCLIENT:绘制窗口的非客户区域

PRF_OWNED:绘制所有窗口拥有的子窗口。

CDC* GetDC( );

该方法用于返回窗口客户区的设备描述体指针

CDC* GetWindowDC( );

该方法用于返回整个出阿哥看的设备表述体指针

int ReleaseDC( CDC* pDC );

该方法用于释放一个设备描述体,其产生的作用依赖于设备描述体的类型。

void Invalidate( BOOL bErase = TRUE );

该方法使窗口整个客户区域无效。当WM_PAIT消息发生时,将重绘窗口

bErase:标识窗口的跟新区域是否被擦除。如果为TRUE,更新区域的背景被擦除,否则,更新区域的背景不被擦除。

BOOL ShowWindow( int nCmdShow );

该方法控制窗口的显示。

nCmdShow:窗口的可见状态,可选值如下。

  • SW_HIDE   Hides this window and passes activation to another window.

  • SW_MINIMIZE   Minimizes the window and activates the top-level window in the system’s list.

  • SW_RESTORE   Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position.

  • SW_SHOW   Activates the window and displays it in its current size and position.

  • SW_SHOWMAXIMIZED   Activates the window and displays it as a maximized window.

  • SW_SHOWMINIMIZED   Activates the window and displays it as an icon.

  • SW_SHOWMINNOACTIVE   Displays the window as an icon. The window that is currently active remains active.

  • SW_SHOWNA   Displays the window in its current state. The window that is currently active remains active.

  • SW_SHOWNOACTIVATE   Displays the window in its most recent size and position. The window that is currently active remains active.

  • SW_SHOWNORMAL   Activates and displays the window. If the window  is minimized or maximized, Windows restores it to its original size and position.

BOOL IsWindowVisible( ) const;

该方法确定窗口是否可见

void ClientToScreen( LPPOINT lpPoint ) const;

void ClientToScreen( LPRECT lpRect ) const;

该方法将点或区域的客户坐标转换为屏幕坐标

void ScreenToClient( LPPOINT lpPoint ) const;

void ScreenToClient( LPRECT lpRect ) const;

该方法将点或区域的屏幕坐标转换为客户坐标

void SetWindowText( LPCTSTR lpszString );

该方法用于设置窗口的文本

int GetWindowText( LPTSTR lpszStringBuf, int nMaxCount ) const;

void GetWindowText( CString& rString ) const;

获取窗口的文本。

pszStringBuf:标识一个缓存区

nMaxCount :标识复制到缓冲区中最大的字符数量。

void SetFont( CFont* pFont, BOOL bRedraw = TRUE );

该方法用于设置窗口的字体

pFont:标识字体指针

bRedraw:标识是否重画窗口。

CMenu* GetMenu( ) const;

该方法用于获取与窗口关联的菜单对象。

BOOL SetMenu( CMenu* pMenu );

该方法用于为窗口设置菜单。

BOOL EnableToolTips( BOOL bEnable );

该方法用于确定是否激活工具提示

UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );

该方法用于设置系统定时器

nIDEvent:定时器标识

nElapse:以毫秒为单位标识时间间隔

lpfnTimer:是一个函数指针,每隔nElapse时间,系统将调用lpfnTimer函数,如果lpfnTimer为NULL,WM_TIMER消息处理函数将被调用。

LRESULT SendMessage( UINT message, WPARAM wParam = 0, LPARAM lParam = 0 );

该方法将某个消息发送你刚到窗口过程中。

message:表示消息ID

wParam/lParam:标识消息的附加信息

说明:该方法将消息发送到窗口过程,知道窗口过程处理了该消息才返回

BOOL PostMessage( UINT message, WPARAM wParam = 0, LPARAM lParam = 0 );

该方法吧消息发送到窗口消息队列,并立即返回。

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值