Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear?
Why does API created MenuBar disappear? Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
Go Back  Xtreme Visual Basic Talk > > > Why does API created MenuBar disappear?


Reply
 
Thread Tools Display Modes
  #1  
Old 03-24-2015, 08:21 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default Why does API created MenuBar disappear?


This is code I use to create a MenuBar via API.

It will disappear when the MessageBox is clicked.

Can the code be re-written so this doesn't happen?
Code:
Option Explicit

Private Const MF_ENABLED = &H0&
Private Const MF_STRING = &H0&

Private Declare Function CreateMenu Lib "user32" _
    () As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" _
    (ByVal hMenu As Long, _
     ByVal wFlags As Long, _
     ByVal wIDNewItem As Long, _
     ByVal lpNewItem As Any) As Long
Private Declare Function SetMenu Lib "user32" _
    (ByVal hwnd As Long, _
     ByVal hMenu As Long) As Long
Private Declare Function DestroyMenu Lib "user32" _
    (ByVal hMenu As Long) As Long

Dim lMnu As Long
Dim lRes As Long

Private Sub Form_Activate()
    lMnu = CreateMenu()
    lRes = AppendMenu(lMnu, MF_ENABLED Or MF_STRING, 4, ByVal "Edit")
    lRes = SetMenu(Form1.hwnd, lMnu)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    lRes = DestroyMenu(lMnu)
End Sub

Private Sub Command1_Click()
    MsgBox "***?"
End Sub
Reply With Quote
  #2  
Old 03-24-2015, 09:41 AM
OnErr0r's Avatar
OnErr0rWhy does API created MenuBar disappear? OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

That's an IDE problem. If you compile you'll notice the EXE doesn't have that problem. You'll can call SetMenu on WM_NCACTIVATE in the IDE as a workaround.

The Menu Vanishes (Spies! Playing the game of love - and sudden death!)
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #3  
Old 03-24-2015, 12:41 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

Thanks for the reply.

I see (now that you point it out) that code is OK if run from EXE, so I guess this is a non-issue.

Just so everything works in IDE, I did as you suggest but cannot get it working.

My sub-class works OK, but I can't grab the WM_NCACTIVATE and act on it.

Form1 code:
Code:
Option Explicit

Private Sub Form_Activate()
    Dim lRet As Long
    lMnu = CreateMenu()
    lRet = AppendMenu(lMnu, MF_ENABLED Or MF_STRING, 4, ByVal "Edit")
    lRet = SetMenu(Form1.hwnd, lMnu)
End Sub

Private Sub Form_Load()
    Hook (Form1.hwnd)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim lRet As Long
    lRet = DestroyMenu(lMnu)
    Unhook (Form1.hwnd)
End Sub

Private Sub Command1_Click()
    MsgBox "***?"
End Sub
Module1 code:
Code:
Option Explicit

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, _
     ByVal hwnd As Long, ByVal Msg As Long, _
     ByVal wParam As Long, ByVal lParam As Long) As Long

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, _
     ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const GWL_WNDPROC = -4

Public lpPrevWndProc As Long

Public Sub Hook(hwnd As Long)
    lpPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub Unhook(hwnd As Long)
    Dim lRet As Long
    lRet = SetWindowLong(hwnd, GWL_WNDPROC, lpPrevWndProc)
End Sub

Function WindowProc(ByVal hwnd As Long, _
                    ByVal uMsg As Long, _
                    ByVal wParam As Long, _
                    ByVal lParam As Long) As Long

    '#define WM_NCACTIVATE  0x0086

    Debug.Print uMsg

    If uMsg = &H86 Then
        ' Set Menu AGAIN
        Call SetMenu(Form1.hwnd, lMnu)
    End If
    
    WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)

End Function
Module2 code:
Code:
Public Const MF_ENABLED = &H0&
Public Const MF_STRING = &H0&

Public Declare Function CreateMenu Lib "user32" _
    () As Long
Public Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" _
    (ByVal hMenu As Long, _
     ByVal wFlags As Long, _
     ByVal wIDNewItem As Long, _
     ByVal lpNewItem As Any) As Long
Public Declare Function SetMenu Lib "user32" _
    (ByVal hwnd As Long, _
     ByVal hMenu As Long) As Long
Public Declare Function DestroyMenu Lib "user32" _
    (ByVal hMenu As Long) As Long

Public lMnu As Long
Reply With Quote
  #4  
Old 03-24-2015, 08:37 PM
OnErr0r's Avatar
OnErr0rWhy does API created MenuBar disappear? OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

Take a closer look at the example. SetMenu is called AFTER the return of CallWindowProc. This allows the message to be acted upon after the default VB window proc.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #5  
Old 03-25-2015, 12:05 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

Yes that fixes bug in IDE

Thank you!
Code:
Public Const WM_NCACTIVATE = &H86
Code:
Function WindowProc(ByVal hwnd As Long, _
                    ByVal uMsg As Long, _
                    ByVal wParam As Long, _
                    ByVal lParam As Long) As Long

    WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)

    If uMsg = WM_NCACTIVATE Then
        ' Set Menu AGAIN
        Call SetMenu(Form1.hwnd, lMnu)
    End If

End Function
A little explanation of what is going on?

Also, on the subject of EXE's

If I compile my program with all error checking turned off, time to compile is approx. 1 minute.

If I compile with error checking ON, it takes 1 hour and 3 minutes to compile.

Execution speed of both EXE's seem about the same, but I get strange things happening in the 1 minute EXE (no crashing, just questionable results in certain instances).

Is long compile time normal?
Is incorrect program execution in (no error checking) EXE to be expected?
Reply With Quote
  #6  
Old 04-28-2015, 05:04 AM
fafalone fafalone is offline
Freshman
 
Join Date: May 2010
Posts: 37
Default

Either there's something wrong or you have a beyond insane codebase size. My largest project is closing in on 100k lines of code and still only takes a couple minutes to compile.
Have you tried to narrow it down to a specific check? (you're referring to the checks in the 'advanced optimizations' page right?)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
Why does API created MenuBar disappear? Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear? Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
 
Why does API created MenuBar disappear?
Why does API created MenuBar disappear?
 
-->