Click to See Complete Forum and Search --> : Message box display...
jagadishkumar
March 21st, 2000, 08:19 PM
I have a MDI Application which looks for some user preferences in the Windows Registry. If the preferences are not found, default values are set from a .reg file.
The problem is when the values in .reg file are added to the registry, the system displays a message box saying "Information in xxx.reg successfully added to the registry". Is there any way I can avoid displaying this message box?
I use ShellExecute to run the .reg file.
Thanx in advance.
-Jagadish.
Ravi Kiran
March 22nd, 2000, 01:16 AM
If you look at the registry, .reg files are run/opened by regedit.exe.... so i was wondering if there is any "silent" command line option like "/s" or something, but i was not able to get the command line options listed - done typically by "> regedit /?" or "> regedit -help" from a dos window.
There are 2 solutions i can think of.. not sure which will work.. if you want to give them a try:
1. Start the process with ShellExecuteEx.
and use WaitForInputIdle. This wait will break the momemt the msgbox is displayed by Regedit.exe, then post a "enter" with sendkeys.
just the other day i posted some similar code.. but someone added a comment saying that some problem with Appactivate line in that code..check it out.
OR
2. Use a system level hook ( as shown elsewhere by Aaron Young's post on Msgbox) all message boxes are derived from same class, so you can use that code to find out when the msgbox was created, and post a wm_close or wm_quit using that window handle.. i think
Or 3. write your own set of Registry addition class. There are good articles codeguru vb-articles sectoin. Be sure to check them.
RK
Chris Eastwood
March 22nd, 2000, 02:48 AM
You can trap the MsgBox using Aaron's Code (as pointed out by Ravi) from :
http://codeguru.developer.com/vb/articles/2064.shtml
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
Ravi Kiran
March 22nd, 2000, 03:30 AM
Oh!, nice.. its been added as an article.
I was just thinking of adding "AutoClose" feature to it with WM_TIMER event, and add a event proc to handle that....
RK
Chris Eastwood
March 22nd, 2000, 04:03 AM
>Oh!, nice.. its been added as an article.
Yep - Aaron was nice enough to say to me 'If you like any of my posts, feel free to post them as articles'.
>I was just thinking of adding "AutoClose" feature to it with WM_TIMER
>event, and add a event proc to handle that....
That sound's good - I have seen a similar bit of code somewhere (I think it was on Karl Petersons site (http://www.mvps.org/vb), but I'm not sure.
I can't add any more articles to the site for the next couple of weeks as we're redesigning the server-side of CG (and some other EarthWeb sites) - the redesign is looking pretty exciting, but that's all I can tell you for now.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
jagadishkumar
March 22nd, 2000, 05:40 AM
Thanx Kiran.
I am sort of doing something similar to ur second option. Here is the code.
private Sub LoadPrefs()
Dim lRetVal as Long
lRetVal = ShellExecute(me.hWnd, "open", strRegFilePath, "", "", essSW_SHOWNORMAL)
if lRetVal > 32 then Timer1.Enabled = true
'Other code...
End Sub
private Sub Timer1_Timer()
Dim lRetVal as Long
Dim hWnd as Long
Timer2.Enabled = false
'Find the messagebox with the title "Registry Editor" and close it.
hWnd = FindWindow(vbNullString, "Registry Editor")
lRetVal = SendMessage(hWnd, WM_CLOSE, 0, 0)
End Sub
If I call FindMessage and SendMessage immediately after calling ShellExecute, it doesn't work. That's why I call it in a timer.
When I do this, the messagebox is displayed and then closed. I am trying to avoid the messagebox displayed.
Thanx again.
Kyle Burns
March 22nd, 2000, 10:28 AM
Why not use the Registry API functions to add these values?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.