首页
社区
课程
招聘
[求助]SetWindowLong
发表于: 2009-4-1 15:38 8982

[求助]SetWindowLong

2009-4-1 15:38
8982
invoke SetWindowLong,hButn,0,hBrush1      ; butn up colour
    invoke SetWindowLong,hButn,4,hBrush2      ; butn down colour
    invoke SetWindowLong,hButn,8,ID           ; control ID number
    invoke SetWindowLong,hButn,12,alignment   ; text alignment
    invoke SetWindowLong,hButn,16,0           ; text upcolour
    invoke SetWindowLong,hButn,20,0           ; text dncolour
    invoke SetWindowLong,hButn,24,0           ; offset for font handle
    invoke SetWindowLong,hButn,28,0   
请问第2个参数,(0,4 8 12...........)代表什么意思,查看了winuser.h关于按钮样式,还是不明白什么意思,谁能把SetWindowlong这种用法解说一下,谢谢帮助!

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (9)
雪    币: 206
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
装个MSDN 或2003 SDK SP1
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.

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.

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.

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.
GWL_EXSTYLE
Sets a new extended window style. For more information, see CreateWindowEx.
GWL_STYLE
Sets a new window style.
GWL_WNDPROC
Sets 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_HINSTANCE
Sets a new application instance handle.
GWL_ID
Sets a new identifier of the window.
GWL_USERDATA
Sets 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.
DWL_DLGPROC
Sets the new address of the dialog box procedure.
DWL_MSGRESULT
Sets the return value of a message processed in the dialog box procedure.
DWL_USER
Sets 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.

If the function fails, the return value is zero. To get extended error information, call 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.

Remarks

Certain window data is cached, so changes you make using SetWindowLong 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.

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.

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 procedure receiving a window message, the nested window message could overwrite the return value you set using 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.

Reserve extra window memory by specifying a nonzero value in the cbWndExtra member of the WNDCLASSEX structure used with the RegisterClassEx function.

You must not call SetWindowLong with the GWL_HWNDPARENT index to change the parent of a child window. Instead, use the SetParent function.

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.

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.
2009-4-1 16:37
0
雪    币: 206
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
哦,不对,没注意,不好意思楼主。你有VC么,随便一个版本的。从MSDN中查到的SetWindowLong参数中选一个XXXX写到VC文件中来,然后再点击右键->Go To Definition of  XXXX 你应该能看到Winuser.h或Windows.h中那些参数定义的数值了,你再把你上面提问的那些数字参数对应上那些定义的值就可以了。、
2009-4-1 16:47
0
雪    币: 6857
活跃值: (3348)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
谢谢在vc里以看过,(invoke SetWindowLong,hButn,0,hBrush1      ; butn up colour
    invoke SetWindowLong,hButn,4,hBrush2      ; butn down colour)第2个index和上面对不起来,不明白(0,4)什么意思,不过还是谢谢你!
2009-4-1 19:30
0
雪    币: 2110
活跃值: (21)
能力值: (RANK:260 )
在线值:
发帖
回帖
粉丝
5
对应不上,看一下SDK的头文件中这些常量定义的值,就能对应上了:

GWL_EXSTYLE

GWL_STYLE

GWL_WNDPROC

GWL_HINSTANCE

GWL_ID

GWL_USERDATA

DWL_DLGPROC

DWL_MSGRESULT

DWL_USER
2009-4-2 14:41
0
雪    币: 148
活跃值: (12)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
这些常量为什么是英文字母的.
我听说中文版VC中也是英文的.晕
2009-4-2 15:08
0
雪    币: 6857
活跃值: (3348)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
invoke SetWindowLong,hButn,0,hBrush1  winuser.h里对过了,hbrush1对GWL_HINSTANCE=-6不明白为什么是0,还有个是4,谢谢,书呆大哥,能不能在帮助一下,等待中,谢谢!
2009-4-2 19:57
0
雪    币: 2384
活跃值: (766)
能力值: (RANK:410 )
在线值:
发帖
回帖
粉丝
8
从这个操作上来看,你那个hButn控件应该是属于一个自定义的控件(不是Windows预定的)。而那些索引的功能也只有写该控件的作者才能给你答案(因为那些都不是Windows预定的索引,这个索引除了使用Windows预定的之外,还可以由开发者自定义的),因为这个索引除了Windows预订的之外,有些开发者在写开发自定义控件的时候开发者可能会自己从(Get)SetWindowLong中保存和获取一些数据以进行交互作用。
2009-4-2 20:06
0
雪    币: 6857
活跃值: (3348)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
谢谢小虾,明白了。
2009-4-2 20:18
0
雪    币: 67
活跃值: (546)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
高手都是。。不太明白
2010-12-29 18:39
0
游客
登录 | 注册 方可回帖
返回
//