|
I am having trouble with this code. This is giving output as mesgbox with 0, ie successful, but is not filling the image. Please look in to it. I want to replace all connected pixels of a particular color with another color. Normal function outruns stack memory.
Any suggestions will be appreciated.
void dlg::OnButton1()
{
CClientDC* hdc= new CClientDC(this);
CFileDialog fd(1,0,0,0,"Bit Map(*.bmp)|*.bmp||");
fd.m_ofn.lpstrTitle="Browse";
if(fd.DoModal()==IDOK)
{
str=fd.GetPathName();
HBITMAP hBmp = (HBITMAP)::LoadImage(NULL,str,
IMAGE_BITMAP,0,0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
bmp.Attach(hBmp); //bmp is member of the class dlg
CClientDC dc(this);
bmDC.CreateCompatibleDC(&dc);
pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
dc.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
bmDC.SelectObject(pOldbmp);
}
}
void dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
COLORREF rgb;
CClientDC dc(this);
CQuickFill qf;
int i;
rgb=RGB(255,10,10);
i=qf.QuickFill(&bmp,point.x,point.y,rgb,CLR_INVALID);
if(i==0)
MessageBox("0","0");
if(i==-1)
MessageBox("1","1");
if(i==-2)
MessageBox("2","2");
if(i==-3)
MessageBox("3","3");
CDialog::OnLButtonDown(nFlags, point);
}
Awasthy
Any work worth doing is worth doing well.
|
|
|
|
|
Hi
I have developed a windows based service in C++ which runs on Windows 2000 Professional OS.
It is a multithreading service in which first it creates one master thread then it creates number of child thread in suspended mode. Now this child thread when resumed...gets the details needed....
For this I use Semaphore to synchronize the threads and WaiForSingleObject() functions to make it work properly.
It is like ....
---------------
if ( WaitForSingleObject(threadHandle,INFINITE) == WAIT_OBJECT_0 )
{
Do some work here.....
}
---------------
But some time it stucks waiting more time to finish so that new thread can start and continue working. So is there any other idea how can I make it run fast ?
Thankx in advance.
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Depending upon what task your 'worker' threads are performing, you can always consider LOWERING their thread priority so that your 'controller' thread has a higher priority and the controller thread will get serviced more frequently when there is a task for it to perform, such as starting more worker threads.
You also might consider creating less worker threads and using a round-robin subdivision of the tasks to be performed, assuming your implementation can afford such a redesign. If each of these threads does not necessarily have to block on something, like a file handle or other event, then perhaps all the servicing can be done from a single thread that processes data for each item in turn, each time the thread executes. If you are making too many threads, your process will spend a significant per-unit amount of time switching threads constantly instead of getting 'real' work done.
|
|
|
|
|
I want to make a tooltip which could show each item(picture)'s thumbnail on the tooltip, but just use LVN_GETINFOTIP message is not enough, as the LPNMLVGETINFOTIP only let me pass in limit string, So is there any way to draw on the List Ctrl's tooltip?
Thanks a lot! any comment is welcom
|
|
|
|
|
Hi,
Instead of creating a new MFC Active-X project, i reused an existing project. But, when both the controls are being used simultaneously, i have the issue of same class-id for both the controls. How do i change the class-id of the control?
The active-x is being rendered on a web-page. Two different controls are needed and because of the same class-id i'm not able to use them.
Please help.
Thanks and Regards
Vikram Attiganal
|
|
|
|
|
Go through all your source files and change the GUID. I haven't done AX controls in MFC in ages, so I don't know off-hand which files to look at, but at the miniumum it will be the IDL or ODL file, and the code used for registration/unregistration of the server.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
hi..
how do we save user entered text in a file.. i am using common dialog box and allowing the user to specify the file name and the location.. I used CArchive.. The first character in the saved file is always a garbage value.. Why?
regards
mpallavi
|
|
|
|
|
If you use CArchive, maybe that's normal... In fact, I never used CArchive for saving data but maybe it adds its own data before your data.
Try to use CFile instead:
char* szText = "Your string To Save";<br />
CFile* pFile = fopen("YourFile.txt","w");<br />
fwrite(szText,strlen(szText),1,pFile);<br />
fclose(pFile);
|
|
|
|
|
Hi cedric
i am giving here my code:
..........................
CFile flCPhone;
CStdioFile fl;
char strFilter[] = { "Text Files (*.txt)|*.txt|" };
CFileDialog FileDlg(FALSE, ".txt", NULL, 0, strFilter);
if( FileDlg.DoModal() == IDOK )
{
if( flCPhone.Open(FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite) == FALSE )
{ return;}
CArchive ar(&flCPhone, CArchive::store);
ar<
|
|
|
|
|
Ouch... Sorry, I have mixed CFile with FILE*
But I think your question has already been answered
|
|
|
|
|
Hi cedric
its ok..
I wasn't using the member functions of CFile..
There is no function for appending text to a file..in CFile (..I suppose)..
How do i go about it?
|
|
|
|
|
Then you can use FILE* and open it in appending mode ("-a"). Take a look at fopen in the doc:
FILE* pFile = fopen("YourFile.txt","a");<br />
fwrite(.....);
|
|
|
|
|
mpallavi wrote:
There is no function for appending text to a file..in CFile (..I suppose)..
Sure there is. Just go to the end of the file before writing to it. Remember to use CFile::modeNoTruncate when opening the file.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
hi david..
thanx
I could append text to a already existing file.. I want the newly entered text to appear on a new line.. I used CFile::seektoend().. how to take the pointer to new line? ..
regards
pal
|
|
|
|
|
Insert a CR and/or LF character first.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
try this :
FILE *file;
char *FileName = "C:\\TestFile.txt";
char *string_to_save = "this is a test";
file = fopen(FileName,"w");
if(!file)
{
AfxMessageBox("Unable to open the specified file");
return;
}
fputs(string_to_save,file);
fputs("\n",file);
fclose(file)
return;
regards,
Eli
|
|
|
|
|
hey friends ..
i did it.. it was simple
.................
CFile flCPhone;
flCPhone.Open(FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
int len;
len=strlen(m_strInput);
flCPhone.Write(m_strInput,len);
.....................
thanx for showing me the write track.. i was simply running behind CArchive..
(A beginner in vc++.. getting into it..)
thanx
pal
|
|
|
|
|
if you allow the user to choose the file name and position with File dialog,
in your flCPhone.open() use FileDlg.GetPathName() instead FileDlg.GetFileName().
regards,
Eli
|
|
|
|
|
ya fine..
thanx Eli
..
pal
|
|
|
|
|
i want get HDD serial number, and encoding it to binary number, and write this binary number into file application (example: myapplication.exe) ?
i can't completed, help me !
Regards.
|
|
|
|
|
|
mpallavi wrote:
The first character in the saved file is always a garbage value
It is the number of bytes in the CString object that were written to the archive. You should be able to verify this. Take a look at CArchive 's << operator. If the length of the CString object is >= 255 and < 0xfffe, an extra 0xff is written to the archive followed by the length of the CString object.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I am curious if thee is a form event that fires when a form gets focus after a called form is closed.
I am using a form, in VC++ .net, that calls another form to generate a text string and passes that string to a global variable. Now I want to "refresh" that calling window to load that string into a text box. "When called window closes, set text box->text = global string." or some such (I know, my techno-speak is malfunctioning. Pseudo-pseudo-code?
Thanks
Thom
--"Late to bed, Early to rise,-- -Work like hell and Advertise."- Wernher von Braun
|
|
|
|
|
I met a problem relating to use CArray in MFC.
CArray<CMyClass*,CMyClass*> m_pArr;
CMyClass is very simple
Class CMyClass
{
CString m_szName;
CString m_szId;
long m_i4Age;
}
allocate memory:
for (int i=0;i<1000;i++)
{
m_Arr.Add(new CMyClass);
}
destroy memory
for (int i = 0;i<m_Arr.GetSize();i++)
{
CMyClass*p = m_Arr[i];
if (p)
{
delete p;
p = NULL;
}
}
m_Arr.RemoveAll();
m_Arr.FreeExtra();
When I build this code in two mode: debug and release
1. In debug mode, It seems not be leaked
2. In release mode, leak!!! memory is allocates for application never
decrease although i used above code to free the memory. I don't know why there is the difference like that.
Anybody can explain me why? and give me a solution to configure in order to It can run without leak in both mode debug and release.
Thanks a lot
Tin Le,
|
|
|
|
|
I'm not familiar with CArray ( I use C++ containers ), but I don't see any problem with this. It would be easier to read your code if you checked 'Do not treat <'s as HTML tags' so it was all visiable though.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|