|
Hi,
I like to know how can I use the function:
OpenDocumentFile(FileName) in my CView class.
I have a bunch of files, and I like to use this function to open the files.
and each file has to be in a new document.
Thanks
Ehsan Behboudi
|
|
|
|
|
You can use AfxGetApp()->OpenDocumentFile( "filename.ext" );
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Thanks for you reply,,
the filePathName that I pass to the OpenDocumentFile( FilePathName)
is a Bitmap,
it opens an epmty document,, Can you have a look at my code Please..
Thanks
//My application is MDI, and I store a bunch of bitmap pathNames in the
// first docuemnt, pFirstDoc is a pointer to that document.
pApp->OpenDocumentFile(pFirstDoc->m_filePathArray.GetAt(0));
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
// Get the active MDI child window.
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
// or CMDIChildWnd *pChild = pFrame->MDIGetActive();
// Get the active view attached to the active MDI child
// window.
CTurboMechView *pView = (CTurboMechView *) pChild->GetActiveView();
pView->LoadBitmap(pFirstDoc->m_filePathArray.GetAt(0));
pView->OnPaint();
Any ideas???
Thanks
Ehsan Behboudi
|
|
|
|
|
What is the problem that you are experiencing?
BTW: Just curious;
> pApp->OpenDocumentFile(pFirstDoc->m_filePathArray.GetAt(0));
[snip]
> pView->LoadBitmap(pFirstDoc->m_filePathArray.GetAt(0));
Why load the bitmap twice? Maybe I dont understand what your doing, but when you call OpenDocumentFile does this not load the bitmap in your document?
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
When I call OpenDocumentFile, it only opens a blank document.
It doesn't display the bitmap.
but when I load it with my pointer to CView, it still won't display the bitmap.
any ideas?
Ehsan Behboudi
|
|
|
|
|
Hmmm... I think I'd have to take a look at what your view is doing. When you call LoadBitmap, I'm guessing the information is stored in the view, what does your painting(WM_PAINT) look like?
It sounds to me like your using the same doc/view pair the first one, and all the rest. Is this correct? If thats the way your doing it, you might consider just attaching a new view to the original document and loading the bitmap from there.
Sorry if I'm rambling... I'm not realy sure what it is your tring to do.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Thanks for replying
this is the whole deal,,
void CTurboMechView::OnToolsNewDocuemnt()
{
// TODO: Add your command handler code here
CWinApp* pApp = AfxGetApp();
CTurboMechDoc *pFirstDoc= GetFirstDocument();
pApp->OpenDocumentFile(pFirstDoc->m_filePathArray.GetAt(0));
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
// Get the active MDI child window.
//CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
CMDIChildWnd *pChild = pFrame->MDIGetActive();
// Get the active view attached to the active MDI child
// window.
CTurboMechView *pView = (CTurboMechView *) pChild->GetActiveView();
pView->LoadBitmap(pFirstDoc->m_filePathArray.GetAt(0));
pView->OnPaint();
// so up there, I loaded the bitmap in the new View, but it still doesn't show it... weird !!!
}
This my OnPaint()
void CTurboMechView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect lrec;
CTurboMechDoc* pDoc=GetDocument();
if(pDoc->m_sBitmap !="" /*&& showstate==TRUE*/)
{
ShowBitmap(&dc,lrec);
}
OnDraw(&dc);
// Do not call CScrollView::OnPaint() for painting messages
}
void CTurboMechView::LoadBitmap(CString file)
{
CTurboMechDoc* pDoc = GetDocument();
if(file!="")
{
HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if (hBitmap)
{
// Delete the current bitmap
if (m_bmpBitmap.DeleteObject())
{
m_bmpBitmap.Detach();
}
// Attach the currently loaded bitmap to the bitmap object
m_bmpBitmap.Attach(hBitmap);
}
Invalidate(FALSE); // you may change this to False
//NOTE:IMPORTANT I moved this showstate inside the if
}
}
void CTurboMechView::ShowBitmap(CDC *pdc, CRect trect)
{
BITMAP bm;
CDC dcMem;
CRect lRect=trect;
// Get the loaded bitmap
m_bmpBitmap.GetBitmap(&bm);
// Create a device context to load the bitmap into
dcMem.CreateCompatibleDC(pdc);
// Select the bitmap into the compatible device context
CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject(m_bmpBitmap);
lRect.NormalizeRect();
width=bm.bmWidth;
height=bm.bmHeight;
pdc->StretchBlt(0, 0, width*2.28, height*2.28, &dcMem, 0, 0, 255, 255, SRCCOPY);
}
Ehsan Behboudi
|
|
|
|
|
hello
I have a trouble with Sending WM_VSCROLL/WM_HSCROLL message to a ListView
I send WM_XSCROLL to a control for scrolling the control
when i use
::SendMessage(hWnd, WM_HSCROLL, SB_LINELEFT, NULL);
it worked if hWnd is a CEdit handle or CListView handle.
this is send to a CEdit ctrl to scroll the window it works(picture)
this is send to a CListView to scroll the listview it works(picture)
BUT
when i send the drag scroll message to a listview ,it doesn't work
I use :
::SendMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, nPos) , NULL);
when the windows is a CEdit it works
it works(picture)
BUT when the windows is a CListView
it doesn't work(picture)
I use SPY++ finding the window have received the messages I sended
what's wrong??
HELP HELP
Leadream
I am Bruce
|
|
|
|
|
hello
I have a trouble with Sending WM_VSCROLL/WM_HSCROLL message to a ListView
I send WM_XSCROLL to a control for scrolling the control
when i use
::SendMessage(hWnd, WM_HSCROLL, SB_LINELEFT, NULL);
it worked if hWnd is a CEdit handle or CListView handle.
this is send to a CEdit ctrl to scroll the window it works(picture)
this is send to a CListView to scroll the listview it works(picture)
BUT
when i send the drag scroll message to a listview ,it doesn't work
I use :
::SendMessage(hWnd, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, nPos) , NULL);
when the windows is a CEdit it works
it works(picture)
BUT when the windows is a CListView
it doesn't work(picture)
I use SPY++ finding the window have received the messages I sended
what's wrong??
HELP HELP
Leadream
I am Bruce
|
|
|
|
|
hey, does anyone know how to delete a cookie in the temporary internet files folder? because they dont seem to act as files, i couldn't remove one with DeleteFile()
Thanks
Ku
|
|
|
|
|
Does anybody have any adice about learning MFC... I seem to have a hit a bit of a dead end lateley. Im using it lots but sometimes make stupid mistakes and cant realise how to do something. I understand the principles of most things, and quite a bit about messages etc but when I want to actually do something in code I always have so many problems working out the documentation etc an getting it to work. Ive been using the debugger more but 9 times out of 10 it drops us into the guts of MFC where its difficult to have a clue whats going on.... any advice appreciated!
|
|
|
|
|
Make sure you know a good amount of C++ first, so you can figure what the MFC source is doing ( I bury myself in it when I am extending a control, there's no other way ). Buy a good book - every MFC programmer should have the MFC Answer book by Eugene Kain, and download example code from here and play with it. No better way to learn than start with something that works and see what happens when you change/add stuff.
And don't be scared to ask if you get stuck.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Hi,
Does anyone know how i can change the selection color in a rich edit control.
Cheers
Rich
|
|
|
|
|
Hi,
I have a function which returns a HRESULT. Not quite sure how they work, i know there is loads of constants and stuff for them. But I want to define a constant return value of my own. How do i go about this?
Cheers
Rich
|
|
|
|
|
An HRESULT is the only return permitted by COM, excepting a sleight of hand that I believe does not occur under C++, but VB and other languages for people easily confused. It is a complex structure, but in the first instance you can check using two macros, SUCCEDED() and FAILED, as in
HRESULT hr = pISomeINterface->SomeMethod();
if (FAILED(hr))
{
AfxMessageBox("You've stuffed it again !!!!");
return false;
}
Where did the function come from, and why do you want to change the return value ?
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
A completely useless anwser! It has nothing to do with the question asked.
|
|
|
|
|
This may be true, to the illiterate or truly stupid.
I'm still at a loss as to why we have pussies here who refuse to put their names to their posts, but I guess if you're going to insult people that would give you a reason to run and hide....
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Your wit is to much for me, I leave in shame and disgrace.
|
|
|
|
|
If you want to make your own HRESULT you can use the MAKE_HRESULT macro.
Before you go playing with making your own you need to read some documentation on HRESULTS.
|
|
|
|
|
"Winerror.h" has the answers that you are looking for!
use MAKE_HRESULT macro. You may want to check if you
cannot convert your error by a predefined error type by
using the HRESULT_FROM_WIN32 macro.
Good luck!
|
|
|
|
|
Cheers, things are clearer now. I only want to flag to the user of my DCOM routine that the operation couldn't go ahead. So i just set the severity to information, to flag this. I kinda expected there would be a range where we could define our own. Doesn't look that simple though.
Thanks
Rich;)
|
|
|
|
|
How can I add hours ahead to a given date?
e.g., if the date time is now 16-July-2001 17:00:00 PM,
the expected date time is 16-July-2001 23:00:00 PM. (6 hours ahead)
The default DATE Arithmetic operators (-/+) in Visual C++ only apply to DAY.
How can I do so for HOUR?
STDMETHODIMP CMyLibrary::MyGetDate(DATE *MyGetDate)
{
SYSTEMTIME dDate;
GetLocalTime(&dDate);
DATE dTemp;
if (SystemTimeToVariantTime(&dDate, &dTemp) == 0 )
return Error("Conversion Error - MyGetDate");
/* This add one more DAY to a current date */
dTemp = dTemp + 1;
/* How can I add hours to a given date */
*MyGetDate = dTemp;
return S_OK;
}
|
|
|
|
|
if you want to add 2 hours you can use
dTemp += (1 / 24) * 2;
or for 5 hours
dTemp += (1 / 24) * 5;
Disclaimer: I have just written it, not tried to compile and run it, but it should work...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Thanks for your help, I have tried to test it,
but it still add DAYS instead of HOURS.
It seems the DATE + operator adds day with round-up figure:
dTemp = dTemp + 1.5 --> adds one day
dTemp = dTemp + 0.5 --> adds NONE
|
|
|
|
|
Strange, the DATE is an 8-byte floating-point number...
Maybe someone else knows something, I don't...
(Have never really used DATE...)
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|