|
Hi again,
Did you see Solitaire game(I'm sure you saw that !).
I want to know, how can drag and drop pictures like that ?
Please help me ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hi,
I had to do the same thing about a year ago for my card game and it works great:
(UltraUno -- http://www.outreach4him.50megs.com/UltraUno/ -- yes, this is a plug! )
I found Chris Maunder's article on bitmap controls very useful, but it looks like the link is broken (not sure who I would notify to fix it):
http://www.codeproject.com/bitmap/bitmappicture.asp
His control is derived from a CStatic, and the way I did the drag and drop stuff is to create one CBitmapPicture controls in the view and use the WM_LBUTTONDOWN to see if the user clicked the bitmap control. I set a flag and then track the WM_MOUSEMOVE messages and move the bitmap around based upon the initial coordinates and the current coordinates. When the WM_LBUTTONUP msg is received, I release the capture on the bitmap control.
If needbe, I can e-mail you a code sample directly...
Chris
|
|
|
|
|
Hello Chris, Thanks aloooooooooooot for your help
I see your game, that was prefect ...
YES, i'm intrested to have your source code.
If possible please send it to hadi_rezaie@yahoo.com
Thx aloooooooooot !
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
OK, I'm relatively new to ATL/ActiveX/COM.
We have an MFC application (CView and CDialog usage) built with VC++6 SP5.
I am in the process of creating an ActiveX control (via ATL) that will be used by this application, but I'm having a problem.
I can insert the control onto the template in the resource editor and it shows up. I run the application and the control functions properly. But I need to have access to the interface of that control.
I used:
CAxWindow m_axTheControlWindow;
CComPtr<ITheControlInterface> m_ctlTheControl;
CWnd* pControl = GetDlgItem(IDC_THECONTROLID);
if (pControl)
{
m_axTheControlWindow.Attach(pControl->GetSafeHwnd());
hr = m_axTheControlWindow.QueryControl(&m_ctlTheControl);
if (FAILED(hr) || !m_ctlTheControl)
{
ATLASSERT(false);
}
}
but QueryControl returns E_FAIL and m_ctlTheControl is NULL.
I guess it has something to do with how MFC keeps track of OLE controls (COleControlContainer) ???
Perhaps the only way I could communicate with this control would be via IDispatch?
The control was create via the VC++ Insert | New ATL Object... wizard. It's a Full Control (Single Threaded, Dual interface, No aggregation, Support ISupportErrorInfo, support connection points, not based on another control, normalize dc, insertable, opaque, solid background, no stock properties).
Now, this is just the bare-bones wizard code. Nothing has been implemented as far as IDispatch or ISupportErrorInfo or connection points beyond what the wizard gives, but I didn't want to go too far before finding out it wasn't going to work.
Thanks for any help.
Gil
|
|
|
|
|
OK, now that this is buried deep it probably won't be seen, but a co-worker of mine has helped me figure this out.
CWnd* pControl = GetDlgItem(IDC_THECONTROLID);
if (pControl)
{
pControl->EnableAutomation();
IUnknown* pUnk = pControl->GetControlUnknown();
CComQIPtr<ITheControl> pIFace(pUnk);
if(pIFace)
{
pIFace->AControlMethod(value);
}
}
|
|
|
|
|
Hi !
I started to develop an ATL object with VC++ 6.0. The COM object is a DLL, supporting the MFC.
In some particular situation, I need to display a dialog box. I created a new class, derived from CDialog, as I usually do with a normal MFC application (Let's call this class CTestDlg).
In the ATL class, I added a member of type of my dialog class (CTestDlg m_myDialog), and when I want to display it, I do : m_myDialog.DoModal();
When I run this COM object, at the moment of displaying the dialog, I get an ASSERT error. In the debugger, the failed assertion is :
ASSERT(afxCurrentResourceHandle != NULL)
which is called in the function CDialog::OnInitDialog()
I'm now wondering if a COM Dll is able to display a dialog box, and if yes, how I'm supposed to do it !!!
Any help will be greatly appreciated !
Thank you !
Jerome
|
|
|
|
|
yes, it's possible to do this (i do it all the time).
1. where are you calling DoModal ? (don't do it in the ATL object's constructor)
2. are you using that little MFC context macro (forget what it is, but you see it at the top of methods that use MFC...) ?
-c
I don't care, and you can't make me.
|
|
|
|
|
Chris Losinger wrote:
1. where are you calling DoModal ? (don't do it in the ATL object's constructor)
From a method which is part of my interface.
2. are you using that little MFC context macro (forget what it is, but you see it at the top of methods that use MFC...) ?
...mmm....nope, I didn't find any context stuff....
Jerome
|
|
|
|
|
Chris is refering to the AFX_MANAGE_STATE(AfxGetStaticModuleState()) macro that gets added to ATL method when added thought the Class View add method option. This is needed so the application looks at the right resource table when executing the ATL methods. If your ATL object is using its own resources (dialogs, bitmaps, cursors, etc.) you must call the manage state macro.
Hope this helps...
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Ok....I'm making some progress.
I have this AFX_MANAGE_STATE in each of my methods of my interface.
I figured out what I was doing wrong. I tried to display a dialog box, derived from CDialog.
Now, I used the 'Insert ATL Object->Miscellaneous->Dialog' to create my dialog.
I have a problem remaining though : I have a CListBox in my dialog box, and when I do
CListBox* pList=(CListBox*)GetDlgItem(IDC_LIST);
it works, but then, when I do
pList->AddString("Test");
I have an ASSERTION failure.
Do you have any idea how I could use the ListBox control (and any other controls ?)
Thanks !
Jerome
|
|
|
|
|
hi,
I want to get the index of the element clicked in a tree.I can get total elements but can I get the index or relative position of the element I clicked?It may be even in the child nodes.
I have figured out a way but it seems too complicated so wanted to check first; but again it may be how the function would have operated if existed,I dont know.
So,can I?
Sorry about the premature entry
waiting.
|
|
|
|
|
Nope, there is no index in CTreeCtrl. You can only enumerate thru items and count them manually
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
A method would be to store an index in the items data: SetItemData. Then when you need: GetItemData.
Joel Lucsy (jjlucsy@ameritech.net)
|
|
|
|
|
hi,
I want to get the index of the element clicked in a tree.I can get total elements but can I get the index or position of the element I clicked?
|
|
|
|
|
CTreeCtrl::GetSelectedItem
-c
I don't care, and you can't make me.
|
|
|
|
|
Hi there,
Please answer to my questions about DLL …
Q1.
I want to write simple function in a Win32 DLL project …
And call that by LoadLibrary …
I made a Win32 DLL project …
Then I wrote this function in .h file:
__declspec(dllexport) void SayHello();
And I wrote it in .cpp file:
void SayHello()
{
MessageBox(NULL, “Helllllllllo !”, “Info”, MB_ICONINFORMATION);
}
Then I compiled it without any problem …
In my MFC exe project …
I loaded that:
CoInitialize(NULL);
HMODULE hModule = LoadLibrary( "test4.dll" );
FARPROC procFunc;
procFunc = GetProcAddress(hModule, "SayHello");
(procFunc)();
FreeLibrary(hModule);
CoUninitialize();
There is no problem in DLL path file, I checked it …
But when I run this code, program show me this error:
“Unhandled exception in testdll.exe : 0x0000005 : Access violation.”
What is my wrong ?
Q2.
If I write a DLL by MFC DLL, can I use of that from other programming language like Delphi or VB ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
are you testing hMoudle or procFunc for NULL ? you should.
-c
I don't care, and you can't make me.
|
|
|
|
|
Ok,
hMoudle returned value ...
But procFunc returned NULL !!!
Can you help me, please ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
The reason that GetProcAddress returns NULL is because the SayHello function does not exist in your dll. C++ Name mangling would change that to an entry like this: SayHello@@YAXXZ. I answered this question with more detail in the other thread.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
You are having a problem with the name mangling that the c++ compier does on functions. The compiler will generate and export this symbol instead:
SayHello@@YAXXZ
So if you want to call load library on this function, then you need to ask for that symbol instead. If you chang the signature of the function, the mangling will change as well, so you will have to use the Depends tool that came VC++ to determine what the name of the exported symbol is.
If you would like to turn off name mangling for this function you can prepend your function definition with this:
extern "C" void SayHello();
About your second question, yes you will be able to use your functions from a DLL in Delphi or VB as long as you only declare functions, if you would like to use a class that you exported from an MFC or a C++ DLL then you will need to create a COM component to represent that class. Also, I would recommend turning off name mangling if you plan on using these functions in Delphi or VB.
Good Luck.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi dear kilowatt
Thanks for reply ...
I got confused
I runed Dependes program and that show me this function in my DLL: ?SayHello@@YAXXZ
In fact, i want to use this DLL in Delphi program ...
Now, Please please please tell me how could i fix it ?
I must make .DEF file ?
But i don't know what i must write in that !!!
Plz help me ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Your function is failing to be found by GetProcAddress because it is not called SayHello, it is name mangled and the new name is SayHello@@YAXXZ.
In order to make the name of your exported function be just a plain SayHello, you will need to declare it like this in your header file:
extern "C" _declspec(export) void SayHello();
The _declspec(export) directive is probably a macro definition in your file. Anyway, the extern "C" defintion will turn off name mangling and you will be able to refer to your function just as SayHello rather than SayHello@@YAXXZ.
I am not that familiar with Delphi, but if you are supposed to declare a .DEF file in order to use the DLL, then you should declare the SayHello function int he IMPORTS section of this file. I think you will then need to link your delphi program with the .lib file that is created for your DLL.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Thanks alooot kilowatt,
Yes, now IT WORKS FINE !
I used .DEF file for it ...
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Sample .def file
; myfile.def : Declares the module parameters for the DLL.
LIBRARY "mylib" BASE=0x10000000 ; change the base to something better
; to avoid collisions with other modules
DESCRIPTION 'does a lot of useful stuff'
EXPORTS
myFunction ; no parameters or anything else, just name of function
myOtherFunction
This will turn off mangling as well as setting some useful parameters, like the default base address. Set this to something other than 0x1000000 as this is the default base for C++ modules (speed up loading time that way).
/moliate
Two o'clock and walking through familiar London - Or what was familiar London before the cursor deleted certain certainties -
I watch a suit and tie man giving suck to the Psion Organizer lodged in his breast pocket
its serial interface like a cool mouth hunting his chest for sustenance, familiar feeling, and I'm watching my breath steam in the air.
Neil Gaiman - Cold Colours
|
|
|
|
|
Hello moliate,
Thanks alooooooooooooooooooooot for your help.
IT WORKS
I can't believe it !
Now it works fine ...
Now i think, i can go and sleep in rest !
Really thanks and thank you for simple .DEF ...
I just have other question ...
If i define a enum like this:
enum Days
{
sunday = 0;
saturday = 1;
};
or classes and strctures ...
How about them ?
How could i define them in .DEF file ?
I must write only their names in .DEF ?
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|