|
Hi all. I am very new to Visual C++ and would be grateful for some pointers for the following. I am attempting to embed a scrollable view into a form view. It would like a CScrollView, but obviously non-resizable. I have got as far as creating an object based on CWnd, embedded it into a form view and drawn into it, but I have no idea how to create a "canvas" larger than the size of the object and handle the mechanics of scrolling. Can anyone point me in the direction of some scrolling code, or tell me a way of doing it? Thanks
|
|
|
|
|
If you create a new dialog (ie: wizard), delete all the gadgets from it then go it its properties and turn on vertical scrolling. You will need to play with the SCROLLINFO structure (add a member of new dialog class).
eg:
CDialogContainer::OnInitDialog()
{
CDialog::OnInitDialog();
m_pScrollInfo = new SCROLLINFO;
m_pScrollInfo->cbSize = sizeof(SCROLLINFO);
m_pScrollInfo->fMask = SIF_ALL;
m_pScrollInfo->nMin = 0;
m_pScrollInfo->nMax = 100;
m_pScrollInfo->nPage = 10;
m_pScrollInfo->nPos = 0;
m_pScrollInfo->nTrackPos= 0;
this->SetScrollWindow();
...
}
You will also need :
// ----------------------------------------------------------------------------
// Method: OnVScroll
//
// Abstract: Maintains the scroll bar.
// Called automatically from the scrollbar events
// Also called manually to update the scrollbar after changes.
//
// Arguments:
//
// UINT nSBCode : The Scroll type
// UINT nPos : For ScrollType SB_THUMBPOSITION nPos is the new position
// CScrollBar* pScrollBar : Ignored (usually NULL anyway)
//
// ----------------------------------------------------------------------------
void CDialogContainer::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
RECT rectClient;
int iButtonIncrement;
int iPageIncrement;
int iScrollAmount = 0;
//////////////////////////////////////////////////////////////
// Not interested in ENDSCROLL events.
//////////////////////////////////////////////////////////////
if (SB_ENDSCROLL == nSBCode)
return;
//////////////////////////////////////////////////////////////
// If we get events which would cause the scrolling to leave
// the range then just return.
// ie: Pressing the scrollup when its already up.
//////////////////////////////////////////////////////////////
if ( (m_pScrollInfo->nPos <= m_pScrollInfo->nMin) && (nSBCode == SB_LINEUP) )
return;
if ( (m_pScrollInfo->nPos <= m_pScrollInfo->nMin) && (nSBCode == SB_PAGEUP) )
return;
if ( (m_pScrollInfo->nPos >= m_pScrollInfo->nMax) && (nSBCode == SB_LINEDOWN) )
return;
if ( (m_pScrollInfo->nPos >= m_pScrollInfo->nMax) && (nSBCode == SB_PAGEDOWN) )
return;
this->m_vectorCDialogAddress[0]->GetClientRect(&rectClient);
iButtonIncrement = (rectClient.bottom - rectClient.top)/4;
iPageIncrement = (rectClient.bottom - rectClient.top);
switch (nSBCode)
{
case SB_LINEUP:
iScrollAmount = -iButtonIncrement;
break ;
case SB_LINEDOWN:
iScrollAmount = iButtonIncrement;
break ;
case SB_PAGEUP:
iScrollAmount = -iPageIncrement;
break ;
case SB_PAGEDOWN:
iScrollAmount = iPageIncrement;
break ;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
{
if (nPos > m_pScrollInfo->nMax)
nPos = m_pScrollInfo->nMax;
if (nPos < m_pScrollInfo->nMin)
nPos = m_pScrollInfo->nMin;
iScrollAmount = nPos-m_pScrollInfo->nPos;
}
break;
}
if ( (SB_LINEDOWN == nSBCode || nSBCode == SB_PAGEDOWN) &&
(m_pScrollInfo->nPos + iScrollAmount > (m_pScrollInfo->nMax - m_pScrollInfo->nPage)) )
{
//////////////////////////////////////////////////////////////
// Round off the last piece to the leftover amount
//////////////////////////////////////////////////////////////
iScrollAmount = (m_pScrollInfo->nMax - m_pScrollInfo->nPage - m_pScrollInfo->nPos);
}
if ( (SB_LINEUP == nSBCode || nSBCode == SB_PAGEUP) &&
(m_pScrollInfo->nPos + iScrollAmount < m_pScrollInfo->nMin) )
{
//////////////////////////////////////////////////////////////
// Round off the last piece to the leftover amount
//////////////////////////////////////////////////////////////
iScrollAmount = (m_pScrollInfo->nMin - m_pScrollInfo->nPos);
}
m_pScrollInfo->nPos += iScrollAmount;
this->ScrollWindow(0,-iScrollAmount); // opposite direction on scroll bar!
this->SetScrollInfo(SB_VERT,m_pScrollInfo,TRUE);
}
BOOL CDialogContainer::OnCommand(WPARAM wParam, LPARAM lParam)
{
//////////////////////////////////////////////////////////////
// Prevent Enter and ESC from closing the control.
//////////////////////////////////////////////////////////////
if (wParam == IDOK)
return FALSE;
if (wParam == IDCANCEL)
return FALSE;
return CDialog::OnCommand(wParam, lParam);
}
//////////////////////////////////////////////////////////////
// iIndex of -1 means preserve the position.
//////////////////////////////////////////////////////////////
void CDialogContainer::SetScrollWindow(int iIndex)
{
RECT rectClient ;
RECT rectDialogRect;
int iHeight;
int iScrollPos;
iScrollPos = m_pScrollInfo->nPos;
m_pScrollInfo->nPos = 0;
this->SetScrollInfo(SB_VERT,m_pScrollInfo,FALSE);
this->GetClientRect(&rectClient);
for (int i=0;i<m_vectorcdialogaddress.size();++i)
{
="" m_vectorcdialogaddress[i]-="">GetClientRect(&rectDialogRect);
iHeight = rectDialogRect.bottom - rectDialogRect.top;
rectDialogRect.top = (iHeight * i);
rectDialogRect.bottom = rectDialogRect.top + iHeight;
m_vectorCDialogAddress[i]->MoveWindow(&rectDialogRect);
m_vectorCDialogAddress[i]->ShowWindow(SW_SHOW);
}
int iRangeMax = (iHeight*m_vectorCDialogAddress.size());
if (iRangeMax <= (rectClient.bottom - rectClient.top))
{
this->EnableScrollBar(SB_VERT,ESB_DISABLE_BOTH);
iRangeMax = 0;
}
else
{
this->EnableScrollBar(SB_VERT,ESB_ENABLE_BOTH);
}
m_pScrollInfo->nPos = 0; // As we are going to SCROLL to where we want.
m_pScrollInfo->nMax = iRangeMax; // Total Height
m_pScrollInfo->nPage = (rectClient.bottom - rectClient.top); // Visable Height
this->SetScrollInfo(SB_VERT,m_pScrollInfo,FALSE);
//////////////////////////////////////////////////////////////
// Explicit scroll to the supplied entry.
//////////////////////////////////////////////////////////////
if (iIndex != -1)
this->OnVScroll(SB_THUMBPOSITION,iIndex*iHeight,NULL);
this->ShowScrollBar(SB_VERT,TRUE);
}
Julien.
|
|
|
|
|
|
I tried several things now but my CBitmap still appear under Cstatic bmp and Cstatic control
when using Onpaint. (CpaintDc)
How is drawed the screen ? is there priority that we can set ?
a kind of Z buffer ? anythings ?
|
|
|
|
|
Hi All,
I am using VC++6.0 to do the C++ Program. I want to draw a Graph in Console window. Is it possible to do ?Then which is the header file to be included??
Thanks in Advance
Rgds
Sangeetha
|
|
|
|
|
No, you can't ...
I'm sure, i think my answer is clear, so i don't explain.
Cheers ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
yes. you can, or at least you could. i wrote many programs using Microsoft's older C compilers using the DOS VESA drivers. i even wrote my own windowing system before Windows 3.0 came out. and, all my old programs still run in the current DOS windows.
i honestly have no idea if the current batch of Visual C++ compilers let you do this or not (i suspect not). but, if you can find an old MS C compiler (pre v7 i think) you're all set.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Hello,
I am trying to write an application in WTL with Horizontal Splitters. Could some one send me a link or code to create splitter in WTL.
Thanks in Advance
Regards
Alpesh Makwana
|
|
|
|
|
Can anybody tell me how can i programmatically send and receive mails from any mail account for ex hotmail.com like outlook express does.
|
|
|
|
|
Sending and receiveing mail progrmatically like hotmail is possible by using the SMTP and POP3 Protocol wrappers that are available on CodeProject Site.
http://codeproject.com/internet/csmtpconn.asp by PJ Naughter could help in this.
Thanks in Advance
Regards
Alpesh Makwana
|
|
|
|
|
That's a really complex question though like most complex questions it is much easier to state.
Here are a few hints for direction:
1. Learn WinSock or BSD sockets (you'll need them).
2. Read through RFC 821 (SMTP) most of it might be confusing if your not used to "grammars" but you can get the protocol quite easily. This is how internet mail is propogated (aka sent and passed on).
3. Read through RFC 1939 (POP-3) the same goes as hint #2 except this is how mail is typically recieved through email programs (there are other protocols such as IMAP or Exchange for example but this is far simpler to start with).
If you really want to figure out how this works I suggest you make 4 little experiment tools to begin with in this order (from easiest to hardest).
1. Simple SMTP client.
2. Mail Queue lister and deleter.
3. Mail Reader.
4. Mail Reader with MIME support.
Hopefully this has given you a specific direction to work in. If you need more clarification don't hesitate to ask.
Sean Cody (NullStream)
"As long as you want to live,
everywhere will become heaven.
Afterall, you are still alive."
- End Of Evanglion
|
|
|
|
|
I want to use the status bar in my Dialog based app!
but this code doesn't show the status bar!
m_SB.Create(this); // m_SB is a CStatusBar object
m_SB.SetIndicators(indicator, sizeof(indicators)/sizeof(UINT));
I wrote it in OnInitDialog()
but there is no control when my app is running!
Is there more inits to do before a status bar can be shown....? (hope you understod that!
HELP!!!!!!!!!
/*
BETA
*/
|
|
|
|
|
Rickard
I think that you will need to place this function call after the code you have listed above.
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
Also have a look at the project I e-mailed you that shows how to add a menu and statusbar to a dialog based app.
Hope this helps.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
Hi,
I want to Lock my system by using the Api LockWorkStation. But Whn I am using that it shows an error undeclared identifier. I already included that winuser.h headerfile in to the program .The OS is Win2000...
Plese Help me
|
|
|
|
|
I used this and it works. Most probably the first 3 lines are missing from your code (the 'defines" )...
#define _WINVER 0x0500
#define _WIN32_WINNT 0x0500
#include <Windows.h>
#ifdef _DEBUG
#include <ConIO.h>
#endif
#include <StdIO.h>
VOID Error_DisplayLastW(
IN LPCWSTR pwszMsg
);
int
main(
IN int argc,
IN char **argv
)
{
__try
{
puts("Preparing to lock workstation...\n");
if(!LockWorkStation())
{
Error_DisplayLastW(L"LockWorkStation");
__leave;
}
puts("Workstation unlocked.\n");
}
__finally
{
puts("Finally.\n");
}
puts("Exiting.\n");
return
#ifdef _DEBUG
!_getch()
#else
0
#endif
;
argc;
argv;
}
VOID
Error_DisplayLastW(
IN LPCWSTR pwszMsg
)
{
LPWSTR pwszMessage;
if(FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL,
GetLastError(), 0, (LPWSTR)&pwszMessage, 0, NULL))
{
fprintf(stdout, "%S %S\n", pwszMsg ? pwszMsg : L"", pwszMessage);
LocalFree(pwszMessage);
}
}
|
|
|
|
|
I always forgot the include >...< forms...
The include section is
#include >Windows.h<
#ifdef _DEBUG
#include >ConIO.h<
#endif
#include >StdIO.h<
|
|
|
|
|
#include <Windows.h>
#ifdef _DEBUG
#include <ConIO.h>
#endif
#include <StdIO.h>
|
|
|
|
|
hello,everyone!
I have made a ActiveX Control about report using MFC on VC6.0,and I want to make the print and
print preview methods in the control.Using it I can print report very easy.But I have some trouble while I do it!
Please give me a hand!
Thanks advanced!
|
|
|
|
|
Hi,
We can't help you, when we haven't any information about your ActiveX or your source code ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Thank you for the answer from you!
I am sorry I don't tell about the Print ActiveX.
This ActiveX is made by VC6.0 and MFC,and about a grid ctrl.
So I want to create the methods of Print and Printpreview in the ActiveX and I can call the method in other app to print the report.
but when I create the printpreview method I have a trouble :That I must
have CFrameWnd point,but I don't how to get the CFramewnd point in the
ActiveX.
That is all,Please give me a hand!
Thanks.
|
|
|
|
|
Have no idea how to add new caption button (like close(x), minimize(_) etc.) to title bar, like it is in GetRight (Docking button (.)). Answer if you know...
|
|
|
|
|
Paul DiLascia wrote about this back in '97, here is the link to the article.
http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0697/c++0697.htm
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
I have a problem I just don't get.
I have created two programs, a ProgramApp and a ProgramDLL. The ProgramApp is a SDI and I create a standard modeless dialog when it starts up. Next I load the ProgramDLL so the ProgramApp can use it. I call a function in the Program DLL called ChangeDialogText( lpDlg ), this function sends the lpDlg pointer to the ProgramDLL when calling the ChangeDialogText( lpDlg ).
ok, so far so good,.. now the ProgramDLL has a singal line that does this lpDlg->SetWindowText( "DLL Text" ).... bang here I get an assert that the lpDlg doesn't have a m_hWnd??!?!?!
I have the AFX_MANAGE_STATE(AfxGetStaticModuleState()) in the beginning of the ChangeDialogText function.
I just don't understand it,... it should work. what am I doing wrong.
|
|
|
|
|
I had the same problem through a COM ATL DLL, but the solution is the same, just build a release version of your DLL, it should work (ASSERT only in debug).
Celhtar
|
|
|
|
|
What you can't see won't hurt you
|
|
|
|