CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 1999
    Location
    Tokyo, Japan.
    Posts
    57

    Message box display...

    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.


  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Message box display...

    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

  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Message box display...

    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

  4. #4
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Message box display...

    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

  5. #5
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Message box display...

    >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

  6. #6
    Join Date
    May 1999
    Location
    Tokyo, Japan.
    Posts
    57

    Re: Message box display...

    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.


  7. #7
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: Message box display...

    Why not use the Registry API functions to add these values?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured