cxpbutton

本文详细介绍了Windows中控制窗口显示的方法,包括使用BringWindowToTop、SetForegroundWindow和SetWindowPos等API函数的区别与应用场景。特别指出不同函数对于窗口所属线程的要求及如何获取窗口的相关信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.codeproject.com/Articles/9919/XButtonXP-an-XP-aware-pushbutton-that-can-also-tog

将窗口移动到前端, BringWindowToTop() 的问题http://blog.youkuaiyun.com/woshinia/article/details/7860924

http://zhidao.baidu.com/link?url=ATkcGNLO0eJtvfoHtR45J-6FITx1z1LCKzEBgi2vCyrnZNvVlApiT1CqPKETFH95yqsJvAKKjrpp5V5KMBfTRa
SetWindowPos 改变比较灵活,功能比较全,而另外两个就比较单一。
使用BringWindowToTop函数显示出被其他窗口部分或全部遮盖的窗口。  
调用这个函数类似于调用SetWindowPos函数来改变窗口在Z序中的位置,
但是BringWindowToTop函数并不能使一个窗口成为顶层窗口。
setforegroundwindow可以把窗口显示到前台窗口,并对系统的原始输入线程设置连接到此窗口所属的线程,这样所有的对输入的操作就输入到这个窗口中,比如说键盘输入。 
bringwindowtotop只适用于对调用bringwindowtotop线程所属的窗口起作用,也就是说 
在A线程中调用了bringwindowtotop()函数,如果函数传递的窗口句柄不是属于A线程的,那么会立即返回,不对任何进行操作。而setForeGroundWindow()函数则没有这个约束。
 

在得到窗口句柄后我们可以通过GetWindowThreadProcessId这个函数来获得窗口所属进程ID和线程ID,从而判断创建窗口的进程和线程。

函数原型:

DWORD GetWindowThreadProcessId(HWND hWnd,LPDWORD lpdwProcessId);

参数说明:

hWnd:传入的窗口句柄;lpdwProcessId:返回的进程ID地址。

返回值:

函数返回的是窗口所属线程ID。

使用例子:

DWORD ProcessID;

DWORD ThreadID;

ThreadID=GetWindowThreadProcessId(hWnd,&ProcessID);


#ifndef _BTNST_H #define _BTNST_H // Uncomment the following line to enable support for sound effects #define BTNST_USE_SOUND #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 // Return values #ifndef BTNST_OK #define BTNST_OK 0 #endif #ifndef BTNST_INVALIDRESOURCE #define BTNST_INVALIDRESOURCE 1 #endif #ifndef BTNST_FAILEDMASK #define BTNST_FAILEDMASK 2 #endif #ifndef BTNST_INVALIDINDEX #define BTNST_INVALIDINDEX 3 #endif #ifndef BTNST_INVALIDALIGN #define BTNST_INVALIDALIGN 4 #endif #ifndef BTNST_BADPARAM #define BTNST_BADPARAM 5 #endif #ifndef BTNST_INVALIDPRESSEDSTYLE #define BTNST_INVALIDPRESSEDSTYLE 6 #endif // Dummy identifier for grayscale icon #ifndef BTNST_AUTO_GRAY #define BTNST_AUTO_GRAY (HICON)(0xffffffff - 1L) #endif class CXPButton : public CButton { public: CXPButton(); ~CXPButton(); enum { ST_ALIGN_HORIZ = 0, // Icon/bitmap on the left, text on the right ST_ALIGN_VERT, // Icon/bitmap on the top, text on the bottom ST_ALIGN_HORIZ_RIGHT, // Icon/bitmap on the right, text on the left ST_ALIGN_OVERLAP // Icon/bitmap on the same space as text }; enum { BTNST_COLOR_BK_IN = 0, // Background color when mouse is INside BTNST_COLOR_FG_IN, // Text color when mouse is INside BTNST_COLOR_BK_OUT, // Background color when mouse is OUTside BTNST_COLOR_FG_OUT, // Text color when mouse is OUTside BTNST_COLOR_BK_FOCUS, // Background color when the button is focused BTNST_COLOR_FG_FOCUS, // Text color when the button is focused BTNST_MAX_COLORS }; enum { BTNST_PRESSED_LEFTRIGHT = 0, // Pressed style from left to right (as usual) BTNST_PRESSED_TOPBOTTOM // Pressed style from top to bottom }; // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CXPButton) public: virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); virtual BOOL PreTranslateMessage(MSG* pMsg); protected: virtual void PreSubclassWindow(); //}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值