Click here to Skip to main content
16,005,389 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralHWND TO string and string to HWND conversion Pin
Atif Mushtaq2-Apr-04 21:46
Atif Mushtaq2-Apr-04 21:46 
GeneralRe: HWND TO string and string to HWND conversion Pin
Maxwell Chen2-Apr-04 22:09
Maxwell Chen2-Apr-04 22:09 
GeneralRe: HWND TO string and string to HWND conversion Pin
Atif Mushtaq2-Apr-04 22:57
Atif Mushtaq2-Apr-04 22:57 
QuestionDisplay a MessageBox right after a dialog is drawn on the screen? Pin
usfesco2-Apr-04 21:29
usfesco2-Apr-04 21:29 
AnswerRe: Display a MessageBox right after a dialog is drawn on the screen? Pin
PJ Arends3-Apr-04 8:30
professionalPJ Arends3-Apr-04 8:30 
GeneralRe: Display a MessageBox right after a dialog is drawn on the screen? Pin
usfesco3-Apr-04 14:10
usfesco3-Apr-04 14:10 
AnswerRe: Display a MessageBox right after a dialog is drawn on the screen? Pin
avenger_sb255-Apr-04 7:55
avenger_sb255-Apr-04 7:55 
GeneralScrollbars Pin
Member 9541232-Apr-04 21:24
Member 9541232-Apr-04 21:24 
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);
}
QuestionHow to Make a Form based Application Window fixed Pin
swarnamanoo2-Apr-04 21:00
swarnamanoo2-Apr-04 21:00 
AnswerRe: How to Make a Form based Application Window fixed Pin
Michael P Butler3-Apr-04 8:17
Michael P Butler3-Apr-04 8:17 
GeneralHiding the row in List Control Pin
Member 9524602-Apr-04 20:29
Member 9524602-Apr-04 20:29 
GeneralRe: Hiding the row in List Control Pin
gUrM33T3-Apr-04 0:39
gUrM33T3-Apr-04 0:39 
GeneralRe: Hiding the row in List Control Pin
Member 9524603-Apr-04 1:32
Member 9524603-Apr-04 1:32 
GeneralRe: Hiding the row in List Control Pin
Gary R. Wheeler3-Apr-04 2:22
Gary R. Wheeler3-Apr-04 2:22 
QuestionPreventing a file from copying.? Pin
ZarrinPour2-Apr-04 18:15
ZarrinPour2-Apr-04 18:15 
AnswerRe: Preventing a file from copying.? Pin
Prakash Nadar2-Apr-04 19:07
Prakash Nadar2-Apr-04 19:07 
GeneralRe: Preventing a file from copying.? Pin
Monty22-Apr-04 23:18
Monty22-Apr-04 23:18 
GeneralRe: Preventing a file from copying.? Pin
Prakash Nadar3-Apr-04 2:29
Prakash Nadar3-Apr-04 2:29 
AnswerRe: Preventing a file from copying.? Pin
Alexander M.,4-Apr-04 1:08
Alexander M.,4-Apr-04 1:08 
QuestionSMTP Server? Pin
Timothy Grabrian2-Apr-04 18:08
professionalTimothy Grabrian2-Apr-04 18:08 
AnswerRe: SMTP Server? Pin
Prakash Nadar2-Apr-04 19:05
Prakash Nadar2-Apr-04 19:05 
AnswerRe: SMTP Server? Pin
Paul Ranson3-Apr-04 8:58
Paul Ranson3-Apr-04 8:58 
QuestionAnyone has any experience on using CHtmlEditCtrl? Pin
usfesco2-Apr-04 13:06
usfesco2-Apr-04 13:06 
QuestionRe: Anyone has any experience on using CHtmlEditCtrl? Pin
Debapritam Chakra29-Dec-16 4:05
Debapritam Chakra29-Dec-16 4:05 
GeneralCOnverting char to int and retaining value Pin
CNewbie2-Apr-04 12:50
CNewbie2-Apr-04 12:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.