|
Remove the static keyword from all of your variable declarations and try again.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I did it but no difference.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Hosam Aly Mahmoud wrote:
FloodFill ( memDC, 20, 20, RGB(255,0,0) ); // red background
I should have seen this before...
The colour you pass to FloodFill() is not the colour of the fill. It's the colour of the border. FloodFill() fills the area with the currently selected brush. To fill a rectangle with a given colour, either create a solid brush (CreateSolidBrush() ) and use Rectangle() , or use the ExtTextOut() function to draw opaque text without actually drawing text:
SetBkColor(memDC, RGB(255,0,0));
RECT rect;
ExtTextOut(memDC, 0, 0, ETO_OPAQUE, rect, NULL, 0, NULL); Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thank you very much! That really helped!
Now I am wondering, if I want to make the background an image, should I do it in response to WM_PAINT too? Why is WM_ERASEBKGND available then? Why did they put it if I should draw in WM_PAINT?
Thank you very much for your patience!
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Hosam Aly Mahmoud wrote:
Now I am wondering, if I want to make the background an image, should I do it in response to WM_PAINT too?
Yes. That will work fine
Hosam Aly Mahmoud wrote:
Why is WM_ERASEBKGND available then? Why did they put it if I should draw in WM_PAINT?
There is nothing wrong with using WM_ERASEBKGND for drawing the background. It's simply not possible to do flicker-free drawing using it. I'm not certain why it's there - it's probably been there since Windows 1.0
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
I'm not certain why it's there
Well, if you "eat" the WM_ERASEBKGND message, return 1, and forward it to the parent window, you can get transparent effects, because you're telling the parent to erase an area, rather than erasing it yourself with the default brush, which is the normal behavior.
This is a neat trick that is played by the Common Controls Toolbar so that it can have a transparent background. It also calls WM_ERASEBACKGND on the parent window whenever it draws anything outside of a WM_PAINT message, so that the background is always erased to the parent's background.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'll have to remember that
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thank you for the information!
Hosam Aly Mahmoud
|
|
|
|
|
Thank you for your replies, your help and all your patience!
Hosam Aly Mahmoud
|
|
|
|
|
Hi,
I've written a program and when I run it for the first time it works, but when I want to run it for the second time, it crashes. Most of the time at a "delete [] ..." or at a "new char[...]". But when I debug it works fine.
The program uses a MySQL database (through MySQL++). Somewhere in the code is a "for()" part (it retrieves the records of a SQL-statement and does something with the values). When I debug it, it only goes one through the loop (retrieves one record), when I compile an optimized exe then it retrieves all the records.
I think this is very weird, does anybody knows the cause of the problem or has a sollution?
Thanks in advance
|
|
|
|
|
Sounds like an uninitialized variable somewhere.
- Mike
|
|
|
|
|
I see what you mean but how can something like this crash on "new ..."?
char* cNewString = NULL;
// cString is not empty
cNewString = new char[strlen(cString) + 1];
-Tom
|
|
|
|
|
Visual C++ is not perfect in reporting the cause of a crash and where the bug resides. One possible cause of delete [] is that the program passes the dynamically allocated array into a function that does not release the memory even after the function has returned.
Kuphryn
|
|
|
|
|
Probably a newbie question but I really want to ask, I have like hundreds of jpg's, gif's and icons need to be shared by multiple application, I heard we can encapsulate all of them into a dll and use that dll to export resource ID's when required by application, but how? Could someone please tell me:
1, what kind of dll I will need to create? Win32 dll? MFC dll? Or others?
2, How do I export resource ID's from a dll?
Thanks a lot.
|
|
|
|
|
putting hundreds of jpgs in a dll is a very bad idea, because it will waste your memory... you won't need them all the same time!
create a folder, put them in there, then create a new dll with 2 exported function: LoadJpg and FreeJpg!
LoadJpg allocates memory and loads the file from disk, FreeJpg frees the memory allocated by LoadJpg!
This is the best way!
Don't try it, just do it!
|
|
|
|
|
Yeah I thought so, but I was just doing some practice, thanks for the suggestion though...
Anyway, I think I have found out the solution already, I created a DLL and included images into that DLL as its resources, then in my executable I read images("resource blocks") from the DLL into my executable process's memory blocks when needed, then draw them on my executable's windows, tested and worked.
|
|
|
|
|
use a normal win32 dll and include the resources there!
then load this dll via LoadLibrary!
now, you can open a bitmap for example by calling LoadBitmap with hInstance of the loaded dll!
Don't try it, just do it!
|
|
|
|
|
I am trying to create an application that is capable of working with multiple document types, each having its own view. In the InitInstance() function I have done the following:
BOOL CTestApp::InitInstance()
{
... Other code
LoadStdProfileSettings(15); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(IDR_FIRSTTYPE,
RUNTIME_CLASS(CTypeOneDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTypeOneView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
CMultiDocTemplate* pDocTemplateT;
pDocTemplateT = new CMultiDocTemplate(IDR_SECTYPE,
RUNTIME_CLASS(CTypeTwoDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTypeTwoView));
if (!pDocTemplateT)
return FALSE;
AddDocTemplate(pDocTemplateT);
... Other code
I have all appropriate view and document classes in place for these doc templates and the project compiles without any problems. The first doc view is derived from CHTMLView and the second is derived from CRichEditView.
PROBLEM:
I create a new rich edit document, type some text into the view, and save it and then close the document. Then when I open the document I just saved, it appears that the document's contents had never been saved, or if they had, they certainly didn't open properly.
ALSO:
The messagebox that usually automatically pops up when you try to close a doc that has not been saved since its last modification fails to come up like it should.
I believe that these two problems are somehow related. Please help.
This has really got me stuck. Does anyone have any suggestions? Any leads to the problem would definitely be appreciated.
BNEACETP
|
|
|
|
|
|
Thanks for letting me know about the book.
I just ordered it earlier today.
BNEACETP
|
|
|
|
|
I was wondering if it were at all possible to derive a class template from another class template and keep the base class templates arguments abstract. I have looked around and cannot find the answer.
|
|
|
|
|
Mike Roode wrote:
I was wondering if it were at all possible to derive a class template from another class template
template<class T>
class Base
{
};
template<class T>
class Derived : public Base<T>
{
};
Is this what you meant? You can add any additional template parameters required in derived.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
That is what I was looking for. Thanks for the syntax Andrew.
|
|
|
|
|
Hi everyone. Again I have some questions, actually a problem with using the MFC class CRecordset. I have implemented a class which will manipulate a database (Oracle 9i). When I try to add a new employee (Employee is the object that carries the data) I get the following error:
---------------------------------------------------------------------------------------
Runtime error:
The application has requested the Runtime to terminate it in an unusual way.
I have this error only with the specific method. The other operations (update, select, delete on the same table work fine).
Does anyone know what is causing it?
bool Service::AddNew(Employee e){
long id;
EmployeeRecordset records(db);
//Begin transaction
db->BeginTrans();
//open the recordset only for adding records mode
try{
if ((records.Open(CRecordset::dynaset,NULL,CRecordset::appendOnly))!=0){
//if recordset is updateable add new record
if (records.CanAppend()){
//find the last YP_ID
records.MoveLast();
id = records.m_YP_ID + 1;
records.AddNew();
records.SetFieldNull( NULL );
//copy new values
//this where I copy the new values to the recordset
//here is where I have the error
if (records.Update()){
//end transaction
db->CommitTrans();
records.Close();
return (true);
}//end if
}//end if
}//end if
}//end of try
catch (CDBException cdbe){
db->Rollback();
records.Close();
return (false);
}//end of catch
catch (CMemoryException cme){
db->Rollback();
records.Close();
return (false);
}//end of catch
cout << "end of addnew" << endl;
db->Rollback();
records.Close();
return(false);
}//end of AddNew
|
|
|
|
|
I'm making a server that should be able to handle multiple connections at once. I use WSABUF, WSASend and WSAReceive in my code but when i try to compile i get the error that they are undefined, even though i am sure winsock 2 is included because i have explicitly included winsock2.h but also have defined _WIN32_WINNT as 0x400. So does anyone know why it is giving me the errors? do i need to include something else as well?
And another question, i am making a server that will be handling upto about a maximum of 200 clients. I've looked into some ways to do it and as i see it there are two ways: A simple multi-threaded server, or to use Input Output Completion Ports. I was told the latter was faster and more stable but i was wondering, where do u draw the line to go from a simple multi-threaded server to a IOCP server?
Many thanks in advance.
Kuniva
--------------------------------------------
|
|
|
|