Important alert: (current site time 7/16/2013 3:02:04 AM EDT)
 

winzip icon

Updated 3/07 - VB+ASM Subclass, Hook, Timer, Api-Window class thunks, w/ Form fade/shadow sample

Email
Submitted on: 2/3/2003 5:25:46 AM
By: Paul Caton 
Level: Intermediate
User Rating: By 71 Users
Compatibility: VB 5.0, VB 6.0
Views: 93125
 
     Superceded by this submission http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=51403&lngWId=1 Updated 3/07 - Just minor stuff --- My cSuperClass submission's download link appears broken so I thought it was about time I made a new entry. Just as Vlad Vissoultchev's excellent subclasser built on mine and added a hooking thunk, I've done likewise and added timer and api-windows thunks. Each of the thunks has an individual sample to demonstrate its use. If you're blessed with Windows 2000 or Windows XP check out the form shadow/fade user control. Credits: Thanks to Clint LaFever for the idea of a form shadow. http://www.exhedra.com/vb/scripts/ShowCode.asp?txtCodeId=42148&lngWId=1 Thanks to Vlad for his superb subclass/hook thunks http://www.exhedra.com/vb/scripts/ShowCode.asp?txtCodeId=40518&lngWId=1

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 13 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

2/3/2003 5:56:38 AMPaul Caton

Sorry about the text formatting, I supose I should figure out how to html it. Enjoy!!
(If this comment was disrespectful, please report it.)

 
2/3/2003 11:43:29 AMPhantom Man

Out Standing!
5 *****
(If this comment was disrespectful, please report it.)

 
2/3/2003 12:13:36 PM

just as i expected, excellent work :)

5 globes from me :)
(If this comment was disrespectful, please report it.)

 
2/3/2003 2:29:32 PMBrian Battles WS1O

Fine job! 5 globes
(If this comment was disrespectful, please report it.)

 
2/3/2003 4:15:26 PM

A long wait since your last submision, but it was worth it :D.
Thanks.
(If this comment was disrespectful, please report it.)

 
2/3/2003 6:50:13 PMThushan Fernando

great work... i see this will be this months code of the month! we'll 5gz to get you there!
(If this comment was disrespectful, please report it.)

 
2/3/2003 7:14:48 PMsherif rofael

Really great work ,

But let me Say that Your code complicated me ,

how long have u been doing it ?

months man ?

In Addition , How long Have u been Doing VB ?

BTW , 5 Globes from Me.
Regards,

(If this comment was disrespectful, please report it.)

 
2/4/2003 3:42:08 AMOzan Yasin Dogan

Thank you Paul for your super performance tools. I would like you to write some MASM articles too. My 5G is allways for you ! :)
(If this comment was disrespectful, please report it.)

 
2/4/2003 2:01:57 PMCodeFester

Cool submission. Thanks for doing so. 5 ballz w/o hesitation.
(If this comment was disrespectful, please report it.)

 
2/5/2003 6:06:37 PMBrio Networks

I was blown away, awesome code! 5 globes from me.
(If this comment was disrespectful, please report it.)

 
2/6/2003 9:31:26 AMORSHEE

I can notice that PSC is becoming a comunity gathering coders with great ideas and skills.
You're surely one of them.
Greetz and respect.
(If this comment was disrespectful, please report it.)

 
2/6/2003 12:36:29 PMDonathan Hutchings

Great Code! 5 globes from me. Keep up the good work!!!
(If this comment was disrespectful, please report it.)

 
2/8/2003 2:28:13 AM

Hey pual, it would be nice if the cWindow class could have an events owner each window in a single class. this would save me having many instances of the same class just to set the .owner for differnt windows.
(i am useing this for a winsock api project so events need to be trigerd in differnt client classes)
(If this comment was disrespectful, please report it.)

 
2/8/2003 4:44:20 PMPaul Caton

Re the winsock api dude/dudette... Why don't you email and explain how this would work. Can't you just Select Case hWnd in iWindow_WndProc ?
(If this comment was disrespectful, please report it.)

 
2/8/2003 4:50:17 PMPaul Caton

Orzan, believe it or not I'm rubbish at assembler, I used to be pretty good on the Motorola 68000 cpu but when Intel started to dominate I learnt C rather than deal with the bizarre architecture that X86 was, it's better now with the flat memory model.
(If this comment was disrespectful, please report it.)

 
2/8/2003 4:54:21 PMPaul Caton

Sherif, I've worked for Microsoft (manufacturing) quite a bit over the years so I had a copy of VB 1 when it was still in beta (1991??), but just for fun, I didn't start to use it seriously until VB5 was released, up till then C/C++
(If this comment was disrespectful, please report it.)

 
2/8/2003 5:02:23 PMPaul Caton

Thanks to all that voted, you'll be notified when I do an update. The alpha blended AND layered shadow is coming along nicely and is looking sweet, also performance using UpdateLayeredWindow for the shadow windows is that much better that i'm considering HideMove and HideSize defaulting to False.
(If this comment was disrespectful, please report it.)

 
2/8/2003 8:59:52 PM

Useing one window for all the sockets was a much better idea. lol, Thanks for making me feel foolish. hehe
(If this comment was disrespectful, please report it.)

 
2/14/2003 1:07:33 AMjoyprakash saikia

Hi paul,
Thank u for illustrating astounding power of VB inherited from legendy x86 instructions. It is really an awesome submission in PSC. It really deserves more than 5 globes.
I've faced one small unhandled exception in SHADOW control in Windows NT 4.0 with SP 6.0a. The Control was unable to
locate "SetLayeredWindowAttributes" API in user32.dll. so It halts the application containing the Shadow Control.
So my suggestion is, If u handle the entry point of the unsupported APIs with OS version, then an application having shadow control can run on machines having win NT 4.0, Windows 95, windows 98 (1st edition) etc.

(If this comment was disrespectful, please report it.)

 
2/15/2003 5:23:00 AMPraveen Menon

Dus all hav Win2000?
(If this comment was disrespectful, please report it.)

 
2/15/2003 5:57:59 AMPraveen Menon

Great code Paul.. nice work.. we should always try to do work like these... but i dont have a Win2000 Machine to check the SetLayeredWindowAttributes API in action....

Sad for that.. 5 Globes
(If this comment was disrespectful, please report it.)

 
2/15/2003 7:39:53 AMPaul Caton

Joyprakesh, the issue is the use of a type lib. I shouldn't have used one for a function that may not exist on the PC because linked this way the windows program loader tries to resolve the call, fails to find it (Win9x, NT4) and bails the app. One of the few advantages of VB's Declare mechanism is that the link to the function is performed dynamically on call and thus you have the opportunity to skip making calls to functions that don't exist. Anyway, the UpdateLayeredWindow call is now out of the type lib. Upshot being that the control won't display a shadow/fade on 9x/NT 4 - but it won't cause a problem running the app. Sorry about the issue, but it was initialy only written as a demo of the cSubclass and cWindow classes. Seeing as people want to use it I'll endevour to ensure that it's up to production standard. Check the update and let me know.
(If this comment was disrespectful, please report it.)

 
2/15/2003 1:48:47 PMVlad Vissoultchev

paul, shadow is looking much better here now. i'm considering re-implementing my office xp menu shadows.

bugreport: shadow depths of 4 and below

HTH,
</wqw>

(If this comment was disrespectful, please report it.)

 
2/17/2003 12:34:17 AMjoyprakash saikia

Thanx for your updates for win9x and WintNT 4.0 as well as the introduction of
(If this comment was disrespectful, please report it.)

 
2/17/2003 12:35:44 AMjoyprakash saikia

"pLayered" Function for Accurate verification of the shadow effect.

Now It is running Properly with WinNT 4.0 , Win2K and Higher.
Cheers!
(If this comment was disrespectful, please report it.)

 
2/17/2003 9:51:00 AM

5 from me! This is awesome.
I only have 1 problem though: If I compile and execute the Shadow program, the form fades on exit but the program stays in memory. Both on Win 2K and XP Pro. Any idea what I might be doing wrong?
phred@qti.net
(If this comment was disrespectful, please report it.)

 
2/17/2003 11:48:52 AMPaul Caton

It's not your fault, there seems to be an aliasing issue that I haven't yet tracked down. Go to compile options, click advanced and uncheck the aliasing checkbox - the problem will go away. Hopefully I'll find it soon and do an update.
(If this comment was disrespectful, please report it.)

 
2/17/2003 11:51:22 AMPaul Caton

Thanks Vlad, i've found the issue you're refering to. It would've helped if I had access to XP then I'd have seen it straight away. Update coming, but I'd like to try and find the alias compile optimization that's causing problems.
(If this comment was disrespectful, please report it.)

 
2/17/2003 1:35:06 PM

Thanks a ton. I've been using Vlad's subclasser and menus like nuts. Some more subclasser updates and a cool shadow effect will make my apps even cooler. BTW 5 globes.
(If this comment was disrespectful, please report it.)

 
2/17/2003 1:41:33 PMPaul Caton

Update 2/17 - Fixed isssue with depth < 5 on XP. Fixed issue with 'No Aliasing' compiler optimization. Detects Luna theme rather than just assuming if XP. Added IsLuna property. Detects and responds to display and theme changes on the fly.
(If this comment was disrespectful, please report it.)

 
3/6/2003 12:06:11 AM

Could you make a tutorial on how to make our own? personaly i would like to know how to edit the cWindow class. i have masm and know some basic asm. but i dont know where togo from there.
also useing typelibs for implemented interfaces? this is so awsome. but tutorial would be great too. i know your really busy so i wont hold my breath :P
(If this comment was disrespectful, please report it.)

 
3/6/2003 12:56:41 PMPaul Caton

Not that busy... I'm currently looking for some work to keep me amused. I'll look into doing a tutorial soon.
(If this comment was disrespectful, please report it.)

 
3/7/2003 2:59:16 AM

awsome, thanks alot! :D
(If this comment was disrespectful, please report it.)

 
3/19/2003 6:20:15 AM

any updates? *impatiant*
lol
(If this comment was disrespectful, please report it.)

 
3/31/2003 8:40:56 AMAlpha Binary

o_0 AWESOME!!
(If this comment was disrespectful, please report it.)

 
4/4/2003 1:12:46 AMTJ Rode

Paul, I need a hand if you don't mind...

I'm trying to hook system messages globally, such as the WD_MOUSE events, MOVE events, etc. With the "Hooking" project, it seems only to accept messages related to the Thunder/VB project. Any clues as to where I'm going wrong? Thanks. (*****)
(If this comment was disrespectful, please report it.)

 
4/15/2003 8:50:38 AMDefcon2

great!!! 5 globes from me.
(If this comment was disrespectful, please report it.)

 
5/2/2003 4:12:21 AMBram Pelgrom

YEAAAAH! Does this mean that I can *FINALLY* experiment with subclassing, without having to worry about VB crashing? :D 5 Globies from me my friend! :P
(If this comment was disrespectful, please report it.)

 
5/12/2003 9:31:26 AM

This is a nice control. Only one disadvantage I found: When using this control in a MDI form the shadow coordinates will not fix to the MDI coordinates, instead it will follow the screen coordinates. I will try to study the code and do the neccessary, but in case any one updated please send to my mail: abdullahosman@yahoo.com THANX ALL
(If this comment was disrespectful, please report it.)

 
5/14/2003 4:11:22 AMPaul Caton

Re MDI - I probably shouldn't say this is impossible but I think it is. It's easy enoung to correct the coordinates but the problem is that for proper behaviour the shadow windows would need to be MDI children themselves and as far as I can tell the transparent extended style won't work on an MDI child. Feel free to prove me wrong.
(If this comment was disrespectful, please report it.)

 
8/23/2003 10:45:11 AM

This is fking gr8!!!!!
Thanks!!
(If this comment was disrespectful, please report it.)

 
10/7/2003 1:09:23 PMStewart Bland

you made a gd program Paul!!ur a gd programmer
(If this comment was disrespectful, please report it.)

 
12/10/2003 7:14:36 AM

Is it possible to do cross process subclassing with your application ? I would like to subclass an application (for legitimate reasons) without the subclassing code being part of the app.
(If this comment was disrespectful, please report it.)

 
12/10/2003 7:50:33 AMWSC

A lovely code presentation. Thank you.
(If this comment was disrespectful, please report it.)

 
12/11/2003 11:52:34 AMSoorya

hi paul,
No more words to say about ur skill...
it is just 30 mins since i am seeing ur brainy stuff. at present i am searching a timer control, which should support 1 ms and it should be free running (what ever the processing happeing in the windows, the timer firing event should not be interupted.) i had one which is written in C++ with winmm.dll, it is lost... can u pls. help me?.

btw here is my *****
soorya
(If this comment was disrespectful, please report it.)

 
12/21/2003 3:21:18 PMAlfred

Exceptional! Thank you! I would like to have more knowledge about the integration techniques of ASM into VB. Can everybody give me at tip for a good source?
(If this comment was disrespectful, please report it.)

 
12/21/2003 5:53:51 PMPaul Caton

The last four guys got their answers in the post. Unless anybody shares those questions?

Question: why so many votes in December? Has this submission been promoted somehow, by a website or such?

THERE WILL BE AN UPDATE SOON, btw.
(If this comment was disrespectful, please report it.)

 
12/26/2003 11:40:52 AM

YEAH! I cant wait for the update, i love cWindow.cls and the rest (cwindow is great for winsock api projects!) Look forward for your xmas update gift. :D
(If this comment was disrespectful, please report it.)

 
12/26/2003 11:43:36 AM

p.s can you send me an email when you update this?
I really love all our work!
(If this comment was disrespectful, please report it.)

 
4/27/2004 7:48:53 PMFred.cpp

"Users have accessed this code 10000 times" wow, I think this have been seen lot of times.
(If this comment was disrespectful, please report it.)

 
10/19/2012 3:58:26 PMDennis Johnson

I know that it is more than 10 years, but I use this wonderful code a lot and it works flawlessly (almost).
I also made it DEP-compatible by calling VirtualProtect in SubClass routine...
I have recently come across a situation, where I call CreateWindow and I try to subclass the new hWnd. As soon as the first message tries to arrive, the application crashes immediately. Of course, I can subclass the new hWnd by using the classic method of SetWindowLong/CallWindowProc.
If you are still watching your submission, can you provide some advice as to how to overcome this obstacle?
We can talk by e-mail, if you like.
(If this comment was disrespectful, please report it.)

 
10/20/2012 3:34:54 AMDennis Johnson

Never mind about my problem about dynamically created controls with CreateWindow... I downloaded WinSubHook, which has about the same interface with your first subclasser, modified it a bit, so that it fits my projects, and guess what, it does the job I actually wanted!
Once again, thank you for your excellent subclassers!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.