|
Well, you can either try this (using GetMessagePos()[^] as DavidCrow already suggested):
CPoint Pt(GetMessagePos());
or
POINT Pt;
GetCursorPos(&Pt);
picture_control.ScreenToClient(&Pt);
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
thank you very much Code-o-mat.
and how can i keep these lines after i draw because in just a few second
all lines are disappear.
|
|
|
|
|
I'm not sure what you mean, but if my guess is correct, you are drawing onto the picture control with the mouse. In this case, you will either have to remember what lines you have drawn, this aproach is more complicated, or simply, draw ONTO the bitmap in memory also, not just the window, this is probably easier done. Create a memory DC, select the bitmap into it and use MoveTo/LineTo to draw your lines. Don't forget to clean up after you are done drawing.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
i try to search MemDC but i don't understand. T_T
can i have example of MemDC and where do i put these function in if i want to show these lines on the image(old) until i load new image, these lines will gone?
thanks for your help
|
|
|
|
|
Well, if you load a new bitmap into your picture control then yes, the lines will be gone. And for the memdc, you can do something like this:
CDC MemDC;
MemDC.CreateCompatibleDC(dc_of_picture_control);
CBitmap *origBitmap = MemDC.SelectObject(pointer_to_bitmap_you_want_to_draw_to);
MemDC.MoveTo(0, 0);
MemDC.LineTo(line_to_x, line_to_y);
MemDC.SelectObject(origBitmap);
MemDC.DeleteDC();
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
void CMyGUIDlg::OnStnClickedPic1()
{
CWnd* prnt = GetDlgItem(IDC_PIC1);
CDC *pdc = prnt->GetDC();
CDC MemDC;
MemDC.CreateCompatibleDC(pdc);
CBitmap *origBitmap = (CBitmap*)MemDC.SelectObject(&m_pic1); //m_pic1.SetBitmap("LenaRGB.BMP");
MemDC.MoveTo(0, 0);
MemDC.LineTo(100,100 );
MemDC.SelectObject(origBitmap);
MemDC.DeleteDC();
}
T_T still can't do it. i try what you said but it is still no line after i minimize it.
hope you not bored me yet i'm sorry but thank you very much
|
|
|
|
|
What is m_pic1? Isn't it a CStatic that shows your bitmap? If it is, don't select THAT into the DC (you shouldn't be able to do that i think), ask it for its bitmap and select that. So if it is a CStatic or derivative, try using GetBitmap[^] like:
...
CBitmap TempBmp;
TempBmp.Attach(m_pic1.GetBitmap());
CBitmap *origBitmap = MemDC.SelectObject(&TempBmp);
...
MemDC.SelectObject(origBitmap);
TempBmp.Detach();
...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
still doesnt work - -
but thank you very much
i load image by using this.
void CPictureBox::ShowBitmap(CPaintDC *pdc)
{
//Create a device context to load the bitmap into
CDC dcMem;
dcMem.CreateCompatibleDC(pdc);
//Get the Display area available
CRect lRect;
GetClientRect(lRect);
lRect.NormalizeRect();
//select the bitmap into compatible device context
CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject(&m_bmpBitmap);
//m_bmpBitmap.SetBitmapDimension(lRect.Width(),lRect.Height());
//copy & resize the window to the dialog window
pdc->StretchBlt(0,0,lRect.Width(),lRect.Height(),&dcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}
void CPictureBox::OnPaint()
{
CPaintDC dc(this); // device context for painting
RECT rect;
GetClientRect(&rect);
dc.FillSolidRect(&rect, RGB(255,255,255));
if(m_sBitmap!="")
ShowBitmap(&dc);
}
void CPictureBox::SetBitmap(CString strBitmap)
{
m_sBitmap = strBitmap;
HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
m_sBitmap, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);
// Do we have a valid handle for the loaded image?
if (hBitmap)
{
// Delete the current bitmap
if (m_bmpBitmap.DeleteObject())
m_bmpBitmap.Detach(); // If there was a bitmap, detach it
// Attach the currently loaded bitmap to the bitmap object
m_bmpBitmap.Attach(hBitmap);
}
m_bmpBitmap.GetBitmap(&bm); //Get Bitmap Structure
Invalidate();
}
maybe this is why it doesn't work.and i dont know what should i do with it to make this work. T_T
anyway thanks to you.
|
|
|
|
|
I believe -according to what i see in the code you gave- you have to select m_bmpBitmap into the memory-dc when you draw the lines.
Btw i see you are using StretchBlt, that will cause problems with drawing those lines, but first try to get it to keep the lines first.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
thank you for all your help.
|
|
|
|
|
I have a static function in that I have some array members, that function will be called from so many places, I want to know that when ever the process of the function is over means all the member variables will be get released from memory or will Occupy the space.
|
|
|
|
|
rr_ramesh71 wrote: I have some array member
What kind of array it is ?
|
|
|
|
|
char lbuffer[5000];
sprintf(lbuffer,"Stock in List [%s] Quantiry %d", SymbolList,qty);
but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed
|
|
|
|
|
Yes the buffer will be released.
rr_ramesh71 wrote: but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed
How do you check that ? Are you using some tools to verify that information ?
|
|
|
|
|
rr_ramesh71 wrote: // will this array get released after the function over
Yes, You don't need to worry about memory, as its been allocated on stack.
|
|
|
|
|
How are the arrays declared?
If they're declared as local variables (as shown with localArray below), they will definitely be cleared up, as they're allocated space on the stack, which is tidied up when the function exits.
double SomeFunction(int x)
{
double localArray[] = { 1.0, 2.0, 3.0, 4.0 };
const size_t localArraySize = sizeof localArray / sizeof localArray[0];
return x<localArraySize?localArray[x]:-1.0;
}
|
|
|
|
|
The only thing you have to take care in this case, is that if you are allocating memory with new (or new[]), then you should delete it with delete (or delete[]). For the rest, the memory will be automatically released.
|
|
|
|
|
Also don't forget malloc and free (I know, i know, don't use malloc and free in C++ but they CAN be used), and maybe GlobalAlloc and GlobalFree (or LocalAlloc and LocalFree but as far as i know those are no longer different from their Global counterparts)
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Hello everyone,
In order to test a ini file (for the read write operation) what are the steps I should make...What I have dome is...
I created an ini file in the current directory, also inside the debug folder.Then I added that to my project workspace....and I wrote the following code
int iResult = GetPrivateProfileInt("extensions","123",555,"info.ini");
cout<<"\n-:"<<iResult;
my ini file content is
[extensions]
123=001100
333 = 9999
444=8888
But its always returning 555
What mistake I might have done?
project is a win32 application
Thanks in advance
I am a learner Always
|
|
|
|
|
himangshuS wrote: ,"info.ini");
Try giving full path of this file. I think it's not in local folder of you application.
|
|
|
|
|
still the same
I am a learner Always
|
|
|
|
|
If you are running your program from withing Visual Studio (pressing F5 for instance) the working folder is the same folder that has your .vcproj/.sln files - NOT the debug/release folder, so you file would have to exist in the same folder as the .vcproj/.sln.
When you run the program by directly clicking on the .exe file from Windows Explorer, the working folder is initially the same folder with the .exe.
Also, is there some reason that you have blank lines in your .ini file?
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
I have the same file in the debug folder too....
And ya I removed the blank lines and tried....
But the same again...
I am a learner Always
|
|
|
|
|
himangshuS wrote: still the same
But what does your changed code look like? If you provide the correct path, the value of iResult will be 1100 .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
great it works...
hey David,...A sincere thanks to you
Regards,
Himangshu....
I am a learner Always
|
|
|
|