|
Dear all,
This problem of mine has been bugging me crazy.
I have to load a 24bit .bmp file and convert it to a 32 bit bmp file.
I've manage to load the bitmap file, display it on the screen and even made the code to make it a 32bit bitmap.
The problem is to attach the modified bits to the m_bmpBitmap CBitmap object. Then I get the info of the m_bmpBitmap with the BITMAP structure.
BITMAP bm;
m_bmpBitmap.GetBitmap(&bm);
The bm.bmBits is 0x0 which it shouldn't be.
All the CreateBitmap() and GetBitmap() funtions return successful but I can't even display the image to screen and I feel it is due to bm.bmBits = 0x0.
I've even tried to create a 24 bit bitmap with the same method below and it didn't work too.
I would like to be able to view the image that I created and as well as to be able to save it. I welcome any new ideas on how to approach this matter.
Many many thanks.
Chun Te, Ewe
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
CBitmap m_bmpBitmapOri;
CBitmap m_bmpBitmap;
BYTE *m_pOriSrc, *m_pSrc;
HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), "h:\\logo.bmp"
,IMAGE_BITMAP, 0, 0, R_LOADFROMFILE | LR_CREATEDIBSECTION);
m_bmpBitmapOri.Attach(hBitmap);
BITMAP bmOri;
m_bmpBitmapOri.GetBitmap(&bmOri); // Get the loaded bitmap
m_pOriSrc = (BYTE*)bmOri.bmBits; // Pointer to the original bitmap bits
// Prepare a new location
if(m_pSrc!=NULL) delete [] m_pSrc;
m_pSrc = new BYTE[(bmOri.bmHeight+1)*bmOri.bmWidth*4];
...
some code to change from 24bpps to 32 bpps (if needed I can provide)
...
if (m_bImageValid) m_bmpBitmap.DeleteObject();
// Creating the image
m_bmpBitmap.CreateBitmap( bmOri.bmWidth, bmOri.bmHeight, 1, 32, m_pSrc );
BITMAP bm; // Obtain info regarding bitmap
m_bmpBitmap.GetBitmap(&bm); //
// Create a device contect to load the bitmap into
CDC dcMem;
CClientDC pDC(this);
dcMem.CreateCompatibleDC(&pDC);
dcMem.SelectObject(m_bmpBitmap);
pDC.BitBlt(250, 7, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
// Won't display image
|
|
|
|
|
I want to scroll to the last line of my edit box. Is there a simple way to do this? Thanks
-Ken Mazaika
|
|
|
|
|
I tried this...is there a reason it didn't work?
class CMsgBox : public CEdit<br />
{<br />
protected:<br />
LESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);<br />
};<br />
<br />
<br />
and in the module:
#include "headerFile.h"<br />
<br />
LRESULT CMsgBox::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)<br />
{<br />
LRESULT result = CEdit::DefWindowProc(message, wParam, lParam);<br />
if (message == WM_SETTEXT)<br />
SendMessage(EM_SCROLL, SB_BOTTOM, 0);<br />
return result;<br />
}<br />
Is there something I'm going wrong? Thanks.
-Ken Mazaika
|
|
|
|
|
My release build works but the debug build crashes at at the delete. It says its a memory check error. The release version sails on through. Actually the debug version will keep going after the crash(retry) then crash again, and retry restores it. So the logic is working but I'm doing something really wrong.
memory check error at 0x002F59AA = 0x00, should be 0xFD.
Any ideas?
Thanks,
ns
char* photo1;
photo1 = new char [strlen(pDoc->m_db.m_photoInfo)];
strcpy(photo1,pDoc->m_db.m_photoInfo);
char* pDelimiter = strstr (photo1, ",");
ASSERT (pDelimiter != NULL);
*pDelimiter = '\0';
char* dbname = photo1;
m_PhotoDBName = dbname;
pDelimiter++;
CString mineName = pDelimiter;
<code> delete[] photo1</code>;
When I hit debug, it gave the error (user breakpoint called from code at (some address).
It went into dbgheap.c. Does this help in diagnosing the problem?
|
|
|
|
|
You need to allocate room for the terminating NULL
photo1 = new char [strlen(pDoc->m_db.m_photoInfo) + 1];
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Well, that took care of one of them! The next crash is again at a delete[] (I just started using delete!) It turns out to be a variable I dont need, but still want to know whats wrong:
m_pCommandPhoto->ActiveConnection = m_pConn1;
CString partQuery = "'"+MineName+"'";
char* partQuery0 = new char(partQuery.GetLength()+1);
strcpy(partQuery0,partQuery);
CString SQLQ = "SELECT * FROM tblMine WHERE (DefID = "+partQuery+")";
char* SQLQuery = new char [SQLQ.GetLength()+1];
strcpy(SQLQuery, SQLQ);
AfxMessageBox(SQLQuery);
<code>delete[] partQuery0;</</code>pre>
Thanks,
ns
|
|
|
|
|
You've used () in the new statement, which makes the length a parameter that is passed to the char constructor. This means that your newing with the non-[] form so delete [] fails
change it to
char* partQuery0 = new char[partQuery.GetLength()+1];
Roger Allen
Sonork 100.10016
I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.
|
|
|
|
|
Thanks so much. So a new done my other way with () is legal? I didnt think we could do that. I appreciate your help,
Thanks,
ns
Incidentally the release version was perfectly happy with it!!! Would this have shown up later as a problem in the release?
|
|
|
|
|
ns wrote:
So a new done my other way with () is legal?
Yes, although it means an entirely different thing. This allocates one char and initializes it:
char* pch = new char ('a'); Since chars and ints are interchangeable to a degree, you can stick a number less than 255 in place of 'a' above.
--Mike--
Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Great! Thanks for the explanation. Appreciate it!
ns.
Wonder why the release exe didnt crash.
|
|
|
|
|
One bit of advice: why on Earth are you bugging yourself with new/delete when you're already using CString? Instead of new/strcpy just declare a CString and assign your text.
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
Hi!
I have a dialog based app. I have a bunch of child dialog in my main dialog which I keep showing and hiding based on a few user actions. I need to know when these child dialogs loose focus. I tried WM_KILLFOCUS, WM_ACTIVEATE, but for some reason neither of these messages get sent to my child dialog or even my main dialog for that matter. Does anybody have any suggestions on how I could fix this or maybe get around it?
Thanks,
NC
|
|
|
|
|
How are you showing your child dialogs? Are you using DoModal() (modal dialogs) or Create() with ShowWindow() (modeless dialogs)?
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Hi!
I am doing a create() and ShowWindow(). They are modeless dialogs.
Thanks
NC
|
|
|
|
|
WM_ACTIVATE is the message you want to handle. It is sent to the window being activated, then to the window being deactivated.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Hi!
I tried WM_ACTIVATE too. But for some reason, that doesn't get sent when activating the dialog or even when deactivating the dialog.
One more quick question regarding this - if the focus is on one of the controls on the dialog and if the focus is moved to another dialog altogether, will the original dialog which looses the focus still get the WM_ACTIVATE msg even though the focus was on one of the controls and not really on dialg. I am thinking that this is what is happening in my case since I am not getting the msg.
Thanks,
NC
|
|
|
|
|
I mean, an easy way, like:
<br />
bool isConnected = IsConnected(mySocket);<br />
Or maybe with the select() function?
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Hello, the codegurus around the world.;)
At CAsynSocket, OnConnect member function will return the error code
called "WSAEISCONN The socket is already connected".
So, you can call Connection function by some interval time, and
check if OnConnect will return this error code.
Please, don't send me your email about your questions directly.
Have a nice day!
Sonork - 100.10571:vcdeveloper
-Masaaki Onishi-
|
|
|
|
|
Hi
I started 2 processes in my app. and now every one second i want to see if these processes are still running. Coud anyone please tell me how i can get the status of a process to see whether it is running or has been terminated?
thanks
|
|
|
|
|
tcuong wrote:
now every one second i want to see if these processes are still running
Why 'every one second'? Can't you create a thread which waits for process termination with WaitForSingleObject, then posts a message?
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
this is to monitor if the processes are running or not? It is just an excercise to get myselft familiar with Win32 programming.
First i create 5 process namely notepad.exe . Then i have to monitor that how many of these processes are running every 1 second. I've attempted many ways to do it but i failed. This is how i did it.
<br />
void main()<br />
{<br />
STARTUPINFO startUpInfo[5];<br />
PROCESS_INFORMATION proInfo[5];<br />
BOOL success;<br />
HANDLE proHandle[5];<br />
INT i;<br />
INT runningProcess = 5;<br />
CHAR appName[100];<br />
<br />
<br />
<br />
<br />
strcpy(appName, "c:\\windows\\notepad.exe");<br />
<br />
<br />
<br />
<br />
for(i = 0; i <5; i++)<br />
GetStartupInfo(&startUpInfo[i]);<br />
<br />
<br />
for(i = 0; i < 5; i++)<br />
{<br />
success = CreateProcess(appName, 0, 0, 0, FALSE, 0, 0,0,&startUpInfo[i], &proInfo[i]);<br />
<br />
if(!success)<br />
cout <<" Error creating process: "<< GetLastError() <<endl;<br />
<br />
cout << "The process ID is " << proInfo[i].dwProcessId << endl;<br />
}<br />
<br />
for(i = 0; i <5; i++)<br />
{<br />
proHandle[i] = proInfo[i].hProcess;<br />
}<br />
<br />
while (WaitForMultipleObjects(5, proHandle, TRUE, 1000) == WAIT_TIMEOUT)<br />
{<br />
for(i = 0; i < 5; i++)<br />
{<br />
if(proInfo[i].hProcess == NULL)<br />
runningProcess--;<br />
<br />
}<br />
<br />
<br />
printf(" %d ", runningProcess); <br />
I know that this code may look silly to some of you but instead of laughing, please guide me to the right direction. Thanks
|
|
|
|
|
tcuong wrote:
instead of laughing, please guide me to the right direction.
Nobody laughs at you. Seriously.
If you insist on using WaitForMultipleObjects:
- proInfo[i] will not be set to NULL when process terminates
- setting 3rd argument to TRUE causes WaitForMultipleObjects to exit only if timeout occured or *all* processes have terminated. This is obviously not what you're looking for.
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
tcuong wrote:
while (WaitForMultipleObjects(5, proHandle, TRUE, 1000) == WAIT_TIMEOUT)
{
for(i = 0; i < 5; i++)
{
if(proInfo[i].hProcess == NULL)
runningProcess--;
}
printf(" %d ", runningProcess);
}
This code looks neither silly nor anybody wants to laugh on you, really!
First I thought the problem is the TRUE parameter for bWaitAll in your call to WaitForMultipleObjects(), (which is a common mistake) but then I realized that you want to loop until all handles reached signaled state (a process or thread handle becomes signaled if it terminates). Quite clever!
Your problem is, that a signaled handle is not set to NULL, it is still present. Therfore your process counter is never decremented. If you change the line
if(proInfo[i].hProcess == NULL)
runningProcess--;
to
if( WaitForSingleObject( proInfo[i].hProcess, 0 ) == WAIT_OBJECT_0 )
runningProcess--;
it should work. (Note that I just wrote the above from scratch and did not test it )
However, your description intents that you want to check the status exactly every 1 second. The above checks it at least every 1 second. This is because the WaitForMultipleObjects() returns if either a handle becomes signaled or the timeout elapsed. Of course, this is a negligible detail in almost any case, but hey, you wrote you want to learn how to solve it with Win32 API
One idea is to use Sleep() instead of WaitForMultipleObjects():
while ( runningProcess > 0)
{
for(i = 0; i < 5; i++)
{
if( WaitForSingleObject( proInfo[i].hProcess, 0 ) == WAIT_OBJECT_0 )
runningProcess--;
}
printf(" %d ", runningProcess);
Sleep( 1000 );
}
BTW: If you bracket your code postings to the forum with <pre> and </pre> tags, the formatting will survive. This would makes it much more comfortable to read it.
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Daniel! This is a big help! I really appreciate it! Thank you very much!
Best Regard
|
|
|
|
|
Hi Daniel! I've got it. I just post it up here to let you know that with your help. FULL credit to you!!!
BOOL flag[5];
for(i = 0; i < 5; i++)
flag[i] = true;
while (WaitForMultipleObjects(5, proHandle, TRUE, 1000) == WAIT_TIMEOUT)
{
if( WaitForSingleObject( proInfo[0].hProcess, 0 ) == WAIT_OBJECT_0 && flag[0] == true)
{
runningProcess--;
flag[0] = false;
}
if( WaitForSingleObject( proInfo[1].hProcess, 0 ) == WAIT_OBJECT_0 && flag[1] == true)
{
runningProcess--;
flag[1] = false;
}
if( WaitForSingleObject( proInfo[2].hProcess, 0 ) == WAIT_OBJECT_0 && flag[2] == true)
{
runningProcess--;
flag[2] = false;
}
if( WaitForSingleObject( proInfo[3].hProcess, 0 ) == WAIT_OBJECT_0 && flag[3] == true)
{
runningProcess--;
flag[3] = false;
}
if( WaitForSingleObject( proInfo[4].hProcess, 0 ) == WAIT_OBJECT_0 && flag[4] == true)
{
runningProcess--;
flag[4] = false;
}
printf(" %d ", runningProcess);
}
This might look lengthy and messy for a moment but i think i can tight it in a loop!! Thanks!!!!
Also thanks to Tomasz !! I greatly appreciate it!!!
|
|
|
|
|