'Setting his position while popping up the mode dialog box' This example is the upper left corner of the parent window Align 'according to BCB_FANS (four major names catching the chasing order) BCB code to vb' only reference 'attached to BCB_FANS Source code 'BCB_FANS (four major name catching chasing order)' When the MessageBox dialog is displayed, the main window will lose the focus, know this, the problem is very simple. Here is my C Builder code. '' // Replace the window process of the main window (I don't know how VC is doing this, anyging the principle is this) '' 'Void __fastcall tform1 :: wndproc (messages :: tMessage & Message)' {'tform :: WndProc (Message ); '' // Before the loss of focus, '{'} '// After the focus is lost,' elseness.msg == wm_Activate '{' m (loword (message.wparam) ) == wa_inactive) '{' hwnd hwnd; 'char classbuf [64];' 'hwnd = (hwnd) message.lparam;' getclassname (hwnd, classbuf, sizeof (classbuf)); '' // First judgment is whether it is MessageBox dialog, 'if (ANSISTRING (ClassBuf) == "# 32770")' {'// determines if this window is a window of its own program (because other programs pop-up window, your main window is also lost in the focus ) 'DWORD dwprocessid;' 'getWindowThreadProcessid (Hwnd, & dwprocessid);' 'IF (dwprocessid == getCurrentProcessId ())' {'// Mobile window location' MoveWindow (......); // or call SetwindowPos (...) '// Replace the left header bar icon (if any)' setClasslong (hwnd, gcl_hicon, (long) image1-> picture-> icon-> handle); '' // Reset The text of the button (such as the determination is changed to "OK 007") 'hwnd htemp;' 'htemp = getdlgitem (hwnd, 1);' setWindowt EXT (HTEMP, "New Text for Button); '' // ......... Other action '}'} '}'} '}
'Form
Option ExplicitPrivate Sub Form_Load () On Error Resume Next lhSysMenu = GetSystemMenu (hwnd, 0 &) lRet = AppendMenu (lhSysMenu, MF_SEPARATOR, 0 &, vbNullString) lRet = AppendMenu (lhSysMenu, MF_STRING, IDM_ABOUT, "About ...") Show ProcOld = SetWindowLong (hwnd, GWL_WNDPROC, AddressOf WindowProc) End SubPrivate Sub Form_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single) Dim r As RECT Dim p As POINTAPI If Button = vbRightButton Then GetCursorPos p TrackPopupMenu lhSysMenu, 0, PX, Py, 0, Me.hwnd, r end ifend sub
Private Sub Form_Unload (Cancel AS Integer) Setwindowlong Hwnd, GWL_WndProc, Procoldend Sub
'Module
Option ExplicitPublic Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As RECT) As LongPublic Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPublic Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic 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 LongPublic Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As String) As LongPublic Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As LongPublic Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long , ByVal lpClassName As String, ByVal nMaxCount As Long) As LongPublic Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongPublic Declare Function GetCurrentProcessId Lib "kernel32" () As LongPublic Declare Function GetWindowRect Lib "user32" (BYVAL HWND As Long, LPRECT AS REC) AS Longpublic Declare Function SetWindowPos LIB "User32"
(Byval HwndInsertAfter As Long, Byval X As Long, Byval Y As Long, BYVAL CX As Long, BYVAL CY As Long As LongEnd TypePublic Type POINTAPI x As Long y As LongEnd TypePublic ProcOld As LongPublic Const TPM_LEFTALIGN = & H0 & Public Const WM_SYSCOMMAND = & H112Public Const MF_SEPARATOR = & H800 & Public Const MF_STRING = & H0 & Public Const GWL_WNDPROC = (-4) Public Const IDM_ABOUT As Long = 1010Public Const WM_COMMAND = & H111Public Const WM_ACTIVATE = & H6Public const wa_inactive = 0PUBLIC LHSYSMENU As long, LRET AS Long