I've been trying to add a few extra cytes to a window an use them with SetWindowLong. However, it says access denied when I use SetWindowLong. Here's the code:
mov wc.lpfnWndProc, OFFSET MemoryProc
mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
mov wc.cbWndExtra, 4
mov wc.lpszClassName,OFFSET MemoryClass
mov wc.lpszMenuName,NULL
mov wc.hbrBackground,COLOR_WINDOW
invoke LoadIcon, hInstance, IDI_ICON2
mov wc.hIcon,eax
invoke DestroyIcon, eax
invoke RegisterClassEx, ADDR wc
invoke CreateWindowEx, WS_EX_MDICHILD,
ADDR MemoryClass, ADDR szMemory,
0,
0, 0, 796, 140,
hClient, NULL, hInstance, NULL
push eax
invoke CreateWindowEx, 0,
ADDR RichEditClass, ADDR NullString,
WS_CHILDWINDOW or WS_VISIBLE or ES_MULTILINE or\
ES_SAVESEL or WS_VSCROLL or WS_HSCROLL or ES_AUTOHSCROLL or \
ES_AUTOVSCROLL or ES_NOHIDESEL or ES_READONLY,
0, 0, 788, 113,
eax, NULL,
hInstance, NULL
pop ebx
invoke SetWindowLong, ebx, 0, eax
Try:
invoke SetWindowLong, ebx, GWL_USERDATA, eax
First things first.
Check whether your CreateWindowEx call is successful. Your method of accessing the extra bytes is correct. You may think that it's not successful because SetWindowLong returns 0.
This is a bit bewildering to a beginner. SetWindowLong normally returns the previous value of the dword you replaced. However, the previous value of the window extra bytes in your case is 0. Thus SetWindowLong returns 0 but it did not set the last error.
Ernie: GWL_USERDATA is not the same as window extra bytes
Hel,
have a look at the "BmpButton" procedure in the latest service pack for MASM32, it does this stuff properly.
1st. Set the mov wc.cbWndExtra, 16 member of the WNDCLASSEX structure with the number of bytes you need,(this allocates the space)
2nd. After the window has been created and you have a valid windows handle, then use SetWindowLong() as follows,
invoke SetWindowLong,hButn1,0,hBmpU
In this example, hButn1 is the valid windows handle, 0 is the offset and hBmpU is the value to put at that offset in extra windows memory. Limit on win95 is 40 bytes.
If you wish to change a preset value for the window class, use the constants from the win32.hlp file instead of the offset from 0 to 36.
Regards,
hutch@pbq.com.au
Iczelion, I think you're right that there is no error. I have another program where I did the same thing successfully. It's probably the code that uses the set data that doesn't work, which led me to believe SetWindowLong is the problem, so I'll take a look at that code instaead. Thnx a lot.