Question icon in the Title Bar

Just starting out? Need help? Post your questions and find answers here.
PureBaser
User
User
Posts: 33
Joined: Mon Apr 10, 2006 8:47 pm
Location: Berlin, Germany
Contact:

Question icon in the Title Bar

Post by PureBaser »

Hi!
Does one of you know, how I can create the interrogation mark in the title bar next to the minimize-, resize- and close- gadgets ?
PB 4 | WinXP_SP2
xgp
Enthusiast
Enthusiast
Posts: 128
Joined: Mon Jun 13, 2005 6:03 pm

Post by xgp »

SetWindowLong_() and #WS_EX_CONTEXHELP

Just modified a bit.
This code was written by Sparkie ( http://www.purebasic.fr/english/viewtopic.php?t=15277 )

Code: Select all

If OpenWindow(0, 100, 100, 320, 300,  "SetWindowLong_() Test", #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
  ButtonGadget(0, 10, 10, 100, 20, "ContextHelp")
  Repeat
    event = WaitWindowEvent()
    If event = #PB_Event_Gadget And EventGadget() = 0
      oldStyle = GetWindowLong_(WindowID(0), #GWL_EXSTYLE)
      SetWindowLong_(WindowID(0), #GWL_EXSTYLE, oldStyle | #WS_EX_CONTEXTHELP)
      DisableGadget(0, 1)
      SetWindowPos_(WindowID(0), 0, -1 , -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_NOZORDER  | #SWP_FRAMECHANGED | #SWP_SHOWWINDOW)
    EndIf
  Until event = #PB_Event_CloseWindow
EndIf
End
Then, just WM_HELP on your callback.
Phoenix
Enthusiast
Enthusiast
Posts: 141
Joined: Sun Sep 04, 2005 2:25 am

Post by Phoenix »

Why does this give an Illegal Memory Access on the Repeat/Until line?????

Code: Select all

Procedure MyCallback(WindowID,Message,wParam,lParam)
  Result=#PB_ProcessPureBasicEvents
  Select Message
    Case #WM_HELP
      Debug "help"
  EndSelect
  ProcedureReturn Result
EndProcedure
If OpenWindow(0,300,350,400,200,"test",#PB_Window_SystemMenu|#PB_Window_Invisible)
  SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_CONTEXTHELP)
  ShowWindow_(WindowID(0),#SW_SHOW)
  SetWindowCallback(@MyCallback)
  Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Phoenix wrote:Why does this give an Illegal Memory Access on the Repeat/Until line?????

Code: Select all

Procedure MyCallback(WindowID,Message,wParam,lParam)
  Result=#PB_ProcessPureBasicEvents
  Select Message
    Case #WM_HELP
      Debug "help"
  EndSelect
  ProcedureReturn Result
EndProcedure
If OpenWindow(0,300,350,400,200,"test",#PB_Window_SystemMenu|#PB_Window_Invisible)
  SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_CONTEXTHELP)
  ShowWindow_(WindowID(0),#SW_SHOW)
  SetWindowCallback(@MyCallback)
  Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Because you point the callback to the memory position that the variable 'MyCallback' is stored, you should use '@MyCallback()' instead! If you use PB4 you should enable explicit mode to avoid these kind of misstakes..
xgp
Enthusiast
Enthusiast
Posts: 128
Joined: Mon Jun 13, 2005 6:03 pm

Post by xgp »

Here is an example i've just made, hope anyone can understand this piece of code.

Update: Added menus ( I misunderstood at first, the WM_HELP is called when you press F1 )

Code: Select all

#Button1 = 0
#Button2 = 1

#MenuItem1  =   0
#MenuItem2  =   1


Procedure WinCallback(WinID, message, wParam, lParam)
    
    
    If message  =   #WM_HELP
        
        ; lparam returns a pointer to the HELPINFO structure
        *Help.HELPINFO = lParam
        If *Help\iContextType   =   #HELPINFO_WINDOW
            MessageRequester("Help", "Help on:" +Chr(13)+Chr(10) + GetGadgetText(*Help\iCtrlId))
        Else
            MessageRequester("Help", "Help on:" +Chr(13)+Chr(10) + GetMenuItemText(0, *Help\iCtrlId))
        EndIf
        
    EndIf
    
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure


If OpenWindow(0, 100, 100, 200, 200, "ContextHelp Example", #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
    
    ButtonGadget(#Button1, 10, 10, 100, 20, "HelpOnMe 1")
    ButtonGadget(#Button2, 10, 40, 100, 20, "HelpOnMe 2")
    
    CreateMenu(0, WindowID(0))
    MenuTitle("Simple Menu")
    MenuItem(#MenuItem1, "Item 1")
    MenuItem(#MenuItem2, "Item 2")
    
    ; let's put that <question icon> on the titlebar
    SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_CONTEXTHELP)
    SetWindowPos_(WindowID(0), 0, -1 , -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_NOZORDER  | #SWP_FRAMECHANGED | #SWP_SHOWWINDOW)
    
    SetWindowCallback(@WinCallback())
    Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow 
EndIf
Last edited by xgp on Tue May 30, 2006 7:47 pm, edited 1 time in total.
User avatar
travismcgee
New User
New User
Posts: 9
Joined: Mon May 29, 2006 2:16 am

Post by travismcgee »

@xgp: Thank you, that will be very useful.
PureBaser
User
User
Posts: 33
Joined: Mon Apr 10, 2006 8:47 pm
Location: Berlin, Germany
Contact:

Post by PureBaser »

Thanks too! :D
PB 4 | WinXP_SP2
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Very nice. Thanks.

cheers
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post by Konne »

What do I have to change that I can also use the Minimize and Maximize gadget?
Apart from that Mrs Lincoln, how was the show?
xgp
Enthusiast
Enthusiast
Posts: 128
Joined: Mon Jun 13, 2005 6:03 pm

Post by xgp »

Konne wrote:What do I have to change that I can also use the Minimize and Maximize gadget?
It might not be possible without some workaround, i think ( hope to be wrong ).
Win32 Programmer's Reference wrote:WS_EX_CONTEXTHELP
Includes a question mark in the title bar of the window. When the user clicks the question mark, the cursor changes to a question mark with a pointer. If the user then clicks a child window, the child receives a WM_HELP message. The child window should pass the message to the parent window procedure, which should call the WinHelp function using the HELP_WM_HELP command. The Help application displays a pop-up window that typically contains help for the child window.WS_EX_CONTEXTHELP cannot be used with the WS_MAXIMIZEBOX or WS_MINIMIZEBOX styles.
Post Reply