|
|
See GDI+
Image::RotateFlip
|
|
|
|
|
Hi,
As u Suggested I started to use Image object in GDI+.My intention was to make a Image object and manupulate its position and orientation.(As given in msdn page titled Drawing, Positioning, and Cloning Images - refer the link below)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/AboutGDIPlus/IntroductiontoGDIPlus/OverviewofGDIPlus.asp[^]
I tried to insert a image to my main frame using "Image" in GDI+. But a runtime error (unhandled exception) is occuring when im going to run the program.The details are as follows.
I have included "gdiplus.h" in StdAfx.h. There were no issues on that.But the problem started when i tried to insert a image using the guidelines given in above msdn link(.Drawing, Positioning, and Cloning Images - GDI+)
As per that method I used the following code:
CPaintDC dc(this);<br />
Graphics myGraphics(dc.m_hDC);<br />
<br />
Image myImage(L"robot.gif");
myGraphics.DrawImage(&myImage, 20, 10);
The program Built & compiled successfully in VC++ 6.0.But didn't run.It gaves a error.
When I insert that code to a .NET project the error message says that ;"Unhandled exception at 0x7c9105f8 in tttdk.exe: 0xC0000005: Access violation reading location 0x00000010."
When I break it , it shows the location of the error in the following cpp file.
D:\VS\VC\atlmfc\src\atl\atls\allocate.cpp
..<br />
<br />
...<br />
<br />
CAtlTraceCategory *CAtlAllocator::GetCategory(int iCategory) const<br />
<br />
{<br />
<br />
if(iCategory == m_pProcess->CategoryCount())<br />
<br />
return NULL;<br />
<br />
<br />
<br />
ATLASSERT((iCategory < m_pProcess->CategoryCount()) || (iCategory == -1));<br />
<br />
CAtlTraceCategory *pCategory = NULL;<br />
<br />
if(iCategory >= 0)<br />
<br />
{<br />
<br />
BYTE *pb = reinterpret_cast(m_pProcess) + m_pProcess->MaxSize();
<br />
pCategory = reinterpret_cast(pb) - iCategory - 1;<br />
<br />
}<br />
<br />
return pCategory;<br />
<br />
}<br />
<br />
.............. Please help me regarding the above matter ASAP.or else tell me way to Insert a GIF image to a MFC frame and to change its position and rotate by given angles time to time.
Dhananjaya
ENTC
UoM
ENTC
UoM
|
|
|
|
|
if you want to show gif or jpeg or png or bmp you can use from CImage class but im not sure its working in VC6.0 or no but this problem
I think this code solve your problem
<br />
ULONG_PTR m_gdiToken;<br />
GdiplusStartupInput gdiplusStartup;<br />
<br />
GdiplusStartup(&m_gdiToken, &gdiplusStartup, NULL);<br />
<br />
img = Image::FromFile(L"c:\\0.jpg");<br />
<br />
CPaintDC dc(this);<br />
Graphics myGraphics(dc.m_hDC);<br />
...<br />
...<br />
|
|
|
|
|
How can be allocated virtual memory? (PAGEFILE)?
|
|
|
|
|
VirtualAlloc()
Tanvon
happy programming
the brain behind ...
|
|
|
|
|
Thanks
|
|
|
|
|
You probably don't want to do what you think you want to.
The operating system will use the page file to back any virtual memory allocation that doesn't come from a memory-mapped file. This is completely automatic - as demand for memory increases, and on a periodic basis to ensure that a reserve of physical memory is available, the operating system removes pages from your process's 'working set' - a process called 'trimming' - to return them to the available physical memory pool. If the page has been modified since last written to disk, the new contents will be written to the appropriate place in the page file.
The 'working set' is the set of pages that the OS thinks are most appropriate to be in memory for the process at the current time. When trimming, it removes the pages that have been used least recently. A phenomenon known as 'locality of reference' normally means that the pages used most recently are the most likely to be referenced next; a program that has poor locality of reference can lead to thrashing as the OS removes the least recently used page, the program then references it and the OS has to read it back in - page it in - from the page file.
To ensure that it can always write any given page without running out of space in the page file, the operating system reserves space in the page file for each virtual memory page allocated, at the time of the allocation. You don't need to do anything for this to happen.
The VirtualAlloc function only allows you to make page-sized allocations (4KB on x86), and then only from 64KB-sized address space reservations. Using VirtualAlloc badly will waste your virtual address space. Only use it if you really know what you're doing. For most normal programming, you should use a heap, allocating with new , malloc , LocalAlloc or HeapAlloc . A heap is simply a data structure that manages a block of virtual memory, and the Heap Manager has the ability to deal with virtually any size block quite well. This flexibility does mean that it can be slower than a specialised implementation handling allocation for specific data structures, but in general it's a good choice.
|
|
|
|
|
i'm very impressed
Thanx a lot.
|
|
|
|
|
I was trying to follow through a tutorial I found at the following site to implement a linked list:
http://etude.uwaterloo.ca/~ctrudeau/lessons/C++/tutorial2.html. The source code is on the website, and I was trying to test this class so I could inherit it from an implementation I was trying to code.
The code breaks when the method 'first' is called
p = (DataObject *)list.first();
which calls inline function *first
List.cpp
void *first()
{
if( pHead == NULL )
return( NULL );
return( pHead->Data() );
}
Which calls method *Data
..
List.h
void *Data() { return( pData ); }
Then the code breaks and the following error is displayed:
Unhandled exception at 0x... in ListClass.exe: 0x... (another memory address) Access violation reading location 0x... (another memory address).
Any idea what might have caused this leak?
Jon
|
|
|
|
|
i'm going to guess that pHead contains random junk data (was never initialized to NULL, nor set to hold valid data).
|
|
|
|
|
Hi all,
I had created one mainframe window and several document templates inside it. I had called all those from the "App" class.
Now I want to disable some buttons in the toolbar in one of its view class.
I tried....
CTCToolBar m_wndtoolbar; // Derived from CToolBar
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON,ID_USECASE_NEW,FALSE);
and---->
m_wndtoolbar.GetToolBarCtrl().EnableButton(ID_USECASE_NEW,false);
But the application crashed...
can any one help me....
Thanks in advance..
vinsankar
|
|
|
|
|
Vinod A Sankaranarayanan wrote: CTCToolBar m_wndtoolbar; // Derived from CToolBar
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON,ID_USECASE_NEW,FALSE);
Did you even create the toolbar between those two calls ???
if the toolbar already exists then you need to grab a pointer to that already created toolbar and not create a new instance by CTCToolBar m_wndtoolbar; .
Don't believe everything you think.
|
|
|
|
|
Thanks...
I grab that pointer and try to disable some buttons by using the functions described in my first message.
But it doesn't work...
Is there any other solution?
vinsankar
|
|
|
|
|
Map command-update handler (using ON_UPDATE_COMMAND_UI).
As for example we have a toolbar button with command identifier ID_MYCOMMAND:
class CMyView : public CView
{
afx_msg void OnUpdateMycommand(CCmdUI* pCmdUI);
DECLARE_MESSAGE_MAP()
};
ON_UPDATE_COMMAND_UI(ID_MYCOMMAND, OnUpdateMycommand)
END_MESSAGE_MAP()
void CMyView::OnUpdateMycommand(CCmdUI* pCmdUI)
{
pCmdUI->Enable(FALSE);
}
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
Hi CuCu....,
Thanks......a lot..........
it works.........
Once again.....thanks......!!!
Regards
vinsankar
|
|
|
|
|
Hi Vinsankar,
You are welcome!
Ovidiu
|
|
|
|
|
How do you use from CTCToolBar in your code that you get a crash?
|
|
|
|
|
Hi,
Does anybody know of a way that I can host an ActiveX control in such a way that it draws to a memory context instead of directly to the screen? I'd like to modify what the ActiveX control displays before it hits the screen, rather than try and draw on top of it once it has already been drawn, which is asking for trouble. Im currently using the ATL CAxWindow class to host the control, but its not too late to switch to MFC or something if there is a way to do this.
Thanks,
Andy
|
|
|
|
|
Jeff Prosise briefly covers "Windowless controls in his book "Programming Windows with MFC. Second Edition"
Check out IOleInPlaceObjectWindowless and IOleInPlaceSiteWindowless. You should be able to pass in a MemDC instead of the standard DC. I never used them because the amount of work appeared comparable to creating my own control classes. The container is responsible for passing in messages and such and I needed a third option to output the drawing commands to PDF so windowless controls just didn't fit my needs but from what I've read on them, they sound like they would work for you based on what you asked.
I'm not sure if that helps, but for what it's worth...
|
|
|
|
|
Thanks bob, I shall look into them.
From a lengthy search around the net, I came upon a comment from an MVP, which said, "...get the view image via IViewObject and use the view change notification. It seems you are supposed to derive a class from
CAxWindow and implement IAdviseSink's methods (it already derives from IAdviseSink)."
This seems a relatively straight forward approach in theory, but I wasn't aware that CAxWindow is derived from IAdviceSink, or at least it doesn't seem so from looking at CAxWindow's implementation in AtlWin.h. Does this sound feasible to you? I would appreciate a little guidance to appreciate this method if true.
Many thanks,
Andy
|
|
|
|
|
I think I misunderstood your situation. I was assuming that you were also creating the controls you were hosting. Now I'm thinking your refering to hosting someone elses ActiveX controls and wanting to have them draw into a memDC. Correct me if I'm off track.
I don't use ATL so I won't be much help with the CAxWindow stuff.
I have used IViewObject to get the control to draw to a MemDC and I based my approach off of Andrew Wirger's article[^]. Have a look in the IViewObject section of the article if you haven't already found it.
Your approach sounds reasonable but again, I have little experience with ATL.
|
|
|
|
|
hi all
i had implemented the key board hooks the capture the key strokes but it work for only the current appplication not for all application(application from which these are executed).
when i switch windows of application then it did not work and i had to call the setwindows hook functin once again, is it due to the AfxGetapphandle() or why these are not working here is the code.
it is setting window hook
HINSTANCE hInstance;
hInstance=AfxGetInstanceHandle();
hHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc,hInstance, 0);
}
it is call back function
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if (nCode<0)
{
return (CallNextHookEx(hHook,nCode,wParam,lParam));
}
else if (((DWORD)lParam & 0x40000000) &&(HC_ACTION==nCode))
{
KeyLoggerMain(wParam);//show which key is pressed
}
LRESULT RetVal = CallNextHookEx(hHook,nCode,wParam,lParam);
return RetVal;
}
it function working is same as i found from the MSDN.
Tasleem Arif
|
|
|
|
|
tasleem143 wrote: HINSTANCE hInstance;
hInstance=AfxGetInstanceHandle();
i think the problem is with the instance u taking.
try the following way
create a global vaibale of HINSTANCE.
initialize this variable with the hinstance passed in the DllMain().
pass this hinstance in the SetWindowsHookEx()...
or if ur using MFC dll initialize the hinstance as shown below
BOOL CDllApp::InitInstance()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hins = AfxGetInstanceHandle();
return CWinApp::InitInstance();
}
nave
|
|
|
|
|
i was not implementing it in the form DLL its in the form of application MFC APP wizard(exe). i think dats why problem was comming i had tried to pass null in the place of hinstace but it did not work look i had to implement it in the form of DLL now.
Tasleem Arif
|
|
|
|