|
Hi Mr.Andrew,
Thanks alooooooot for your help ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
i am making a program where i need to constantly check for a change in the state of a socket, and i was wondering if there is any way to draw a dialog box so it allow me to use the OnIdle() function of the main class of my program, or if there is a similar function that is available through the CDialog class. i've tried drawing a modeless dialog, but it won't appear but for a fraction of a second. any help would be greatly appreciated.
-Aaron
|
|
|
|
|
I'm not sure if this is what you mean but if you try creating a second thread and attach a modal dialog box you should be able to create a loop that won't interupt your main application.
|
|
|
|
|
Another option is to handle the WM_KICKIDLE private MFC message, which is defined in afxpriv.h
Your handler for this message would be the equivalent of OnIdle in your main class.
Derek Lakin.
Salamander Software Ltd.
|
|
|
|
|
Hi All!
I'm writing some control in C++/MFC. It is basically ready, and now I'm working on speed it up/optimization. I found that BitBlt operation consumes significant amount of time:
/* sorry I'm writing from my home computer with no C++ installed and no sources, so there may be error in function names/parameters - not relevant to problem.
*/
CToolBtnList::OnPaint()
{ dc = CPaintDC(this); // or something like this...
CRect rect;
GetClientRect(&rect);
CDC memDC;
memDC.CreateCompatibleDC(NULL);
// this one is needed because I want first create
// image on it piece by piece and then copy it to
// PaintDC
CBitmap bitmap, *poldbitmap;
bitmap.CreateCompatibleBitmap(&memDC, etc...);
poldbitmap = memDC.SelectObject(&bitmap);
....
DrawBackground(&memDC);
....
// here I'm calling another my function:
DrawButtonsArea(&memDC);
...
...
/* place 1*/
dc.BitBlt(....., &memDC, ...., SRCCOPY); // one-to-one copy
memDC.SelectObject(poldbitmap);
memDC.DeleteDC();
bitmap.DeleteObject();
}
CToolBtnList::DrawButtonsArea(CDC* pDC)
{ /* and here I'm doing another copy: this is essential,
because I need to have possibility to cut what I've drawn by specific area without affecting other areas
*/
// repeat all the same:
CRect rect;
GetClientRect(&rect);
CDC memDC;
memDC.CreateCompatibleDC(NULL);
// this one is needed because I want first create
// image on it piece by piece and then copy it to
// PaintDC
CBitmap bitmap, *poldbitmap;
bitmap.CreateCompatibleBitmap(&memDC, etc...);
poldbitmap = memDC.SelectObject(&bitmap);
/* place 2*/
memDc.BitBlt(....., pdc, ....,SRCCOPY); // one-to-one copy
....
....
/* place 3*/
pdc.BitBlt(..., &memDC, ..., SRCCOPY); // this is cutted copy - not one-to-one
}
I'm calling Invalidate() each time when mouse moves to specific location (another "button" inside of control).
On silly test to call Invalidate() each 100ms (which is quite reasonable in my case) I found that my thread consumes 30% of processor time (which is unreasonable).
If I'll take out that 3 places (so I'm doing all other work, just don't do that copying), it goes down to 0% or 1% - even with all (~20) animated GIFs fooling around in worker thread.
Next tests showed that BitBlt operation _to_ PaintDC eats about 6% of processor time, and BitBlt operation _from_ PaintDC to memoryDC eats 15%-20% of processor time (which I can't understand: this is the same function with almost exactly same amout of data).
In archives here I found ::CopyImage function and will try it Monday at work, but I still doubt it can improve performance.
I understand that DIB processing will be faster, but I need DC functions to draw (line, ellipse, etc), so it will not work. How else can I speed this section up?
I'll try eliminate first copy to memDC (in OnPaint function), but I'm afraid it will be flickering.
Any other suggestions? How can I _directly_ copy data from one bitmap to another in memory without going to DC, and do it most efficient way without using DIBs? (something like memcpy ).
Any help will be appreciated.
Oh, by the way, I've tried GetBitmapBits and SetBitmapBits, and also I've tried bitmap<->DIB conversion (GetDIBits and SetDIBitsToDevice) - absolutely same speed
SY-
Kosta.
Kosta - wolf alone.
|
|
|
|
|
I am creating a CTreeCtrl derived class, that will act similiar to the left side of Windows Explorer. I need to do some initialization (like display the drives) as soon as possible, which is right after the window is shows. What message, or function do I need to catch/override in order to do this.
Thanks, John
|
|
|
|
|
OnInitialUpdate
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Okay, i may/maynot get flamed for this post, but I'm going to wear my aluminium pants anyway.
What is the real advantage/purpose of 32, 64, or 96+ bit integers????????? I mean, I know my computer's hardware is 16/32, but what I don't understand is why in programming we have to be aware of what bits our integers are using? Do you only need to care of device drivers?
|
|
|
|
|
In windows programming on a PC it may not be as important as in an embedded environment. It can be very important in large applications using structure with lots of integers is can be important from the point of view of memory usage. Why use 96bit intergers when you know at the time of writing the software that the largest numbers you will use will all fit into 16bits. This can mean less disk swapping and faster offset calculations and for embedeed systems, where memory can be a scarse resource, less memory usage, and possibly better performace overall.
There are other considerations but that's the one I have been confronted with mostly.
Happy programming!!
|
|
|
|
|
First of all, when using 16 bit integers on 32 bit machines compiler generates bigger __16_bit__ code (which of course executes slower than that 32 bit one).
Second of all, 16 bit integer is not faster due to smaller size. Register size is rather 32 bit.
So when writing 32 bit application, do not use short, __int16 and so on, use 32 bit integers.
|
|
|
|
|
Hello. Could anybody redirect me to a tutorial, or tell me, how to connect
to a running instance of IE? Because I want to pull back the current web page
im at (or user).
Thanks,
Caleb
|
|
|
|
|
I retrieve ERROR_SUCCESS in RegSaveKey, but file is zero lenght
What wrong I do?
|
|
|
|
|
Hello , I've got small problem ... Probably somebody can help ?
Here is a problem :
For example , I have Main.cpp ... I added Appendix.cpp and appendix.h files to my project ... I have definition of "float aaa" in .CPP and "extern float aaa" in .H file (Is it RIGHT ?) ... Also in appendix.cpp I described procedure "void Twice()" that make aaa*=aaa;
So - I CAN'T SAVE DATA INTO aaa FROM MAIN.CPP !
I CAN DO IT ONLY FROM Appendixies ...
Only I can do from main.cpp is to read 'aaa' - result of Twice()...
Probably I did something WRONG ? or I need to add something ?
Please Help !!!
P.S.
***
Appendix.CPP
---
#include "stdafx,h"
#include "appendix.h"
float aaa;
void Twice()
{
aaa=1.5;
aaa*=aaa;
}
***
Appendix.H
---
extern float aaa;
void Twice();
***
Main.CPP
---
#include "appendix.h"
!@**!@
|
|
|
|
|
I'm working on code for a real-time control system. This will sound strange but here goes. I've built classes for all the elements of the control (i.e. digital filters and related components). Each of then descends from a base class (Tsignalprocessor) which supports linking actions and data between them. I want to read a script (run time) then instantiate and configure the various components based upon the script. I also want to be able to insert/delete/reconfigure components at run time. To do this I'd like to use a dynamically allocated block of pointers (to each instantiated component). In straight C this was easy (just declare as void then cast pointer). How can I do this in C++? I understand how to get RTTI info, but how do I typecast the pointer (since I want to draw from a block of pointers and point to different classes)? Please email any answers (as well as post here) to me at BobBain@MaritimeDynamics.com
|
|
|
|
|
Ok, this is not an answer - just a 'hey what a neat problem' reply.
The only difference between C and C++ in this area is that C++ enforces typechecking on parameters passed to a function. So you can, in C, pass a void * to a method and then let that method figure out what it is (if need be).
In C++, there's probably a few workarounds - including overloads of a fn for each type that might be received, IDing the classes in the array by first casting them to the base then retrieving an ID denoting their type etc.
I get a feeling that you could somehow modify the C code to work, involving some ugly casting, but that there's probably a creation pattern that covers this.
Hmmm...
|
|
|
|
|
I split the view of my application in two parts. My problem is that the status bar and toolbar disappear after the split and I don't know why!!!
This is my code :
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CCreateContext* pContext = (CCreateContext*)lpCreateStruct->lpCreateParams;
int rc;
CRect cr;
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
GetClientRect(&cr);
CSize paneSize(cr.Width() / 2, cr.Height());
m_wndSplitter.CreateStatic(this, 1, 2);
if(!m_wndSplitter.CreateView(0, 0,
RUNTIME_CLASS(CBOFListView),
paneSize, pContext))
{
TRACE0("Failed to create Splitter Wnd\n");
return -1; // fail to create
}
if(!m_wndSplitter.CreateView(0, 1,
RUNTIME_CLASS(CBOFInfoView),
paneSize, pContext))
{
TRACE0("Failed to create Splitter Wnd\n");
return -1; // fail to create
}
return 0;
}
Best Regards!
|
|
|
|
|
Try to set
CSize paneSize(200,200);
then try to handle the OnSize message as follows:
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
CRect cr;
if ( m_initSplitters && nType != SIZE_MINIMIZED )
{
m_mainSplitter.GetClientRect( &cr );
m_mainSplitter.SetColumnInfo( 0, cr.Width() / 2, 0 );
m_mainSplitter.SetColumnInfo( 1, cr.Width() / 2, 0 );
m_mainSplitter.RecalcLayout();
}
}
m_initSplitters is a BOOL set to TRUE after the splitters have been created in the OnCreateClient-function. Use this function to create your splitters instead of the OnCreate function
regards!
|
|
|
|
|
My application "uses" tons of memory. And yes, all of it get's deallocated when program exits. What I would like to do is to find out where all allocation goes too... Application has 100's of classes.
Memory allocated by "new"
Brian
#define new new(_T(_FILE_), _T(_LINE_))
Anyone has class that agregate line above?
|
|
|
|
|
you need to use delete for every variable that you had allocated with new
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
I am not a newbie.
No I don't any leaks. I am looking for a way to optimize structures
to reduce memry overhead.
what does "delete" has to do with this?
Brian
|
|
|
|
|
Wow, that was rude.
The only thing you can do is delete the pointers as soon as you don't need them any more, but then, you take a chance on fragmenting memory.
Other than that, we really can't help you much without seeing the code and analyzing your structures.
|
|
|
|
|
OK, if I understand your question, you're saying that you don't have memory leaks, but you want to know which functions are allocating (and deleting) lots of memory, and which aren't so that you know which ones to optimise?
I'm not sure about your redefinition of new, but you could always try profiling your code, and find out how often the constructors of your various classes get called. That should give you some idea of where the most memory is being allocated. Have a look at "profiling" in MSDN for more info.
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
My program has gone psycho, and I'd really appreciate some help reducing the 115 compilation errors down to none The problem is with the VC++ generated line:
static char THIS_FILE[] = __FILE__;
that is placed in every cpp file. For some reason, this is giving me serious errors in every class!
Looks something like this:
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'THIS_FILE' : pure specifier can only be specified for functions
error C2838: illegal qualified name in member declaration
error C2059: syntax error : 'return'
error C2238: unexpected token(s) preceding ';'
error C2143: syntax error : missing ';' before '*'
error C2501: 'GetMessageMap' : missing storage-class or type specifiers
error C2556: 'int *__thiscall CTestApp::GetMessageMap(void) const' : overloaded function differs
43) : see declaration of 'GetMessageMap'
error C2373: 'GetMessageMap' : redefinition; different type modifiers
43) : see declaration of 'GetMessageMap'
error C2143: syntax error : missing ';' before 'tag::id'
error C2734: 'AFX_MSGMAP' : const object must be initialized if not extern
error C2371: 'AFX_MSGMAP' : redefinition; different basic types
p(38) : see declaration of 'AFX_MSGMAP'
fatal error C1004: unexpected end of file found
Every one of those errors points to the BEGIN_MESSAGE_MAP macro. Needless to say, this is the lamest thing ever, and I don't have a clue what caused all this craziness. Any help is much needed
thanks a ton,
Jake
|
|
|
|
|
If you have any inline functions in your header file, make sure they have a matching {} pair. If you use an ")" instead of a "}", you'll get all kinds of bizarre errors. Also, make sure the statement inside the "{}" pair ends with a semi-colon.
Lastly, if this is an abstract class, make sure you've completed the definitions inside the class header.
If you're deriving forom an abstract class, the pure virtual functions have to be prototyped AND have a body.
|
|
|
|
|
Sweet Jesus it actually worked! I had a non-inline function without the semicolon, and the compiler wasn't happy. Thanks a ton!
Jake
|
|
|
|
|