|
|
|
Terry O`Nolley wrote:
I'll give you a C++
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"
|
|
|
|
|
How can I change the toolbar background color? I want it to have a custom color.
Eilzabeth
|
|
|
|
|
Is it possible to use a macro on another macro?
For example (and purely for illustrative purposes), suppose I have the following:
#define YES "1"
#define NO "0"
#define StartYourEngines "1"
and in my code I would like to do something like this:
StartYourEngines = YES;
is that possible? Or how would I go about doing something like that (using macros)?
Thanks.
William
Fortes in fide et opere!
|
|
|
|
|
#define YES "1"
#define NO "0"
#define StartYourEngines YES
|
|
|
|
|
Thanks for replying.
#define StartYourEngines YES
doesn't work. The compiler complains that "YES" is an undeclared identifier.
Actually, prior to posting the question, I had tried a few experiments and was unable to get a clean compile (understanding that a clean compile is not a guarantee for a correct execution of the program), which makes me think either it cannot be done, or it would require a clever way of getting around the compiler, and at the same time getting it to work correctly.
William
Fortes in fide et opere!
|
|
|
|
|
Compiles OK for me in VC6.
If you want to do conditional compilation using macros, then you would typically do something like this:
#define OPTION_A
#ifdef OPTION_A
#endif
#ifdef OPTION_B
#endif If you want to define a number of options, and create a default for one with any of them being dynamically available, you would do something like this:
#define OPTION_A 0
#define OPTION_B 1
#define DEFAULT_OPTION OPTION_A
int nOption = DEFAULT_OPTION;
switch( nOption )
{
case OPTION_A:
{
}
break;
case OPTION_B:
{
}
break;
}
|
|
|
|
|
Thanks for replying.
You posted some very good samples here, and I'll see which one will work for my situation at hand.
Actually, I have a MACRO file that I '#include' in my application. In that MACRO file is where I have (and again for purely illustrative purposes):
#define YES "1"
#define NO "0"
#define StartYourEngines "YES" // using your suggestion
==============================
In the application, I have:
#include "MACROFILE.h"
etc.
if(StartYourEngines == YES)
{
...
StartYourEngines = NO;
}
==============================
That's what I was referring to about the compiler giving the error messages (about "YES" and "NO" being undeclared identifiers).
That's what I'm trying to accomplish without resorting to cluttering up the global namespace. Ordinarily, I would use a specialized class object to do what I'm after, but I'm suffering heavily from time pressure and I'm looking for the quickest and easiest way of getting the work done. Later, I could always go back and clean things up with a better solution, but for right now, I'm doing working lunches and other meals, and surviving on the least amount of sleep as possible.
Thanks again for your suggestions.
William
Fortes in fide et opere!
|
|
|
|
|
If you expand your macros, the resulting code will look like this:
if( "1" == "1" )
{
...
"1" = "0";
} As you can see that's not valid code. If you want to change the value of StartYourEngines at runtime, then you'll need to use a variable something like this:
#define YES 1
#define NO 0
int StartYourEngines = YES;
if( StartYourEngines == YES )
{
...
StartYourEngines = NO;
} Expanding the macros from that example, the code will look like this:
int StartYourEngines = 1;
if( StartYourEngines == 1 )
{
...
StartYourEngines = 0;
}
|
|
|
|
|
It looks like you might be wanting to run something once, if so you could do it like this:
class MyClass
{
protected:
BOOL m_bFirstTime;
public:
MyClass()
: m_bFirstTime( TRUE )
{
}
void MyFunction()
{
if( m_bFirstTime )
{
m_bFirstTime = FALSE;
}
}
}; Although, in real world apps it would be better to structure the class something like this:
class MyClass
{
protected:
BOOL m_bInitialized;
public:
MyClass()
: m_bInitialized( FALSE )
{
}
virtual ~MyClass()
{
UnInitialize();
}
BOOL Initialize()
{
BOOL bResult = FALSE;
{
m_bInitialized = TRUE;
bResult = TRUE;
}
return bResult;
}
void UnInitialize()
{
if( m_bInitialized )
{
m_bInitialized = FALSE;
}
}
BOOL MyFunction()
{
BOOL bResult = FALSE;
{
if( m_bInitialized )
{
bResult = TRUE;
}
}
return bResult;
}
}; Or if you aren't using classes, and you want to be bad, you could do something like this:
void MyFunction()
{
static v_bFirstTime = TRUE;
if( v_bFirstTime )
{
v_bFirstTime = FALSE;
}
} Or this:
static g_bFirstTime = TRUE;
void MyFunction()
{
if( g_bFirstTime )
{
g_bFirstTime = FALSE;
}
}
|
|
|
|
|
Thanks again for replying.
Theses are flag issues that I'm working with, and as such, they are handy and powerful for doing all sorts of things. The downside to using flags, is that they are mostly volatile (meaning, you don't necessarily want them to be permanent members of your class). They are mostly disposable. But unless you make them part of your class, you lose that "global-ness" they provide by having their values go with them wherever the class in which they are a part of, gets "#included".
The other alternative is (of course) using the global namespace which is what I'm trying to avoid, but still retain the "global-ness" of their presence (i.e. the flags), which is where the idea of using a macro file originated.
What I was trying to do, was use the universality of the macro idea (by way of a separate macro file), coupled with the permanence of the class object that would signal to the class object, "when this macro condition is true, use this certain variable in the class (or go down that certain path in your processing)." Likewise do something quite differently if the condition is false. Then by '#including' this class object in other files with the macro file as well, I'd be able to communicate with that class object file wherever it's '#included', thereby avoiding use of the global namespace.
Of course the first step in accomplishing what I was ultimately trying to do, was to set up the macro side of it and get that working before going on to the next phase of actually implementing the goal.
Your messages have given me some good infomation, and there are merits to some of the things you offered, which if I am to succeed in my grand plan, I have yet to get the macro part nailed down. OTOH, in the interest of time, I might just go with the global namespace and clean that up later.
Thanks again. I appreciate the thoughts and the efforts.
William
Fortes in fide et opere!
|
|
|
|
|
Hi, all:
I have defined the following ofstream
std::ofstream osOut;
in my class and it saves all the stuff I need in the class. Then I have to call the Save method of a member object. The Save method is defined as
HRESULT Save( std::ofstream& osOut );
but located in my DLL. Apparently the osOut passed into DLL does not work as it should be. If I save a string like
osOut << strMyString;
It works. However if I try to save a long like
osOut << lMyNumber;
it crashes badly.
Does anyone know why and have any suggestions how to fix this problem? Thanks in advance.
Dion
|
|
|
|
|
I am new to using WindowSubclassing but I need to know how do I use SetWindowSubclass to change my WndProc. Can someone help me with this.
|
|
|
|
|
Hello all..
I am going to insert some data into a BITMAP File..
BUt First of all..i really hope anyone can explain to me how the BITMAP structures like... i mean.. i did some researches and learned that there are some bitmap header that i cannot alter or edit...
can anyone describe to me.. how should i get the values for a 24bit(true color) bitmap??
i mean... wat functions should i call to get the values..so i can get the values like these :
R G B
= = =
10100100 00101001 11001110
00100111 00110111 01110111
11101110 11110100 11100101
so i can edit the LSB to store my secret datas??
i hope anyone can help me..
thanks alot..
my email : twh81@tm.net.my
thanks..
Thong
(Malaysia)
...
|
|
|
|
|
colormyiris wrote:
BUt First of all..i really hope anyone can explain to me how the BITMAP structures like
Try www.wotsit.org.
|
|
|
|
|
Hi,
I have been trying to put my own
ActiveX on the CFileDialog. Seems
like whenever I put my activeX with
CFileDialog class, the file dialog
won't open; instead, return IDCANCELL
at mydlg.DoModal(); But with those
controls that come with
VC( like combo box, bitmap...etc)
I have no problem open up the Cfiledialog
dialog. Anyone out there solve this problem.
shin
|
|
|
|
|
Hi,
I'm new to MFC, I have some questions about the controls. Please help.
1. If I try to use the variable name of any control, say an Edit box control (m_nEdit, of CString type),it doesn't work.
m_nEdit.Empty(); //doesn't empty the edit box
But, if I do the following it works.
CWnd* pWnd = GetDlgItem(IDC_EDITEdit); //IDC_EDITEdit being the control ID
pWnd->ShowWindow(SW_SHOW);
pWnd->SetWindowText("");
2. If the Editbox has integer, how to get the value of the integer?
pWnd = GetDlgItem(IDC_EDITInt);
pWnd->GetWindowText(cstInt); //gives error
Is there any way to get/set the value in the edit boxes using the variable name of that control?
3. Similar question about check boxes.
How do I get & set the values of the check boxes from my VC++ programs?
I knwo these are very basic stuff, but, please help.
Thanks,
Binayak Bhattacharyya
|
|
|
|
|
Binayak wrote:
1. If I try to use the variable name of any control, say an Edit box control (m_nEdit, of CString type),it doesn't work.
m_nEdit.Empty(); //doesn't empty the edit box
But, if I do the following it works.
CWnd* pWnd = GetDlgItem(IDC_EDITEdit); //IDC_EDITEdit being the control ID
pWnd->ShowWindow(SW_SHOW);
pWnd->SetWindowText("");
You have a "value" variable there. You need a control variable... i.e. a CEdit variable. The CString that you have gets the string from the editbox when UpdateData() is called [probably when you click ok [if it's a dialog box].
When you are creating the variable [I presume your using the wizard here] just select Control instead of Value variable.
Binayak wrote:
2. If the Editbox has integer, how to get the value of the integer?
pWnd = GetDlgItem(IDC_EDITInt);
pWnd->GetWindowText(cstInt); //gives error
Replace GetDlgItemText in your code with GetDlgItemInt .
Binayak wrote:
3. Similar question about check boxes.
How do I get & set the values of the check boxes from my VC++ programs?
Once again... create a control variable [CButton in the case of a check-box] and you the SetCheck() and GetCheck() functions.
Hope this helps.
Regards,
Brian Dela
|
|
|
|
|
Hi,
1. I want to perform different actions depending on user clicking different nodes (tree items) in the tree control. I wanted to write handler for the single click event (NM_CLICK), but, m_Tree.GetSelectedItem() returns the Item which was selected earlier, instead of the one that is selected now. Can anybody tell me how to get the Item on which the user clicks?
2. I'm trying to make XML document from a Tree Control from my VC++ program. I plan to use DOM, can anybody give me some pointers/ sample code on that?
Thanks,
Binayak Bhattacharyya
|
|
|
|
|
Binayak wrote:
Hi,
1. I want to perform different actions depending on user clicking different nodes (tree items) in the tree control. I wanted to write handler for the single click event (NM_CLICK), but, m_Tree.GetSelectedItem() returns the Item which was selected earlier, instead of the one that is selected now. Can anybody tell me how to get the Item on which the user clicks?
That's the wrong message handler, prefer overriding TVN_SELCHANGED. If you _really_ need to use NM_CLICK, I can provide you with a fix to this.
~RaGE();
|
|
|
|
|
Thanks a lot.
It works now
I have some more questions coming up...please help
Thanks again.
|
|
|
|
|
Hi everybody,
I've asked lots of people to help me out here but apparently this seems hard to do. ALL suggestions are more than welcome! If this thing gets solved rapidly I will consider paying a small amount for a solution.
The problem description:
I have a BHO (Browser Helper Object) in a dll. The BHO is loaded when Internet Explorer (iexplore.exe) starts and unloaded when it closes. It performs dynamic dictionary lookups on web pages. In the loading part of the dll
<br />
<br />
extern "C"<br />
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID )<br />
{<br />
if (dwReason == DLL_PROCESS_ATTACH)<br />
{<br />
<br />
_Module.Init(ObjectMap, hInstance);<br />
DisableThreadLibraryCalls(hInstance);<br />
}<br />
else if (dwReason == DLL_PROCESS_DETACH)<br />
_Module.Term();<br />
return TRUE;
}<br />
I have commented out a code section which makes the loading stop if it discovers the caller as the process explorer.exe. This piece of code does everything I want IF it wasn't for the fact that Internet Explorer (iexplore.exe) sometimes runs under the explorer.exe process.
So the problem is, how do I get the dll/BHO to load ONLY ONLY ONLY when Internet Explorer is started and NOT NOT NOT every time when a folder (resides in explorer.exe process) is opened. As you probably know, we all use folders every day and my BHO loads a heavy dictionary every time it is opened.
Now, some of you clever guys out there might say: Why not delay the heavy part loading until you really need it? That is, load it only when you discover you have a web page (and not a folder). That would almost be fair enough if it, among other things, wasn't for a copy protection mechanism that I have in my dll. When the copy protection mechanism sees that there are no more, let's say, evaluation days left for the BHO dll, then a message pops, informing this to the user. And naturally it does this with every opened folder too, not only with Internet Explorer. This is definitely not ok!
And another problem is that the BHO dll sort of hooks on to the operating system since explorer.exe is an important process. For this reason only one would want to get rid of the folder/explorer.exe dependency. Also at installation and uninstallation things become complicated because you have to consider opened folders before you install/uninstall new versions/upgrades... Very annoying and cumbersome!
So, is there anyone out there who can help me with this? Surely there must be a solution cause there are lots (well, some anyway) of BHOs out there that either suffers from the same problem or have solved the problem already.
Thx for all your help! You are free to mail me directly at tommy@internetami.se.
/Tommy
|
|
|
|
|
The trouble is that there really isn't a difference anymore between "IE" and "Explorer" If you run "Explorer" and enter http://www.foo.com into the address bar, suddenly it looks like IE and you can view that web page. If you run "IE" and enter C:\windows in the address bar, suddenly it looks like Explorer and shows that directory.
What I do to tell the difference is try to get an IHTMLDocument interface on whatever is being shown in the view. If that QI fails, then a web page is not being displayed, so you can assume the file system is.
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Michael Dunn wrote:
What I do to tell the difference is try to get an IHTMLDocument interface on whatever is being shown in the view. If that QI fails, then a web page is not being displayed, so you can assume the file system is.
I'm assuming you're not doing this from the DllAttach function. (If that's the case, please tell me how!)
If not, well, I've tried that too (after SetSite call) but what that really does is only to relieve me [or the folders] from my heavy dll dictionary loading; still the folders and all that are under the influence of explorer.exe are loading the BHO when opened.
Is there no way to test for differences between the callers other than the process name?! Sounds weird...
Well, well, the solution is still to be found I guess.
Thx Mike,
/Tommy
|
|
|
|
|