WM_COMMAND user message macro

Here is a nice macro that works very nice if you are working on an MFC project involving user messages. I always got irritated every time I had to add user messages, and sometimes forgot what parameters should be used. This macro pops up a nice dialog box where you just enter your user message (e.g. WM_MYMESSAGE) and it inserts the message body + the line in the AFX_MSG_MAP as well as the line in the header file under AFX_MSG.

It creates the name based on the message, so if it finds "WM_" in the beginning, this is stripped away and replaced with the word "On" just like all the other MFC messages are defined.

It uses another macro you have on your web page called ToggleHandCPP. It should probably be refined better so that it doesn't spew garbage when it is unable to find the header file.

BTW, you have to be in the CPP file to run the macro, if not a message box will pop up. (The macro can be extended to do this switch automatically of course.)

I've been using this for a while and it seems to work just fine. Please report any bugs if you find them.


Sub AddMessage()
'DESCRIPTION: Adds user messages to MFC project (WM_COMMAND)

	ext = ActiveDocument.Name
	pos = Instr(ext, ".")
	if pos > 0 then
		Do While pos <> 1
			ext = Mid(ext, pos, Len(ext) - pos + 1)
			pos = Instr(ext, ".")
		Loop
		ext = LCase(ext)
	end if
	If ext = ".cpp" Then
		msg = InputBox ("Write the message ID:")
		If msg <> "" Then
			'func = LCase(msg)
			If Left(msg, 3) = "WM_" Then
				func = "On" + Mid(msg,4,1) + Mid(LCase(msg),5)
			End If

			ActiveDocument.Selection.EndOfDocument
			ActiveDocument.Selection.FindText "AFX_MSG_MAP", dsMatchBackward
			ActiveDocument.Selection.FindText "AFX_MSG_MAP", dsMatchBackward
			ActiveDocument.Selection.CharRight dsMove, 2
			ActiveDocument.Selection.WordRight dsExtend
			ActiveDocument.Selection.Copy
			ActiveDocument.Selection.EndOfLine
			ActiveDocument.Selection.NewLine
			ActiveDocument.Selection = "ON_MESSAGE("+msg+", "+func+")"
			ActiveDocument.Selection.EndOfDocument
			ActiveDocument.Selection.NewLine
			ActiveDocument.Selection = "LONG "
			ActiveDocument.Selection.Paste
			ActiveDocument.Selection = "::"+func+"( UINT uParam, LONG lParam )"
			ActiveDocument.Selection.NewLine
			ActiveDocument.Selection = "{"
			ActiveDocument.Selection.NewLine
			ActiveDocument.Selection = "return 0;"
			ActiveDocument.Selection.NewLine
			ActiveDocument.Selection.CharLeft
			ActiveDocument.Selection = "}"
			ActiveDocument.Selection.NewLine
			ActiveDocument.Selection.LineUp
			ActiveDocument.Selection.LineUp
			ActiveDocument.Selection.LineUp
			ActiveDocument.Selection.EndOfLine
			ActiveDocument.Selection.NewLine
			ToggleHandCPP
			ActiveDocument.Selection.EndOfDocument
			ActiveDocument.Selection.FindText "AFX_MSG", dsMatchBackward
			ActiveDocument.Selection.LineUp
			ActiveDocument.Selection.EndOfLine
			ActiveDocument.Selection.NewLine
			ActiveDocument.Selection = "afx_msg LONG "+func+"( UINT uParam, LONG lParam );"
			ToggleHandCPP
		End If
	Else
		MsgBox "File is not a .cpp file"
	End If
End Sub


Comments

  • cheap snapbacks free shipping

    Posted by izexpenueMoxjef on 03/29/2013 11:19pm

    [url=http://www.bestcheapsnapbacks.com]cheap snapbacks[/url]wholesale snapbacks [url=http://www.bestcheapsnapbacks.com]cheap snapbacks[/url]snapback hats wholesale [url=http://www.bestcheapsnapbacks.com]cheap snapbacks[/url]cheap sunglasses [url=http://www.bestwholesalehats.com]wholesale snapback hats[/url]oakley sunglasses cheap [url=http://www.cheapforsunglasses.com]cheap oakley[/url]cheap snapbacks free shipping

    Reply
  • ray ban sunglasses cheap

    Posted by kgliliImpumpozz on 03/29/2013 10:03am

    http://fakeGucciwayfarer.webs.com - fake ray ban wayfarer fake oakley sunglasses http://sunglasspomoteauthentic.webs.com - cheap ray ban sunglasses fake ray ban http://onlineguciisunglass.webs.com - cheap ray ban wayfarer cheap ray ban sunglasses http://onlineguciisunglass.webs.com - ray ban for cheap discount ray ban http://onlineguciisunglass.webs.com - cheap ray ban wayfarer cheap sunglasses

    Reply
  • Hot Nurse Bedroom Costume

    Posted by Fishnethm1051 on 03/29/2013 09:30am

    http://SexyTeddies.webs.com - Lingerie TeddiesSo beware of choosing the color for someone with different cultureBabydoll sets work well for any body type http://wholesalesexylingerie.webs.com - sexy lingerie wholesaleSo beware of choosing the color for someone with different culture The look of the lingerie is only half of how it can be considered hot; the way the woman feels when she wears it is the other http://lingeriemall.webs.com - black lace lingerie! As men and women all over the world share their warmth on these cold wintry nights, a celebration of love looms on the horizon, and with it, the promise of the coming spring, The rituals of Valentines Day so often consists of a box of chocolates and some roses, followed by dinner, and an expectation of some better than the usual sex Similar to a corset in design, a teddy is a one piece suit that starts out as a bustier, extends down between the legs as a thong, and ends up fastening to the back of the bodice http://wholesalesexylingerie.webs.com - china wholesale clothingDark blue conveys wisdom, trust and seriousness Then he gets together with his managers and implements procedures to fix what is wrong http://spicylingeries.webs.com - womens lingerie?Lovers?Lanes most popular costume store

    Reply
  • wholesale oakley sunglasses

    Posted by lgliliImpumphhh on 03/28/2013 10:10pm

    http://guccicheapsunglass.webs.com - cheap oakleys cheap oakleys for sale http://bestsunglassesshop.webs.com - cheap fake oakleys cheap fake oakley sunglasses http://discountsunglasseshoo.webs.com - discount ray ban sunglasses akley discount http://cheapsunglassesshop.webs.com - cheap sunglasses,,, wholesale sunglasses china http://sunglasswholesaleofgucci.webs.com - cheap ray ban wayfarer cheap ray ban,,,,

    Reply
  • ugg bank uk

    Posted by Chestereei on 10/28/2012 02:25am

    everythingnfl nike jerseys cheaphappenscheap nfl football jerseyscheatedugg australia italiamemoryugg uk storewrongcheap ugg boots ukeverythingcheap ugg uksweetuggs sale clearance ukwould

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 17, 2014 Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this webcast and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the future state of your servers, …

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds