|
Hi,
I have a dialog box and a picture control (canvas) on that dialog box. I have a list of Images in my dialog box in a list box. I want to implement Drag & Drop feature in my application. I want the user be able to click on the Image with a mouse and then drag the Image to the canvas.
Any help will be appreciated.
Regards,
Mbatra
|
|
|
|
|
Handle the drag event in your dialog or the list. If your list is CListCtrl based use a LVN_BEGINDRAG handler. Otherwise use a WM_LBUTTONDOWN handler. From within that handler create a copy of the bitmap, cache it using the COleDataSource class and start the drag and drop operation:
CBitmap Bitmap;
COleDataSource DataSrc;
STGMEDIUM stgm;
stgm.tymed = TYMED_GDI;
stgm.hBitmap = static_cast<HBITMAP>(Bitmap.Detach());
stgm.pUnkForRelease = NULL;
DataSrc.CacheData(CF_BITMAP, &stgm);
DataSrc.DoDragDrop(DROPEFFECT_COPY);
On the target side, use the COleDropTarget class. If the target is a CView derived class, it is simple to implement by adding a COleDropTarget member to the view, adding the virtual OnDrop... handlers and registering the view as drop target from OnInitialUpdate() . With other window types than CView based ones, you must derive your own window specific COleDropTarget class that knows your window class so that it can access the required functions and members.
From within the COleDropTarget::OnDrop[Ex] function, use the provided COleDataObject to get the data by calling GetData(CF_BITMAP, &stgm) .
When using the MFC COle... classes, you must include afxole.h (e.g. in stdafx.h) and call AfxOleInit() from within InitInstance() of your Windows app class.
|
|
|
|
|
Hello guys. I am trying to write a small recording program but am stuck in basics. I can not pass the pointer of the WaveInProc function properly. I am trying it in two ways, both of them widely used on online examples.
1 - rResult = ::waveInOpen(&phWaveIn, WAVE_MAPPER, &pcmWaveFormat, (DWORD)WaveInProc, 0, CALLBACK_FUNCTION);
2 - rResult = ::waveInOpen(&phWaveIn, WAVE_MAPPER, &pcmWaveFormat, (DWORD)&WaveInProc, 0, CALLBACK_FUNCTION);
3 - rResult = ::waveInOpen(&phWaveIn, WAVE_MAPPER, &pcmWaveFormat, (DWORD)(VOID*)WaveInProc, 0, CALLBACK_FUNCTION);
Their corresponding error messages are shown as under
1 - error C2440: 'type cast' : cannot convert from 'void (__stdcall CWaveApiDlg::* )(HWAVEIN,UINT,DWORD,DWORD,DWORD)' to 'DWORD'
2 - error C2276: '&' : illegal operation on bound member function expression
This is what WaveInProc looks like in my .cpp file
void CALLBACK WaveInProc(HWAVEIN hDevice, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
}
Everything seems to be fine ... what is wrong here? Thanks for any help.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Well, you are passing a pointer to a (non static ) method of class CWaveApiDlg where a function pointer is requested. You cannot do that. Either pass a (pointer to a) global function or to a static method of the class.
Veni, vidi, vici.
|
|
|
|
|
You are incorrectly trying to cast the address of the callback function to a DWORD . But according to the documentation[^], that should be a DWORD_PTR .
|
|
|
|
|
Hello all!
I'm working on a program in which, I'm receiving the bytes of an image and after storing this creating a bitmap to display.
This is my Main code Please see this..
static char buff[MAX_SIZE];
int num;
num=recv(Socket, buff, sizeof(buff), 0);
std::ifstream is;
is.open(buff, std::ios::binary);
is.seekg(0, std::ios::end);
num = is.tellg();
is.seekg(0, std::ios::beg);
is.read(buff, num);
tagBITMAPFILEHEADER bfh = *(tagBITMAPFILEHEADER*)buff;
tagBITMAPINFOHEADER bih = *(tagBITMAPINFOHEADER*)(buff+sizeof(tagBITMAPFILEHEADER));
RGBQUAD rgb = *(RGBQUAD*)(buff+sizeof(tagBITMAPFILEHEADER)+sizeof(tagBITMAPINFOHEADER));
BITMAPINFO bi;
bi.bmiColors[0] = rgb;
bi.bmiHeader = bih;
char* pPixels = (buff+bfh.bfOffBits);
char* ppvBits;
hbitmap = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**) &ppvBits, NULL, 0);
SetDIBits(NULL, hbitmap, 0, bih.biHeight, pPixels, &bi, DIB_RGB_COLORS);
GetObject(hbitmap, sizeof(BITMAP), &cBitmap);
On checking the bytes received,,its ok to be there from both client and server side, But my code is unable to read these bytes to create a bitmap.
Thanks in advance for your help!
|
|
|
|
|
You only perform a single recv() on your socket; how do you know that you have received all the data? Also, what is the purpose of the ifstream in the above code?
|
|
|
|
|
ifstream is to read buffer to create a bitmapinfo.
and if all the data is not received then there should be something on window. either black or something else but there is no activity.
|
|
|
|
|
toms from newdelhi wrote: fstream is to read buffer to create a bitmapinfo. Read what buffer? Where is the actual bitmap data that you are reading? Assuming the client is sending this as a binary stream from the original bitmap buffer there should be no work to do at the server end other than ensuring you capture the entire buffer.
|
|
|
|
|
yes I got it...
ifstream is basically for a file and not for a binary data.
but how to recv all data and create a bitmap with this...
Are you having any idea?
|
|
|
|
|
toms from newdelhi wrote: ifstream is basically for a file and not for a binary data. What does this have to do with your problem?
As I understand it you are trying to transfer a bitmap from one computer to another via a network socket. So it is just a matter of transferring the binary data without any changes to its structure, and displaying the bitmap on the target system.
|
|
|
|
|
yes exactly this is the thing.
But not getting the exact thing how to do this?
|
|
|
|
|
toms from newdelhi wrote: yes exactly this is the thing. But not getting the exact thing how to do this? Too many things here. What exactly do you not understand about transferring a stream of bytes from one PC to another through network sockets? You can find plenty of samples via a Google search.
|
|
|
|
|
either you need to have a protocol implementation in your Clien-Server communication or you have to make sure that you send all the buffer at one time. If you are choosing a protocol means you first send a message to the server that am going to send a image buffer with size/length X and at the server store this and use this value for the next receive command.
If you are going to use whole buffer at one time, just use that buffer as such to create re-create your image. having a protocol is the best choice. if you google you can find many protocols choose the simplest one that suits your requirement.
Jibesh V P
|
|
|
|
|
Hello everybody i have a small question , not big enough for the quick answers . I am working on a MFC project a little bit old. And i had to add a header to the print result. My problem was with the font Size. After some tries i found the really useful Article about Printing trics. The problem was when i used
PrinterFont.lfHeight = -MulDiv(12, dc->GetDeviceCaps(LOGPIXELSY), 72);
Printing was ok but the PrintPreview wasnt. The font size was still small and i know why the GetDeviceCaps was returning the dpi of the monitor. This was understandable . After some digging in the code i found that for the rest printed text the font size was calculated a little bit different. For the font Height was taken the absolute value of the height multiplied by the zoom and all divided by some constant. My question is is there some practice about that kind of calculation . To be honest i don't think its a good idea to use it. I don't believe that all printers will print the same thing. But the PrintPreview and the Print result are pretty much the same.
What do you think ?
Thank you
|
|
|
|
|
Normally for printing the mapping mode is set to MM_TWIPS . Is that the practice you are looking for?
Blog : http://sujay-ghosh.blogspot.com
|
|
|
|
|
I created a MFC Smart Device App with Visual C++ in Visual Std 2008. I have dialog forms, I created SQLite database in VS2008. And I imported sqlite.dll sqlite.def etc. files. Now, I want to select data from my database, show in my textlist for example. But I don't know How can I do this.
What is my sqlconnection sentence? How can I create test.db? Which class will I write my sqlconnection sentence, or my select, insert, delete, update sql code? Can anybody explain this step by step?
It is my Job. I research this topic since a week, but still I can not solve this problem. Please help me!
|
|
|
|
|
|
We have developed a COM DLL 64 bit on Windows Server 2008 R2 - 64 bit and this dll is successfully register when visual studio 2010 is installed on the machine but when on a fresh machine its unable to register with following error:
module xxxx.dll failed to load
make sure the binary is stored at the specified path or debug it to check for prob with the binary or dependent dll files
After a lot of investigation, we found that if Microsoft C++ runtime 2010 10.0.3019 is installed, then only dll will be registered. Can anyone provide the required list of dependecy. Thanks in advance.
|
|
|
|
|
|
I need to play a mp3 file on UPNP device (TV) using program.
Could you help me with related articles or any other information?
|
|
|
|
|
Is this[^] article suitable for you ?
|
|
|
|
|
Thank you but this is not for me.
I am looking to play audio on UPNP device.
|
|
|
|
|
Maybe this[^] article will help.
|
|
|
|
|
This is Vb and not able to debug as it is for Win8 specific.
We need for window7 or lower.Please help.
|
|
|
|