|
As shown below, there are a few functions in CButton, but i want to change its behaviour by dealing with
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) . Yes, just this one and only one functon. It would generate more code than expected if I derive a class from CButton. I wonder if it possible to process this function without Subclass, and not use derivation. If so, how?
Remarks: I must use MFC, it's so hard to use pure Win32 API.
class CButton : public CWnd
{
DECLARE_DYNAMIC(CButton)
public:
CButton();
virtual BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID);
UINT GetState() const;
void SetState(BOOL bHighlight);
int GetCheck() const;
void SetCheck(int nCheck);
UINT GetButtonStyle() const;
void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE);
HICON SetIcon(HICON hIcon);
HICON GetIcon() const;
HBITMAP SetBitmap(HBITMAP hBitmap);
HBITMAP GetBitmap() const;
HCURSOR SetCursor(HCURSOR hCursor);
HCURSOR GetCursor();
#if (_WIN32_WINNT >= 0x501)
AFX_ANSI_DEPRECATED BOOL GetIdealSize(_Out_ LPSIZE psize) const;
AFX_ANSI_DEPRECATED BOOL SetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist);
AFX_ANSI_DEPRECATED BOOL GetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist) const;
AFX_ANSI_DEPRECATED BOOL SetTextMargin(_In_ LPRECT pmargin);
AFX_ANSI_DEPRECATED BOOL GetTextMargin(_Out_ LPRECT pmargin) const;
#endif // (_WIN32_WINNT >= 0x501)
#if ( _WIN32_WINNT >= 0x0600 ) && defined(UNICODE)
CString GetNote() const;
_Check_return_ BOOL GetNote(_Out_z_cap_(*pcchNote) LPTSTR lpszNote, _Inout_ UINT* pcchNote) const;
BOOL SetNote(_In_z_ LPCTSTR lpszNote);
UINT GetNoteLength() const;
BOOL GetSplitInfo(_Out_ PBUTTON_SPLITINFO pInfo) const;
BOOL SetSplitInfo(_In_ PBUTTON_SPLITINFO pInfo);
UINT GetSplitStyle() const;
BOOL SetSplitStyle(_In_ UINT nStyle);
BOOL GetSplitSize(_Out_ LPSIZE pSize) const;
BOOL SetSplitSize(_In_ LPSIZE pSize);
CImageList* GetSplitImageList() const;
BOOL SetSplitImageList(_In_ CImageList* pSplitImageList);
TCHAR GetSplitGlyph() const;
BOOL SetSplitGlyph(_In_ TCHAR chGlyph);
BOOL SetDropDownState(_In_ BOOL fDropDown);
HICON SetShield(_In_ BOOL fElevationRequired);
#endif // ( _WIN32_WINNT >= 0x600 ) && defined(UNICODE)
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
public:
virtual ~CButton();
protected:
virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
};
|
|
|
|
|
|
|
Falconapollo wrote: how about Hook? What does that have to do with drawing a CButton ? Hooks are system wide so you would need to capture every drawing message and then decide whether it was for your control or not. That's like using a big hammer to crack a small nut.
|
|
|
|
|
Inheritance is the natural way for doing that. Any other way (if feasible) would be contrived.
Veni, vidi, vici.
|
|
|
|
|
|
Hi.
A friend of mine wrote this crazy function in VB and i have translated it to C++ in hopes that we could get a bit better performance. I guess the performance might be a bit better but it is still an enourmous amount of loops to go through.
Do you have any suggestions on how to optimize this loop or perhaps replace it completely to be able to finish all iterations in a managable time? Is it hard to have it run on the GPU and would that improve anything?
//
Parre
int CountTheOffsetValids() {
int c0;
int c1;
int c2;
int c3;
int c4;
int c5;
int c6;
int c7;
int c8;
int c9;
int c10;
int c11;
int c12;
int c13;
int c14;
int c15;
int c16;
int c17;
int c18;
int c19;
int llim [20] = {1, 2, 5, 8, 11, 14, 17, 21, 24, 28, 31, 35, 38, 42, 45, 50, 53, 58, 61, 66};
int hlim [20] = {6, 10, 14, 19, 22, 26, 29, 34, 37, 41, 44, 48, 51, 54, 57, 61, 63, 67, 69, 70};
for (c0 = llim[0]; c0 <= hlim[0]; ++c0) {
arrVals[0] = c0;
for (c1 = llim[0]; c1 <= hlim[1]; ++c1) {
arrVals[1] = c1;
if (c1 > c0) {
for (c2 = llim[2]; c2 <= hlim[2]; ++c2) {
arrVals[2] = c2;
if (c2 > c1) {
for (c3 = llim[3]; c3 <= hlim[3]; ++c3) {
arrVals[3] = c3;
if (c3 > c2) {
for (c4 = llim[4]; c4 <= hlim[4]; ++c4) {
arrVals[4] = c4;
if (c4 > c3) {
for (c5 = llim[5]; c5 <= hlim[5]; ++c5) {
arrVals[5] = c5;
if (c5 > c4) {
for (c6 = llim[6]; c6 <= hlim[6]; ++c6) {
arrVals[6] = c6;
if (c6 > c5) {
for (c7 = llim[7]; c7 <= hlim[7]; c7) {
arrVals[7] = c7;
if (c7 > c6) {
for (c8 = llim[8]; c8 <= hlim[8]; ++c8) {
arrVals[8] = c8;
if (c8 > c7) {
for (c9 = llim[9]; c9 <= hlim[9]; ++c9) {
arrVals[9] = c9;
if (c9 > c8) {
for (c10 = llim[10]; c10 <= hlim[10]; ++c10) {
arrVals[10] = c10;
if (c10 > c9) {
for (c11 = llim[10]; c11 <= hlim[11]; ++c11) {
arrVals[11] = c11;
if (c11 > c10) {
for (c12 = llim[12]; c12 <= hlim[12]; ++c12) {
arrVals[12] = c12;
if (c12 > c11) {
for (c13 = llim[13]; c13 <= hlim[13]; ++c13) {
arrVals[13] = c13;
if (c13 > c12) {
for (c14 = llim[14]; c14 <= hlim[14]; ++c14) {
arrVals[14] = c14;
if (c14 > c13) {
for (c15 = llim[15]; c15 <= hlim[15]; ++c15) {
arrVals[15] = c15;
if (c15 > c14) {
for (c16 = llim[16]; c16 <= hlim[16]; ++c16) {
arrVals[16] = c16;
if (c16 > c15) {
for (c17 = llim[17]; c17 <= hlim[17]; ++c17) {
arrVals[17] = c17;
if (c17 > c16) {
for (c18 = llim[18]; c18 <= hlim[18]; ++c18) {
arrVals[18] = c18;
if (c18 > c17) {
for (c19 = llim[19]; c19 <= hlim[19]; ++c19) {
arrVals[19] = c19;
if (c19 > c18) {
std::cout << loopCounter << "lines processed." << std::endl;
loopCounter++;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return isv;
}
modified 2-Mar-14 20:57pm.
|
|
|
|
|
The C++ standard template library (STL) comes with a lot of algorithms optimized for performance.
So if you can tell me what the above code is trying to do, maybe I could suggest an STL algorithm that does the same.
Not sure if the GPU will be able to do this, because I see a lot of data dependencies between the loop variables.
AFAIK, GPU programming needs the loop variables to be independent of each other.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
Hi and thanks for the answer.
The code above is trying every combination of values 1-70 and is supposed to output them to an array of 20 values.
Example output each iteration: arrVals[] = {3, 6, 12, 15, 22, 26, 29, 34, 37, 41, 44, 48, 51, 54, 57, 61, 63, 67, 69, 70};
Each position in the array has limitations to how big or small they can be as follows:
int llim [20] = {1, 2, 5, 8, 11, 14, 17, 21, 24, 28, 31, 35, 38, 42, 45, 50, 53, 58, 61, 66};
int hlim [20] = {6, 10, 14, 19, 22, 26, 29, 34, 37, 41, 44, 48, 51, 54, 57, 61, 63, 67, 69, 70};
The array arrVals is sent to another function each iteration to decide if the current row of 20 is usable or not.
I hope this is clear enough, please ask if not.
|
|
|
|
|
|
I think the std::next_permutation would be perfect tough i need conditions for it so that it doesn't try to find every permutation for all 70^70, which would take forever.
I'm actually not sure if it will be fast enough even with conditions.
I'm obviously not good enough with C++ to manage this :p
|
|
|
|
|
I have added (to the working library) GUID for CLSID_IMGSinkFilter to uuids.h header using this :
// 1d4d3676-96ef-4cd7-a3d7-07fac0d0c585
OUR_GUID_ENTRY(CLSID_IMGSinkFilter,
0x1d4d3676, 0x96ef, 0x4cd7, 0xa3, 0xd7, 0x07, 0xfa, 0xc0, 0xd0, 0xc5, 0x85)
This GUID will be used in static library.
The library compiles and builds, by itself.
The main application complies but it fails to link to the GUID with following error:
VidCapLib.lib(_Graph.obj) : error LNK2001: unresolved external symbol _CLSID_IMGSinkFilter
Debug/TCC_MDI.exe : fatal error LNK1120: 1 unresolved externals
So the VidCapLib.lib is not complete.
What did I missed?
Any help as always will be appreciated.
Cheers
Vaclav
|
|
|
|
|
In the header file you write this code -
#include <guiddef.h>
DEFINE_GUID(CLSID_IMGSinkFilter, 0x1d4d3676, 0x96ef, 0x4cd7, 0xa3, 0xd7, 0x07, 0xfa, 0xc0, 0xd0, 0xc5, 0x85);
In the source file where you're using CLSID_IMGSinkFilter , include the initguid.h header file.
This step is not needed for newer compilers.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
Thanks, works as advertized!
Now I need to get rid of some DirectShow multiple defintions, no problem.
BTW what class(es) did you take to have this much knowledge?
Or are you just a old as I am, but much smarter?
Thanks again and if you ever in Houston, I owe you a beer.
Vaclav
|
|
|
|
|
Spoke too soon.
My attempt to stop multiple defintions run into a snag.
I added a "standard" #ifndef / #define flag/ switch to uuids.h - the one I have modified.
I make sure I use that one.
The "problem" is with plain / non modified DirectShow BaseClasses WXDebug.cpp file.
It compiler get wild in this macro :
/* Stuff for printing out our GUID names */
GUID_STRING_ENTRY g_GuidNames[] = {
#define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
{ #name, { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } },
#include <uuids.h>
};
D:\00\0 SDK\DIrectShow 8.1 SDK\samples\Multimedia\DirectShow\BaseClasses\wxdebug.cpp(936) : error C2059: syntax error : '}'
D:\00\0 SDK\DIrectShow 8.1 SDK\samples\Multimedia\DirectShow\BaseClasses\wxdebug.cpp(936) : error C2143: syntax error : missing ';' before '}'
D:\00\0 SDK\DIrectShow 8.1 SDK\samples\Multimedia\DirectShow\BaseClasses\wxdebug.cpp(936) : error C2143: syntax error : missing ';' before '}'
D:\00\0 SDK\DIrectShow 8.1 SDK\samples\Multimedia\DirectShow\BaseClasses\wxdebug.cpp(939) : error C2070: illegal sizeof operand
Error executing cl.exe.
Apparently the #include <uuids.h> header is no longer OK in the GUID_STRING_ENTRY macro.
I have no clue how to modify this macro and keep the DirectShow debug happy.
Not realy sure if I need the debug, so I may just skip it from compiling if things don't fall apart more.
|
|
|
|
|
Didn't take too many classes in programming.
Mostly self learnt, like most of the people here.
It's probably 16 years of doing the same thing that's helping.
I also retain all the test code that I ever wrote with proper book keeping.
So that becomes the perfect reference material.
Was in Dallas for a couple of days last month.
Never been to Houston except during transit a couple of times.
Will ping you the next time I'm around and get that beer.
If you're coming to India any time, please get in touch.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
HI all
I'm trying to implement a software that create backup files. The backup are created until a maximum of backup files defined, in my case are 10 files.
After that I get the oldest backup file and overwrite. But I have somes question about what use, I tried use Circular buffer but I don't know how to use for files.
Anybody can help me.
Thank you.
|
|
|
|
|
Your circular buffer may contain, for instance the file names, e.g.
fname[0]
fname[1]
...
fname[9]
With a next variable holding next item in the circular buffer. For instance, if next == 4 then the file having fname[4] (if any) is deleted and fname[4] is assigned with the name of a newly created file. Then next is incremented (and set to zero if greater than 9 ).
Hope it makes sense.
Veni, vidi, vici.
|
|
|
|
|
Hello there,
I have a MFC app developed in VS 2012. Inside couple of worker threads it's constantly doing bunch of things.
Now if i start the app and then open the Task Manager and look at the Physical Memory for my app, it's constantly incriminating until i close the app.
I didn't try to run the app for more than an hour yet, as i am not sure whether that will screw up other app's in the system.
What does this increase in Physical Memory mean? Is this a problem?
If yes, how can i fix that?
Thanks in advance.
|
|
|
|
|
Did you look at the Output window to see if there are memory leaks as I had suggested?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes, i don't see any memory leak messages in the Output window.
|
|
|
|
|
OK, I have another suggestion. You might want to check if the program is leaking handles.
In Task Manager, select the "Handles" column to be displayed for all processes. Watch the number to see if it increases without limit. If so, then you'll have to see where you are allocating Windows handles and not closing them with CloseHandle() .
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Don Guy wrote: I didn't try to run the app for more than an hour yet, as i am not sure whether that will screw up other app's in the system. What does this increase in Physical Memory mean? Is this a problem? If yes, how can i fix that? See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hello all, this is my first post, so I'll start off by saying that I began programming about a month and a half ago, and being a "math person" it was mostly intuitive to me. So I would classify myslef somewhere in-between beginner and average.
Anyway, My English teacher brought up a "Game" where you pick two words. And using dictionary definitions of one word, you have to pick a word in the definition, go to it, find its definition, and so on and so forth until you finally reach the second word you picked.
For example: Pick the words Finesse and Aggregate
Using Dictionary.com (Just using the most convenient resource) the definition of Finesse is Extreme delicacy or subtlety in action, performance, skill, discrimination, taste.
So I go to extreme, and it is defined as Of a character or kind farthest removed from the ordinary or average: extreme measures.
So I go to Character, which is defined as The aggregate of features and traits that form the individual nature of some person or thing.
And Thus I have reached Aggregate!
My point in all this is that I would like to write a program do be able to play the game.
This could often take a long time, but I hope you see the point of the "program in my head." The goal of the program would be to find and display the shortest possible path from one word to another.
My problem is that I HAVE NO IDEA HOW TO START THIS HELP. Or at least that's how I feel. If anyone can help me in the slightest, it would be great! Also I feel the program would be simpler if It were written using synonyms and a thesaurus, and if you think there is a better programming language to write this in, feel free to suggest it!
Thanks in advance!
|
|
|
|
|
I'd break it down into units/chunks of work, each unit/chunk exploring one small aspect
your first one may be to be able to use a html query to a website like http://dictionary-api.cambridge.org/index.php/help/resources#c#[^] to get a definition for a word and display it - could be console or forms based
Once you know how the data comes back, you then have to be able to parse/render it into a form you can use for matching - and possibly store it in memory
btw, I showed the c# api for that dictionary - 'better programming language' ? I don't know - there's this big thing about abstraction and using the right language/tool for the job - sometimes like this dictionary api, you may not find an api for your language - that doesn't stop you from having a mixed component approach - I think c# would also be ok for this project - it'll just take you longer to do 'this bit' in c++ since they don't supply an api - so you'd have to model the java or Objective-C one.
So, I'd start in an 'agile' frame of mind, small steps, refined, combined - I don't think the big issue here is getting the dictionary definitions, its the matching - so you may need to think about storing dictionary results in memory or some other appropriate form so you can develop an algorithm for matching and/or retrieving more dictionary entries - and also 'backtracking' if you come to a dead end
|
|
|
|
|