Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Some "corrections" for Msgbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Some "corrections" for Msgbox

    This code demonstrates how to center Msgbox on "parent" window and to change names of buttons
    Code:
       #Compile Exe
       #Dim All
       #Register None
       #Include "Win32Api.Inc"
       Global hHook As Long, hDlg As Long
       
       Function SBProc(ByVal lMsg As Long, ByVal wParam As Long, _
          ByVal lParam As Long) As Long
          If lMsg = %HCBT_ACTIVATE Then
             Dim rc1 As RECT, rc2 As RECT
             GetWindowRect hDlg, rc1: GetWindowRect wParam, rc2
             SetWindowPos wParam, %HWND_TOPMOST, (rc1.nLeft + rc1.nRight - rc2.nRight + rc2.nLeft) / 2 , _
                (rc1.nTop + rc1.nBottom - rc2.nBottom + rc2.nTop) / 2, 0, 0, %SWP_NOSIZE Or %SWP_NOACTIVATE
             SetWindowText GetDlgItem(wParam, %IDOK), "Semen"
             SetWindowText GetDlgItem(wParam, %IDCANCEL), "Other"
             UnhookWindowsHookEx hHook
          End If
       End Function
    
       CallBack Function DemoProc
          hHook = SetWindowsHookEx(%WH_CBT, CodePtr(SBProc), GetModuleHandle(ByVal 0&), _
                   GetCurrentThreadId)
          Select Case MsgBox ("What's your name ?", %MB_OKCANCEL Or %MB_TASKMODAL, "Non-standart Msgbox")
             Case %IDOK: MsgBox "Interesting ...", , "Classic Msgbox"
             Case %IDCANCEL: MsgBox "I know", , "Classic Msgbox"
          End Select  
       End Function
       
       Function PbMain
          Dialog New 0, "Msgbox Demo", 50, 50, 400, 200, %WS_CAPTION Or %WS_SYSMENU To hDlg
          Control Add Button, hDlg, 101, "Show", 175, 180, 50, 15 Call DemoProc
          Dialog Show Modal hDlg
       End Function
    ------------------

  • #2
    Added custom font. Note, that you are not absolutelly free, because Windows calculates sizes, basing on original font and button's text.
    Code:
       #Compile Exe
       #Dim All
       #Register None
       #Include "Win32Api.Inc"
       Global hHook As Long, hDlg As Long, hFont As Long
       Function ENCW(ByVal hWnd As Long, ByVal lParam As Long) As Long
          If hFont = 0 Then hFont = CreateFont(-14, 0, 0, 0, _
             %FW_BOLD, %True, %False, %False, %RUSSIAN_CHARSET, _
             %OUT_TT_PRECIS, %CLIP_DEFAULT_PRECIS, %DEFAULT_QUALITY, %FF_DONTCARE, ByCopy "Times New Roman")
          SendMessage hWnd, %WM_SETFONT, hFont, 0: Function = 1
       End Function
       Function SBProc(ByVal lMsg As Long, ByVal wParam As Long, _
          ByVal lParam As Long) As Long
          If lMsg = %HCBT_ACTIVATE Then
             Dim rc1 As RECT, rc2 As RECT
             GetWindowRect hDlg, rc1: GetWindowRect wParam, rc2
             SetWindowPos wParam, %HWND_TOPMOST, (rc1.nLeft + rc1.nRight - rc2.nRight + rc2.nLeft) / 2 , _
                (rc1.nTop + rc1.nBottom - rc2.nBottom + rc2.nTop) / 2, 0, 0, %SWP_NOSIZE Or %SWP_NOACTIVATE
             SetWindowText GetDlgItem(wParam, %IDOK), "Semen"
             SetWindowText GetDlgItem(wParam, %IDCANCEL), "Other"
             EnumChildWindows wParam, CodePtr(ENCW), 0
             UnhookWindowsHookEx hHook
          End If
       End Function
       CallBack Function DemoProc
          hHook = SetWindowsHookEx(%WH_CBT, CodePtr(SBProc), GetModuleHandle(ByVal 0&), _
                   GetCurrentThreadId)
          Select Case MsgBox ("What's your name ?", %MB_OKCANCEL Or %MB_TASKMODAL Or %MB_ICONQUESTION, "Non-standart Msgbox")
             Case %IDOK: MsgBox "Interesting ...", , "Classic Msgbox"
             Case %IDCANCEL: MsgBox "I know", , "Classic Msgbox"
          End Select
       End Function
       Function PbMain
          Dialog New 0, "Msgbox Demo", 50, 50, 400, 200, %WS_CAPTION Or %WS_SYSMENU To hDlg
          Control Add Button, hDlg, 101, "Show", 175, 180, 50, 15 Call DemoProc
          Dialog Show Modal hDlg
          DeleteObject hFont
       End Function
    [This message has been edited by Semen Matusovski (edited August 14, 2000).]

    Comment

    Working...
    X