mfc >> Bring AfxMessageBox to the Center of mainframe which is not parent to perticular AfxMessaeBox.

by free2cric@yahoo.com » Mon, 27 Mar 2006 14:08:34 GMT

Hi there,

I have a (Dialogbox with a button) which I open from the Menu which is
vertical shaped and docked at the left side.


I click this button on the dialogbox and AfxMessagebox is flashed which

is at the center of the dialogbox . In that way its flashing at the
left side. I call a App's DisplayMessage function in order to show this

messagebox. I though if I display this dialog from App , it may come at

the center but that is not the case.


I want this AfxMessageBox to be flashed at the center of the frame.


I read few postings here. I used following code using SetWindowsHookEx.

Sombody before said to subclass the window of AfxMessageBox in the hook

procedure . I am not sure how to do it and after that how to reposition

the window at the center of the main framme/App. So I straightaway used

SetWindowPos but not working satisfactorily.


HHOOK hookSave;


LRESULT CALLBACK hookFunc(int nCode, WPARAM wParam, LPARAM lParam)
{


if ( HCBT_CREATEWND == nCode )
{


#define pcs (((LPCBT_CREATEWND) lParam)->lpcs)
HWND hwndSave = 0;


if( WC_DIALOG == pcs->lpszClass )
{
hwndSave = (HWND) wParam;


}


if ( hwndSave )
{
// subclass_dialog_any_which_way_you_want(hwndSave);
SetWindowPos(hwndSave,HWND_TOP, 10,50,500,300,SWP_SHOWWINDOW);
//MoveWindow(hwndSave,100,500,500,300,false);
//theApp.m_pMainWnd->SubclassWindow(hwndSave);
}


#undef pcs
}


return CallNextHookEx(hookSave, nCode, wParam, lParam);



}


void CLeeApp::DisplayMessage()
{
hookSave = SetWindowsHookEx(WH_CBT, hookFunc, NULL,
::GetCurrentThreadId());
AfxMessageBox("Just for check");
UnhookWindowsHookEx(hookSave);


}


Could someone help me with some guiding code postings.

It will help me a lot.


Thank you,


Lee



mfc >> Bring AfxMessageBox to the Center of mainframe which is not parent to perticular AfxMessaeBox.

by yang__lee@ausi.com » Mon, 27 Mar 2006 14:09:29 GMT


Hi there,

I have a (Dialogbox with a button) which I open from the Menu which is
vertical shaped and docked at the left side.


I click this button on the dialogbox and AfxMessagebox is flashed which

is at the center of the dialogbox . In that way its flashing at the
left side. I call a App's DisplayMessage function in order to show this

messagebox. I though if I display this dialog from App , it may come at

the center but that is not the case.


I want this AfxMessageBox to be flashed at the center of the frame.


I read few postings here. I used following code using SetWindowsHookEx.

Sombody before said to subclass the window of AfxMessageBox in the hook

procedure . I am not sure how to do it and after that how to reposition

the window at the center of the main framme/App. So I straightaway used

SetWindowPos but not working satisfactorily.


HHOOK hookSave;


LRESULT CALLBACK hookFunc(int nCode, WPARAM wParam, LPARAM lParam)
{


if ( HCBT_CREATEWND == nCode )
{


#define pcs (((LPCBT_CREATEWND) lParam)->lpcs)
HWND hwndSave = 0;


if( WC_DIALOG == pcs->lpszClass )
{
hwndSave = (HWND) wParam;


}


if ( hwndSave )
{
// subclass_dialog_any_which_way_you_want(hwndSave);
SetWindowPos(hwndSave,HWND_TOP, 10,50,500,300,SWP_SHOWWINDOW);
//MoveWindow(hwndSave,100,500,500,300,false);
//theApp.m_pMainWnd->SubclassWindow(hwndSave);
}


#undef pcs
}


return CallNextHookEx(hookSave, nCode, wParam, lParam);



}


void CLeeApp::DisplayMessage()
{
hookSave = SetWindowsHookEx(WH_CBT, hookFunc, NULL,
::GetCurrentThreadId());
AfxMessageBox("Just for check");
UnhookWindowsHookEx(hookSave);


}


Could someone help me with some guiding code postings.

It will help me a lot.


Thank you,


Lee




mfc >> Bring AfxMessageBox to the Center of mainframe which is not parent to perticular AfxMessaeBox.

by yang__lee@ausi.com » Mon, 27 Mar 2006 14:13:24 GMT

I guess this related to making AfxMessageBox as a SubClassWindow to
MainFrame which should be subclassed in the hook function (Which I dont
know how to do in the hookfunction, means hot to get the main frame
handle) and then how to get the windproc of mainframe for afxmessagebox
and then hot to get all these things to work for Afxmessagebox to
center the mainframe

Please help.

thanks
Lee







Similar Threads

1. Form with StartupPosition CenterParent not centered on parent

I have a form (sizeable border, shows in taskbar, nothing unusual), which
is the main form of my application (called MainForm). During an operation
progress is shown in another form, that is shown from within the main form
with: pf.Show(this);

I have set the StartupPosition of the form pf to CenterParent. When the
form shows, it is not centered on the parent.

How can I get the progress form to be shown centered on the main form?

2. Gurus need your help on Centering AfxMessageBox using SetWindowsHookEx

3. Bring Parent to Front (on top of modaless child)

I have a form that shows another child form using the Show()
operation.  Since the child is modaless, I would like the option that
when I click anywhere on the parent form that the parent form comes in
front of the child.  I added a callback in the parent form to call
BringToFront() when I selected anywhere in the parent form, but it
didn't work.  Is there an option that I can specify in the child form
to allow for this behavior?

4. Bringing child window on top of parent window - CSharp/C#

5. centering a childform in MDI parent

I have a simple c# app that opens a child form in a mdi parent.

I want the child form to open in the center of the mdi parent, so i
can open the child form ok, it all works fine, but setting

            frmConfig = new ConfigForm(this);
            frmConfig.MdiParent = this;
           frmConfig.TopLevel = false;

           frmConfig.StartPosition = FormStartPosition.CenterParent;
            frmConfig.Show();


does not seem to work regardless if i set it runtime or in the windows
properties  at design time.

The only way i can get CenterParent to work is to display the form
using Showdialog(), but then it has to be top level and the user can
drag it out the bounds of the MDI parent.


What i have found is if i use 

frmConfig.StartPosition = FormStartPosition.CenterScreen;
         

this will display the childform in the center of the parent, seemingly
regardless of where the parent is located on screen.


All the internet examples ive found say to use
FormStartPosition.CenterParent;

Does anyone have any idea whats going on and how it should be done ?


Peted

6. Center form on parent form - CSharp/C#

7. i am usinng msdatagrid & combo box in vc++ it work well in win98 but in windowsxp my combobox not place on perticular row

here is my code which will sucessfully run on win98 machine but in
windowsxp my combo box not place at perticular Row


CComboBox	m_combo;
		CDataGrid	grid;
		HDC hDC;
        hDC = ::GetDC (NULL);
        SetMapMode (hDC, MM_TWIPS);
		int i=2;  //row number
		CString s;
		CColumns cs;
 	    CColumn cc;
 		CComVariant v1,vt;
	    cs =  grid.GetColumns();
        cc = cs.GetItem(COleVariant(2L));
        float m_RowLeft = cc.GetLeft(); // left cell
		float w=cc.GetWidth();
    	float m_RowTop =  grid.RowTop(i ); // top cell
        float m_RowHeigth = grid.GetRowHeight(); // Heigh cell
        double scaleX=(this->GetDC()->GetDeviceCaps(LOGPIXELSX)/1440);
        double scaleY=(this->GetDC()->GetDeviceCaps(LOGPIXELSY)/1440);
        RECT grd;
        grid.GetWindowRect(&grd); //m_DataGrid is the MSDataGrid ctrl
		VARIANT bmark =  grid.RowBookmark(i);
		CColumns cols(grid.GetColumns());
 	    CColumn col(cols.GetItem(COleVariant((long)1L)));
	    cols.DetachDispatch();
		float  l=col.GetLeft();
		float r=col.GetWidth(); ;
		float h=col.GetTop();
		VARIANT cell_value = col.CellValue(bmark);
		col.DetachDispatch();
		RECT loc;
		loc.right=r  ;
		loc.bottom=  h ;
 		loc.left = l+grd.left;
        loc.top = grd.top - (m_RowTop  )-scaleX ;
	    ScreenToClient(&loc);
 	 m_combo.SetWindowPos(NULL,loc.left,loc.top
,loc.right,-loc.bottom,0);



plz tell me what is wrong with above code

thanks!
yogesh shrikhande
 XXXX@XXXXX.COM 

8. AfxMessageBox does not 'eat' key messages