|
Thanx very much , it really worked , thanx
Unmanaged in a .NET world
|
|
|
|
|
hi all,
I would like my dialog-based app to pop up a message box right after the dialog itself is shown on the screen... anyone knows how to do that?
If I put a message box in my dialog's OnInitDialog like this:
BOOL CTestDlg::OnInitDialog()<br />
{<br />
CDialog::OnInitDialog();<br />
......<br />
AfxMessageBox("hello"); <br />
return TRUE;
}
the message box pops up before the main dialog appears, but I want the message box to pop up AFTER the main dialog appears. I've tried handling WM_SHOWWINDOW message, i.e., put the AfxMessageBox in the dialog's OnShowWindow() function, but it was the same thing as putting the AfxMessageBox in OnInitDialog() -- the message box still pops up before the main dialog appears.
Thanks for your help in advance
|
|
|
|
|
The easist way is post a custom message to your dialog from the OnInitDialog function, that way OnInitDialog will close, and the dialog will be created before the message is handled. In the custom message handler you call AfxMessageBox.
#define WMU_POPUPMESSAGEBOX WM_APP;
...
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
...
ON_MESSAGE(WMU_POPUPMESSAGEBOX, OnPopupMessageBox)
END_MESSAGE_MAP()
...
BOOL CTestDlg::OnInitDialog()
{
...
PostMessage(WMU_POPUPMESSAGEBOX, 0, 0);
return TRUE;
}
HRESULT OnPopupMessageBox(WPARAM, LPARAM)
{
AfxMessageBox(_T("Hello"));
return 0;
}
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks dear Mr. Arends, It Worked!
|
|
|
|
|
Hey, i used the following technique in my program to solve a same problem.
when you recieve WM_INITDIALOG message, call ShowWindow(hDlg,SW_SHOW); //plese write the MFC equivalent urself;P)
After that, you can call MessageBox to do your stuff...
That's simpler solution.
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
Hi ,
When i use the scrollbars the position of the window also changes.
Can i attach my code instead of pasting it?
Thanks and regards,
Salil.
CString szFilename("d:\\vc\\mfc\\2001.bmp");
HBITMAP hBmp = (HBITMAP)::LoadImage(NULL,szFilename,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp;
bmp.Attach(hBmp);
CClientDC dc(this);
CDC bmDC;
bmDC.CreateCompatibleDC(&dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
dc.StretchBlt (0,0,len_in_pix,ht_in_pix,&bmDC,0,0,bi.bmWidth
,bi.bmHeight,SRCCOPY);
bmDC.SelectObject(pOldbmp);
CString szFilename1("d:\\vc\\mfc\\2002.bmp");
HBITMAP hBmp1 = (HBITMAP)::LoadImage(NULL,szFilename1,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp1;
bmp1.Attach(hBmp1);
CClientDC dc1(this);
CDC bmDC1;
bmDC1.CreateCompatibleDC(&dc1);
CBitmap *pOldbmp1 = bmDC1.SelectObject(&bmp1);
BITMAP bi1;
bmp1.GetBitmap(&bi1);
dc1.StretchBlt (0,br_in_pix,len_in_pix,ht_in_pix,&bmDC1,0,0,bi.bmWidth
,bi.bmHeight,SRCCOPY);
bmDC1.SelectObject(pOldbmp1);
CString szFilename2("d:\\vc\\mfc\\2003.bmp");
HBITMAP hBmp2 = (HBITMAP)::LoadImage(NULL,szFilename2,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp2;
bmp2.Attach(hBmp2);
CClientDC dc2(this);
CDC bmDC2;
bmDC2.CreateCompatibleDC(&dc2);
CBitmap *pOldbmp2 = bmDC2.SelectObject(&bmp2);
BITMAP bi2;
bmp2.GetBitmap(&bi2);
dc2.StretchBlt (0,br_in_pix+ht_in_pix,len_in_pix,br_in_pix,&bmDC2,0,0,bi.bmWidth
,bi.bmHeight,SRCCOPY);
bmDC2.SelectObject(pOldbmp2);
CString szFilename3("d:\\vc\\mfc\\2004.bmp");
HBITMAP hBmp3 = (HBITMAP)::LoadImage(NULL,szFilename3,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp3;
bmp3.Attach(hBmp3);
CClientDC dc3(this);
CDC bmDC3;
bmDC3.CreateCompatibleDC(&dc3);
CBitmap *pOldbmp3 = bmDC3.SelectObject(&bmp3);
BITMAP bi3;
bmp3.GetBitmap(&bi3);
dc3.StretchBlt (0,2*br_in_pix+ht_in_pix,len_in_pix,ht_in_pix,&bmDC3
,0,0,bi.bmWidth,bi.bmHeight,SRCCOPY);
bmDC3.SelectObject(pOldbmp3);
CString szFilename4("d:\\vc\\mfc\\2005.bmp");
HBITMAP hBmp4 = (HBITMAP)::LoadImage(NULL,szFilename4,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp4;
bmp4.Attach(hBmp4);
CClientDC dc4(this);
CDC bmDC4;
bmDC4.CreateCompatibleDC(&dc4);
CBitmap *pOldbmp4 = bmDC4.SelectObject(&bmp4);
BITMAP bi4;
bmp4.GetBitmap(&bi4);
dc4.StretchBlt (0,2*br_in_pix+2*ht_in_pix,len_in_pix,20,&bmDC4
,0,0,bi.bmWidth,20,SRCCOPY);
bmDC4.SelectObject(pOldbmp4);
void CAprsView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(GetSafeHwnd() != NULL) {
SetScrollers();
}
}
void CAprsView::SetScrollers()
{
CRect image;
GetWindowRect(&image);
ScreenToClient(&image);
CRect view;
GetClientRect(&view);
//****************************************************************
// Vertical Scrollbar setting
//****************************************************************
SCROLLINFO info;
::ZeroMemory(&info, sizeof(info));
info.cbSize = sizeof(info);
// Do not disable the scrollbar if the image is scrolled
// off the top; it must be vertically entirely
// scrolled on to disable the scrollbars
if(image.top == 0 && image.Height() < view.Height())
{ // no vert scrolling
info.nMin = 0;
info.nMax = 0;
info.fMask = SIF_RANGE;
} //no vert scrolling
else
{ // vert scrolling
info.nMin = 0;
info.nMax = image.Height();
// The code below fiddles the page size to keep
// the scrollbar from disappearing when the page size
// equals the scroll range, a feature of the built-in
// control
if(image.top < 0 && view.Height() >= image.Height())
{ // need more
info.nPage = image.Height() + image.top + 1;
} // need more
else
{ // just fine
info.nPage = view.Height();
} // just fine
info.fMask = SIF_RANGE | SIF_PAGE;
} // vert scrolling
SetScrollInfo(SB_VERT, &info);
//****************************************************************
// Horizontal Scrollbar setting
//****************************************************************
::ZeroMemory(&info, sizeof(info));
info.cbSize = sizeof(info);
if(image.left == 0 && image.Width() < view.Width())
{ //no horz scrolling
info.nMin = 0;
info.nMax = 0;
info.fMask = SIF_RANGE;
} // no horz scrolling
else
{ // horz scrolling
info.nMin = 0;
info.nMax = image.Width(); // - view.Width();
if(image.top < 0 && view.Width() >= image.Width())
{ // need more
info.nPage = image.Width() + image.top + 1;
} // need more
else
{ // just fine
info.nPage = view.Width();
} // just fine
info.fMask = SIF_RANGE | SIF_PAGE;
} // horz scrolling
SetScrollInfo(SB_HORZ, &info);
}
void CAprsView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
void CAprsView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
int newpos = GetScrollPos(SB_HORZ);
SCROLLINFO info;
::ZeroMemory(&info, sizeof(info));
info.cbSize = sizeof(info);
info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;
GetScrollInfo(SB_HORZ, &info);
int low = info.nMin;
int high = info.nMax - info.nPage;
CRect view;
GetClientRect(&view);
CRect image;
GetWindowRect(&image);
ScreenToClient(&image);
switch(nSBCode)
{ /* nSBCode */
case SB_LINEUP:
newpos -= ::GetSystemMetrics(SM_CXVSCROLL);
if(newpos < low)
newpos = low;
break;
case SB_LINEDOWN:
newpos += ::GetSystemMetrics(SM_CXVSCROLL);
if(newpos > high)
newpos = high;
break;
case SB_PAGEUP:
newpos -= view.Height();
if(newpos < low)
newpos = low;
break;
case SB_PAGEDOWN:
newpos += view.Height();
if(newpos > high)
newpos = high;
break;
case SB_THUMBTRACK:
newpos = info.nTrackPos;
break;
case SB_THUMBPOSITION:
newpos = info.nTrackPos;
break;
} /* nSBCode */
SetScrollPos(SB_HORZ, newpos);
SetWindowPos(NULL, -newpos , image.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CAprsView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
SCROLLINFO info;
::ZeroMemory(&info, sizeof(info));
info.cbSize = sizeof(info);
info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;
GetScrollInfo(SB_VERT, &info);
int low = info.nMin;
int high = info.nMax - info.nPage;
int newpos = info.nPos;
CRect view;
GetClientRect(&view);
CRect image;
GetWindowRect(&image);
ScreenToClient(&image);
switch(nSBCode)
{ /* nSBCode */
case SB_LINEUP:
newpos -= ::GetSystemMetrics(SM_CYHSCROLL);
if(newpos < low)
newpos = low;
break;
case SB_LINEDOWN:
newpos += ::GetSystemMetrics(SM_CYHSCROLL);
if(newpos > high)
newpos = high;
break;
case SB_PAGEUP:
newpos -= view.Height();
if(newpos < low)
newpos = low;
break;
case SB_PAGEDOWN:
newpos += view.Height();
if(newpos > high)
newpos = high;
break;
case SB_THUMBTRACK:
newpos = info.nTrackPos;
break;
case SB_THUMBPOSITION:
newpos = info.nTrackPos;
break;
} /* nSBCode */
SetScrollPos(SB_VERT, newpos);
SetWindowPos(NULL,image.left,-newpos,0, 0, SWP_NOSIZE | SWP_NOZORDER);
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
}
|
|
|
|
|
I have a form based application window and i need to make its size fixed.How do i do it.
|
|
|
|
|
I'm assuming you are using MFC and your app is using a CFormView derived class and not a CDialog class.
Add a handler for the WM_GETMINMAXINFO in your CMainFrame class.
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) <br />
{<br />
lpMMI->ptMaxSize.x = 800;<br />
lpMMI->ptMaxSize.y = 600;<br />
lpMMI->ptMaxTrackSize.x = 800;<br />
lpMMI->ptMaxTrackSize.y = 600;<br />
lpMMI->ptMinTrackSize.x = 800;<br />
lpMMI->ptMinTrackSize.y = 600;<br />
CFrameWnd::OnGetMinMaxInfo(lpMMI);<br />
}
Michael
|
|
|
|
|
HI Friends,
I would like to know how to hide the row in list ctrl. I tried the CListCtrl::SetItemState(). I have used all nState, nMask parameter which arespecified in MSDN.
It was given in MSDN that to hide the row in List Ctrl we need to use the CListCtrl::SetItemState(...). BUt unfortunately I am not able to figure out how to use it. This is very urgent. Please help me!!!
Thanks in Advance.
bbye
|
|
|
|
|
Hiding rows is not possible in list controls.
Gurmeet S. Kochar
If you believe in God, it's because of the Devil
|
|
|
|
|
Hi,
But it is given in MSDN that it is possible by using CListCtr::SetItemState(...). U please read MSDN help about the CListCtrl.
|
|
|
|
|
SetItemState does not change the fact whether the row is 'shown' or not. It only changes the state values for the row, which are the following, as quoted from the April 2004 MSDN:
- LVIS_CUT: The item is marked for a cut-and-paste operation.
- LVIS_DROPHILITED: The item is highlighted as a drag-and-drop target.
- LVIS_FOCUSED: The item has the focus, so it is surrounded by a standard focus rectangle. Although more than one item may be selected, only one item can have the focus.
- LVIS_SELECTED: The item is selected. The appearance of a selected item depends on whether it has the focus and also on the system colors used for selection. Items will only show as selected if the list-view control has focus or the LVS_SHOWSELALWAYS style is used.
If you need to 'hide' a row, you must delete the corresponding item.
Software Zen: delete this;
|
|
|
|
|
Hi all,
Is it possible to MONITORING system activity such as file copying.?
I want to know what happens when a file is copied from one place to another place.How windows Copy or Cut a file from one place to another place.is it possible to HOOK this process.?
Thanks.
|
|
|
|
|
I think there is something called ICopyHook interface if you implement the interface and register the component the right way you can monitor the copying process.
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
ICopyHook is only for folders not for files
for files one will have to write a system driver
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
no wonder it didnt work for me when i was doing file copy operation.
mailMonty wrote:
files one will have to write a system driver
how bout api hooking?
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
where is the problem guys?!
just open the file with no share rights, then no other app can open/copy/delete/move/.. it.
Don't try it, just do it!
|
|
|
|
|
Does anyone know where I can learn how to make an SMTP Server in C++ (no MFC please!!)
wWw.KruncherInc.com - My cool programs
|
|
|
|
|
Start with RFC Spec for SMTP server.
Then create a window Service.
Listen for incoming connection at port 25 ( i guess)
Spin off thread for each connection made and process the requests...
I guess these points are good enough to start with the design.
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
You need to find the RFCs for SMTP, Internet Message Format, and MIME etc.
From a programming pov there are three areas, a TCP server, a protocol implementation and mail processing. It's quite a big job.
I built a special purpose SMTP server last autumn using boost::spirit for the protocol parsing. I'd definitely recommend a proper parser here. I rolled my own TCP server utilising the Windows thread pool and IOCompletion Ports. Works well. This bit will be freely available for most uses soonish.
Paul
|
|
|
|
|
CHtmlEditCtrl is a new class introduced since MFC 7.0. It sounds like a great class, which can be used in dialogs for WYSIWYG html editing. But I have a big problem in using CHtmlEditCtrl::SetDocumentHTML after its creation:
<br />
BOOL CTestDlg::OnInitDialog()<br />
{<br />
CDialog::OnInitDialog();<br />
CString str = "<html><head><title>My page</title></head><body><p>test</p></body></html>";<br />
<br />
CHtmlEditCtrl* m_pHtmlEditor = new CHtmlEditCtrl();<br />
m_pHtmlEditor ->Create("",0,CRect(10,10,200,200),this,IDC_HTMLEDITOR);<br />
<br />
m_pHtmlEditor->SetDocumentHTML(str);<br />
<br />
return TRUE; <br />
}
Everything looks good, but when I run the app, the HTML code in "str" does not show up in the HTML Editor window i.e., the html editor window is blank after the dialog appears on the screen.
What's more "interesting" (and frustrating) is, if I put a MessageBox before
m_pHtmlEditor->SetDocumentHTML(str);
i.e., change the code to:
<br />
BOOL CTestDlg::OnInitDialog()<br />
{<br />
CDialog::OnInitDialog();<br />
CString str = "<html><head><title>My page</title></head><body><p>test</p></body></html>";<br />
<br />
CHtmlEditCtrl* m_pHtmlEditor = new CHtmlEditCtrl();<br />
m_pHtmlEditor ->Create("",0,CRect(10,10,200,200),this,IDC_HTMLEDITOR);<br />
<br />
AfxMessageBox("test"); <br />
m_pHtmlEditor->SetDocumentHTML(str);<br />
<br />
return TRUE; <br />
}
It then works! The HTML code in "str" is showing up in the HTML editor window. But I really don't need that MessageBox.
Anybody has any idea? I am really stuck. I can provide a link to my test project if anyone needs it.
Big thanks!
|
|
|
|
|
Did you find any solution for this problem??
|
|
|
|
|
The Below code was able to take 2 char's from an array stream and turn it into an integer # and Convert it to Decimal.
However, unless I am missing something here, what it fails to do is the other half of what my problem was, that I wanted to take those 2 chars from the array stream and just convert them to an int value and leave them be, not convert them to decimal. I tried to do it myself, but it wasn't coming out correct.
Thank You
<br />
#include <iostream><br />
#include <cstring><br />
using namespace std;<br />
<br />
int Convert(char a, char b);<br />
<br />
void main(){<br />
cout << "" << Convert('A', 'A') << endl;<br />
}<br />
<br />
int Convert(char a, char b){<br />
int intTemp, intVal = 0;<br />
char strBuffer[3];<br />
<br />
strBuffer[0] = a;<br />
strBuffer[1] = '\0';<br />
<br />
intTemp = atoi(strBuffer);<br />
<br />
if (intTemp != 0){<br />
intVal = intTemp << 4;<br />
}<br />
else{<br />
switch (toupper(a)){<br />
case 'A':<br />
intVal = intVal | 0xA0;<br />
break;<br />
case 'B':<br />
intVal = intVal | 0xB0;<br />
break;<br />
case 'C':<br />
intVal = intVal | 0xC0;<br />
break;<br />
case 'D':<br />
intVal = intVal | 0xD0;<br />
break;<br />
case 'E':<br />
intVal = intVal | 0xE0;<br />
break;<br />
case 'F':<br />
intVal = intVal | 0xF0;<br />
break;<br />
default:<br />
return 0;<br />
break;<br />
}<br />
}<br />
<br />
strBuffer[0] = b;<br />
strBuffer[1] = '\0';<br />
<br />
intTemp = atoi(strBuffer);<br />
<br />
if (intTemp != 0){<br />
intVal = intVal | intTemp;<br />
}<br />
else{<br />
switch (toupper(b)){<br />
case 'A':<br />
intVal = intVal | 0x0A;<br />
break;<br />
case 'B':<br />
intVal = intVal | 0x0B;<br />
break;<br />
case 'C':<br />
intVal = intVal | 0x0C;<br />
break;<br />
case 'D':<br />
intVal = intVal | 0x0D;<br />
break;<br />
case 'E':<br />
intVal = intVal | 0x0E;<br />
break;<br />
case 'F':<br />
intVal = intVal | 0x0F;<br />
break;<br />
default:<br />
return 0;<br />
break;<br />
}<br />
}<br />
<br />
return intVal;<br />
} <br />
|
|
|
|
|
CNewbie wrote:
just convert them to an int value and leave them be, not convert them to decimal
I don't understand what you're asking there. What's the expected behavior and how is it not working?
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
The above code takes 2 chars from the array and converts them to an int value.
However (and I proved this by running the code) it also converts the new int value from HEX to Decimal.
That helped me in one situation, but another situation where I dont want to convert that new int value from HEX to Dec, but need it to stay a HEX Value it doesnt help.
Hopefully someone understands what I am saying and can help.
Thanks
|
|
|
|
|