MFC SetWindowLong 函数

隐藏和显示标题栏 在设计窗体时,有时需要动态的显示或者隐藏窗体标题栏,可以通过API函数GetWindowLong、SetWindowLong和SetWindowPos来实现。 GetWindowLong函数能够获得指定窗口的信息,其语法结构为: LONG WINAPI GetWindowLong(          _In_  HWND hWnd,          _In_  阅读详情


The SetWindowLong function changes an attribute of the specified window. The function also sets the 32-bit (long) value at the specified offset into the extra window memory.【SetWindowLong函数更改指定窗口的一项属性。该函数还可将指定偏移的32位值设置到附加的窗口内存中。】

Note This function has been superseded by the SetWindowLongPtr function. To write code that is compatible with both 32-bit and 64-bit versions of Microsoft Windows, use the SetWindowLongPtr function. 【注意 该函数已被SetWindowLongPtr函数取代。要编写与32位和64位版本微软Windows系统兼容的代码,使用SetWindowLongPtr函数。】

Syntax(语法)

LONG SetWindowLong (
	HWND hWnd,
    int nIndex,
    LONG dwNewLong
);

Parameters(参数)

hWnd
[in] 输入参数
Handle to the window and, indirectly, the class to which the window belongs.
Windows 95/98/Me: The SetWindowLong function may fail if the window specified by the hWnd parameter does not belong to the same process as the calling thread. 【指向窗口和窗口所属类的句柄。Windows 95/98/Me: 如果由hWnd参数指定的窗口与调用线程不属于同一进程,SetWindowLong 函数可能会失败。】

nIndex
[in] 输入参数
Specifies the zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer. To set any other value, specify one of the following values. 【指定要设置的值的基于零的偏移。有效值的范围为0到附加的窗口内存的字节数减去一个整数的大小。要设置任何其他值,请指定以下值之一。】

GWL_EXSTYLESets a new extended window style. For more information, see CreateWindowEx. 【设置新的扩展窗样式。有关详细信息,请参阅CreateWindowEx。】
GWL_STYLESets a new window style.【设置新的窗样式。】
GWL_WNDPROCSets a new address for the window procedure. Windows NT/2000/XP: You cannot change this attribute if the window does not belong to the same process as the calling thread.【设置窗口过程的新地址。如果窗口与调用线程不属于同一进程,则不能更改此属性。
GWL_HINSTANCESets a new application instance handle. 【设置新的应用程序实例句柄。】
GWL_IDSets a new identifier of the window. 【设置窗口的新标识符。】
GWL_USERDATASets the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero. 【设置与窗口关联的用户数据。此数据供创建窗口的应用程序使用。其值最初为零。】

The following values are also available when the hWnd parameter identifies a dialog box.【当hWnd参数标识对话框时,以下值也可用。】

DWL_DLGPROCSets the new address of the dialog box procedure. 【设置对话框过程的新地址。】
DWL_MSGRESULTSets the return value of a message processed in the dialog box procedure. 【设置对话框过程中处理的消息的返回值。】
DWL_USERSets new extra information that is private to the application, such as handles or pointers.【设置应用程序专用的新附加信息,如句柄或指针。】

dwNewLong
[in] 输入参数
Specifies the replacement value. 【指定替换值。】

Return Value(返回值)

If the function succeeds, the return value is the previous value of the specified 32-bit integer.【如果函数成功,则返回值是指定的32位整数的前一个值。】

If the function fails, the return value is zero. To get extended error information, call GetLastError. 【如果函数失败,则返回值为零。要获取扩展错误信息,请调用GetLastError。】

If the previous value of the specified 32-bit integer is zero, and the function succeeds, the return value is zero, but the function does not clear the last error information. This makes it difficult to determine success or failure. To deal with this, you should clear the last error information by calling SetLastError(0) before calling SetWindowLong. Then, function failure will be indicated by a return value of zero and a GetLastError result that is nonzero. 【如果指定的32位整数的前一个值为零,并且函数成功,则返回值为零,但函数不清除最后的错误信息。这使得很难决定成败。为了解决这个问题,您应该在调用SetWindowLong之前通过调用SetLastError(0)来清除最后的错误信息。然后,函数失败将由返回值0和非零的GetLastError结果指示。】

Remarks(备注)

Certain window data is cached, so changes you make using SetWindowPos will not take effect until you call the SetWindowPos function. Specifically, if you change any of the frame styles, you must call SetWindowPos with the SWP_FRAMECHANGED flag for the cache to be updated properly. 【某些窗口数据是缓存的,因此在调用SetWindowPos函数之前,使用SetWindowLong所做的更改不会生效。特别是,如果更改任何框架样式,则必须使用SWP_FRAMECHANGED标志调用SetWindowPos才能正确更新缓存。】

If you use SetWindowLong with the GWL_WNDPROC index to replace the window procedure, the window procedure must conform to the guidelines specified in the description of the WindowProc callback function. 【如果将SetWindowLong与GWL_WNDPROC一起使用来替换窗口过程,则新的窗口过程必须符合WindowProc回调函数说明中指定的准则。】

If you use SetWindowLong with the DWL_MSGRESULT index to set the return value for a message processed by a dialog procedure, you should return TRUE directly afterward. Otherwise, if you call any function that results in your dialog receiving a window message, the nested window message could overwrite the return value you set using DWL_MSGRESULT. 【如果将SetWindowLong与DWL_MSGRESULT一起使用,为对话框过程处理的消息设置返回值,则应在其后直接返回TRUE。否则,如果调用导致对话框过程接收窗口消息的任何函数,则嵌套的窗口消息可能会覆盖使用DWL_MSGRESULT.设置的返回值。】

Calling SetWindowLong with the GWL_WNDPROC index creates a subclass of the window class used to create the window. An application can subclass a system class, but should not subclass a window class created by another process. The SetWindowLong function creates the window subclass by changing the window procedure associated with a particular window class, causing the system to call the new window procedure instead of the previous one. An application must pass any messages not processed by the new window procedure to the previous window procedure by calling CallWindowProc. This allows the application to create a chain of window procedures. 【用GWL_WNDPROC调用SetWindowLong将创建用于创建窗口的窗口类的子类。应用程序可以子类化系统类,但不应子类化由另一个进程创建的窗口类。SetWindowLong函数通过更改与特定窗口类关联的窗口过程来创建窗口子类,从而使系统调用新的窗口过程而不是前一个窗口过程。应用程序必须通过调用CallWindowProc将新窗口过程未处理的任何消息传递给上一个窗口过程。这允许应用程序创建一系列窗口过程。】

Reserve extra window memory by specifying a nonzero value in the cbWndExtra member of the WNDCLASSEX structure used with the RegisterClassEx function. 【通过在与RegisterClassEx函数一起使用的WNDCLASSEX结构的cbWndExtra成员中指定一个非零值来保留附加窗口内存。】

You must not call SetWindowLong with the GWL_HWNDPARENT index to change the parent of a child window. Instead, use the SetParent function. 【不能使用GWL_HWNDPARENT调用SetWindowLong来更改子窗口的父窗口。相反,使用SetParent函数。】

If the window has a class style of CS_CLASSDC or CS_OWNDC, do not set the extended window styles WS_EX_COMPOSITED or WS_EX_LAYERED. 【如果窗口的类样式为CS_CLASSDC或CS_OWNDC,请不要将扩展窗口样式设置为WS_EX_COMPOSITED或WS_EX_LAYERED。】

Windows XP/Vista: Calling SetWindowLong to set the style on a progressbar will reset its position. 【Windows XP/Vista:调用SetWindowLong设置进度条上的样式将重置其位置。】

Windows 95/98/Me: SetWindowLongW is supported by the Microsoft Layer for Unicode (MSLU). SetWindowLongA is also supported to provide more consistent behavior across all Windows operating systems. To use these versions, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems World Wide Web link.【Windows 95/98/Me: Microsoft Layer for Unicode(MSLU)支持SetWindowLongW。SetWindowLongA还支持在所有Windows操作系统中提供更一致的行为。要使用这些版本,必须将某些文件添加到应用程序中,如Microsoft Layer for Unicode on Windows 95/98/Me Systems World Wide Web链接中所述。】

心得体会

MFC设置透明窗口 在MFC中,通过设置透明窗口,可以得到有对应透明度的窗口: 如果是对话框,则在OnInitDialog中加上以下代码: SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,   GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0X80000);  HINSTANCE hInst = LoadLibrary 阅读详情

相关推荐

MFC学习笔记(五):控件二

的功能,它使程序能够列出 Windows shell 项。使用的显示格式类似于资源管理器窗口的列表视图的格式。控件支持每个项最多三个图像:一个用于选定状态,一个用于未选定状态,一个用于覆盖图像。可用于Button、CheckBox、Radio Button。如果窗口不属于与调用线程相同的进程,则无法更改此属性。不清楚为什么静态创建出来在VS2019上无法运行。通过为图像列表提供支持扩展组合框控件。参数标识对话框时,也可以使用以下值。窗口的句柄,间接地是窗口所属的类。要设置的值的从零开始的偏移量。

hd51cc的博客 1022

Windows API函数SetWindowLong

SetWindowLong()用于改变一个窗口的属性。 LONG SetWindowLong( HWND hWnd, //handle to window(窗口句柄) int nlndex, //offset of value to set(改变窗口上的何种属性) LONG dwNewLong // new value(指定该属性为一个新的具体样式) ); 窗口属性包括窗口的样式(GWL_STYLE)、扩展...

zxf347085420的博客 4097

MFC学习笔记之六————更改appwizard生成的窗口外观

要更改应用程序的窗口的外观,我们可以在两个时候更改,一是在应用程序窗口创建之前,二是在应用程序窗口创建之后进行更改。本文将两种方式记录下来。      在窗口创建之前修改: 我们之前已经知道,在应用程序窗口创建之前会调用一个叫PreCreateWindow()的函数,要想在窗

Natepan的专栏 982

SetWindowLong和SetWindowPos函数详解

一个应用程序可以一个系统美为于类,但是不能以一个其他进程产生的窗口类为子类,SetwindowLong函数通过改变与一个特殊的窗口类相联系的窗口过程来创建窗口子类,从而使系统调用新的窗口过程而不是以前定义的窗口过程。Windows CE:如果这是一个可见的顶层窗口,并且未指定SWP_NOACTIVATE标志,则这个函数将激活窗口、如果这是当前的激活窗口,并且指定了SWP_NOACTIVATE或SWP_HIDEWINDOW标志,则激活另外一个可见的顶层窗口。SWP_NOACTIVATE:不激活窗口。

m0_37346206的博客 4404

C++程序编程中的 SetWindowLong 函数的几个常见用途(附源码)

本文讲解C++程序编程中的 SetWindowLong 几个常见用法。

dvlinker的技术专栏 446

利用ArcGIS创建渔网计算渔网内土地利用占比划分中国北方农牧交错带

依据土地利用数据,根据参考文献划分要求,利用ArcGIS创建渔网对地物进行重分类,划分农业带、牧业带以及农牧交错带。

m0_60672527的博客 3060

MFC 重新定义窗口函数的代码

最近在看游戏传奇2的源代码,发现里面的很多方法值得借鉴,特此分享一下 有时候我们需要使用MFC内置的窗口类来创建一个窗口,但是窗口类是MFC提前注册的,不是自己定义的窗口类,因此不能指定窗口函数来自己处理窗口消息。但是下面的代码就可以在创建好窗口后,重新指定窗口函数:     m_hChatEdit = CreateWindowEx(WS_EX_CLIENTEDGE, _T("EDIT"), ...

hacker_lpy的博客 805

本体(Ontology)概述

认识本体        本体(Ontology)的概念源自于哲学领域,在哲学中的定义为“对世界上客观事物的系统描述,即存在论”。哲学中的本体关心的是客观现实的抽象本质。而在计算机领域,本体可以在语义层次上描述知识,可以看成描述某个学科领域知识的一个通用概念模型。德国学者Studer在1998年给出了本体的相关定义“本体是共享概念模型的形式化规范说明”。这个定义包含了四层含义:即共享(share)...

baijinswpu的博客 7万+

MFC窗口透明

在OnCreate()或OnInitDialog()加入以下代码 SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE)^WS_EX_LAYERED); SetLayeredWindowAttributes(RGB(0, 0, 0), 125,

1394

从零到一:手把手教你用Verilog在FPGA上构建自己的FFT处理器(不依赖IP核)

本文详细介绍了如何从零开始使用Verilog在FPGA上构建256点FFT处理器,不依赖商业IP核。内容涵盖FFT算法基础、蝶形运算单元设计、整体架构实现、时序收敛优化策略以及测试验证方法,重点提升FPGA上算法部署的运行效率与资源利用率。

vv45678的博客 822

STM32 BootLoader 入门教程:从原理到 APP 跳转实现

在 STM32 项目开发中,BootLoader 通常用于实现固件升级、程序引导和应用程序校验。本文从最基础的 BootLoader 原理开始,讲解 STM32 内部 Flash 分区设计、APP 地址偏移、向量表重定位、BootLoader 跳转 APP 的核心代码,以及实际开发中常见的问题。本文适合刚开始接触 STM32 BootLoader、IAP 在线升级、串口升级、OTA 升级的开发者阅读。

lidecong133的博客 1674

MFC SetWindowLong支持功能

原型: WINUSERAPI LONG WINAPI SetWindowLongA( _In_ HWND hWnd, _In_ int nIndex, _In_ LONG dwNewLong); WINUSERAPI LONG WINAPI SetWindowLongW( _In_ HWND hWnd, _In_ int nIndex, _In_ LONG dwNewLong); #ifdef UNICODE #define SetWindowLong S...

kevin的博客 697

【电容/电感】电路板会“滋滋”的响,我们称它为啸叫

一、啸叫的起源 大部分硬件工程师应该都遇到过,PCBA上电后出现“滋滋滋”的叫声,其声响或大或小,或时有时无,或深沉或刺耳,或变化无常者皆有。该现象我们称为“啸叫”,一般分为电感啸叫和电容啸叫。

云轩阁 6万+

VS2015 MFC 修改应用程窗口大小 标题

******窗口创建之前修改MFC窗口大小************************* 一 创建单文档程序,CMainFrame::PreCreateWindow(CREATESTRUCT&cs)。 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateW...

weixin_33785108的博客 1114

Transformer实战(38)——视觉Transformer (Vision Transformer, ViT)

Transformer 在自然语言处理 (NLP) 领域取得了显著成就,在许多不同的任务中都表现出色。在本节中,我们将探索视觉 Transformer (Vision Transformer, ViT) 模型。正如 NLP 领域创建了多种模型一样,视觉领域也开发了多种模型,每种模型都为计算机视觉提供了新的视角。通过本节,将学习如何使用 ViT 等模型进行计算机视觉任务,了解基于 Transformer 的预训练计算机视觉模型的工作原理,以及如何针对特定任务进行微调。

盼小辉丶的博客 2884

30、模态组合规则在振动分析中的应用

本文详细介绍了模态组合规则在振动分析中的应用,重点讨论了绝对峰值叠加法(SRSS)和完全二次组合(CQC)的理论基础、应用场景及优缺点。通过具体工程实例,展示了模态组合规则在地震载荷下结构响应分析中的实际效果,并提供了应用步骤和注意事项,为结构设计和安全评估提供了科学依据。

nice1的博客 222

MFC中固定(锁定)界面窗口大小的函数

【01】【函数】 SetWindowLong(m_hWnd, GWL_STYLE, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX); 【02】【操作方法】 在你的xxxDlg.cpp中的OnInitDialog()中,将上面的函数复制并放到OnInitDialog()中,如我自己的: BOOL Cvoice2...

Soar_dream的博客 2422

图解目标检测 之 YOLO 算法 最全原理详解

YOLO 一.背景 YOLO(You Only Look Once: Unified, Real-Time Object Detection),是Joseph Redmon和Ali Farhadi等人于2015年提出的基于单个神经网络的目标检测系统。在2017年CVPR上,Joseph Redmon和Ali Farhadi又发表的YOLO 2,进一步提高了检测的精度和速度。 二.YOLO算法的网...

DFCED的博客 26万+

MFC中如何使用拦截消息

拦截消息是可以修改控件或者窗口现有的功能,MFC的子类化技术用C++语言把Windows窗口和各种控件镜像包装,是MFC的核心技术。 以文本框为例,使其只能输入数字。核心原理是一个文本框就是一个窗口,而每一个窗口都有自己的窗口过程。 主要会使用到一下三个函数: SetWindowLong() SetWindowLong是一个Windows API函数。该函数用来改变指定窗口的属性.函数也将指定的一个32位值设置在窗口的额外存储空间的指定偏移位置。 CallWindowProc() CallWindowPr

qq_43812868的博客 1509

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

窗口子类化

关于Win32与MFC中窗口子类化的实现,附有源码...

走在成长的路上 1405

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

在MFC的窗口创建之后修改窗口的标题

说明:先建立一个单文档SDI的工程,工程名任取,注意,这个是“文档”,在MFC里,封装了一些信息,框架的默认默认窗口样式(style)是WS_OVERLAPPEDWINDOW和FWS_ADDTOTITLE的组合,FWS_ADDTOTITLE的意思是把文档的标题作为框架窗口的标题,因此,要去掉这个。 框架窗口创建之后修改,在 CMainFrame的OnCreate( )函数中编写代码修改。 方法

1003

MFC中窗体的控制

1、在CMainFrame的PreCreateWindow(CREATESTRUCT& cs)函数中,加入:    cs.cx=300;    cs.cy=400;即可控制窗体初始化时的大小。 2、加入这段代码可以设置一个没有“最小化”按钮和“最大化”按钮,也没有大小可调边框的主框架窗口。此窗口最初在屏幕上居中。    cs.style = WS_OVERLAPPED | WS_SYSMENU |

李孟的专栏 2847

day2 – 最小MFC和消息响应

可以双击button写代码,除了按钮其他的右击 删掉双击出不来 子类化:扩展控件的功能 重写控件的过程函数实现自己的功能,核心函数 SetWindowLong MFC中子类化 创建新的类,继承MFC对应的控件类 在新的类中实现所需要的逻辑代码 为对应的控件创建对应的MFC控件类的变量,将变量类型改成自己新创建的类 DDX void CMFCApplication1Dlg::DoDataEx...

Break-attack的博客 116

mfc窗口去掉标题栏、边框和菜单栏

系统:window xp sp3 编译器:visual studio 2010 项目:基于对话框的MFC应用程序 编译器:vs 2010 所使用函数: //去除标题栏及其他样式 SetWindowLong(m_hWnd,GWL_STYLE,WS_OVERLAPPED); //去除边框及其他样式 SetWindowLong(m_hWnd,GWL_EXSTYLE,WS_EX_LTRREADING); //使SetWindowLong函数的更改生效,如果不使用此函数,去除边框后 //窗口四周...

bmjhappy的专栏 1863

MFC不规则窗口

直接在OnPaint()函数里添加语句 SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); SetLayeredWindowAttributes(RGB(255,255,255), 0, LWA_COLORKEY); RGB用拾色器拾取 第三个参数

许博文的专栏 1万+
上一篇: MFC BLENDFUNCTION 结构体
下一篇: MFC GetLastError 函数
sty_app
博客等级 码龄12年 9粉丝 25原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值