|
When you create a control by adding it via the dialog editor, the control automagically uses the font of the dialog. If you create the control manually via Create() you have to set the font yourself, or else it will use the default system font. You can use GetFont to get the dialog's font, and SetFont to set the control's font.
CMyListBox.Create(...);
CMyListBox.SetFont(GetFont());
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
I am working on a VC++ project in which
UserInterface is an
exe and also a service is running for the
application.My problem is
when i switch between one user in WIN XP to another I
am not able to pop
up the userinterface in new user environment.My
service is autmatic on
task manager i am able to get userinterface exe for a
while but it dies
.when we check the task manager of first user I can
see both
usrinterface and the related service on task
manger.How can i pop up my user
interface when we switch from one user to another.
|
|
|
|
|
Hello Friends,
Kindly observe the code given below
#include <iostream.h>
void show(int x)
{
cout <<"inside the function one " << x << endl;
}
template <class t=""> void show( T a)
{
cout << "inside the template" << a << endl;
}
int main()
{
show(10);
return 0;
}
When I run this program , I get the output
"inside the function one 10".
My question is why the template function is not get executed
and only simple function get executed only"void show(int x)".
Can any one help me in this matter?
|
|
|
|
|
You need to check 'Do not treat <'s as HTML tags' for us to see the code properly.
Christian Graus - Microsoft MVP - C++
#include <iostream.h>
void show(int x)
{
cout <<"inside the function one " << x << endl;
}
template <class T> void show( T a)
{
cout << "inside the template" << a << endl;
}
int main()
{
show(10);
return 0;
}
When I run this program , I get the output
"inside the function one 10".
|
|
|
|
|
phijophlip wrote:
int main()
{
show(10);
return 0;
}
Of course you do, what else could happen ?
show(10) will call the non-templated function, and without that function, would be a compiler error
show<int>(10) will call the second function and will not compile if only the non templated function exists.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i am working on making a mediaplayer.I have to add directories at run time.The files in the folder path should be added to list control along with existing files .iam using SHBrowseForFolder .I am adding foler path to environment variable.List should update and display all files according to the path in environment variable set .List should reside on reboot . Now it is showing the most recently navigated folder.On reboot it 's null.
all files are video files .
Thanks for going through my message
|
|
|
|
|
geo19762005 wrote:
List should reside on reboot
trying to understand the above line, can you please help.
suhredayan There is no spoon.
|
|
|
|
|
Is there some reason you try to manipulate the environment strings?
You could more easily store your setting for each user in the registry under HKEY_CURRENT_USER\Software\<yourcompanyname>\<yourprogramname>\Preferences
Then make a REG_SZ (string) value and called FoldersToCheck and save the folders the user selected, perhaps separated by semicolons or something. Or make a key called FoldersToCheck and then make individual values under it Folder1, Folder2, etc. That is up to you.
|
|
|
|
|
I have a class TstClass, In the TstClass.cpp I declare 3 function, 2 are TstClass funxtions, 1 is general functions...
CTstClass.cpp:
...
...
void Process1( void (*pDataRecept)( CString sDataList ))
{
....
}
BOOL CTstClass::GetData()
{
...
Process1( DispData );
...
}
void CTstClass::DispData( CString sData )
{
...
}
But I got Compilling error : error C2664: 'Process1' : cannot convert parameter 1 from 'void (class CString)' to 'void (__cdecl *)(class CString)'
What is the reason? Thanks!
|
|
|
|
|
DispData is a member of CTstClass. The prototype calls for a 'void (__cdecl *)(class CString)'
|
|
|
|
|
As DispData is a member function from the CTstClass, it has an implicit parameter that is passed to the function: the this parameter. Thus, the function prototype does not match.
To avoid that, make your member function static (but then, inside the function you won't be able to play with non-static members).
|
|
|
|
|
In my application I want to access files, where the underlying character type (ASCII or Unicode) is transparent for the application.
Suppose that in a reporting module a report is written to file, like this:
myfile << reportHeader << std::endl;
for (all columns) myfile << columnname;
myfile << std::endl;
for (all records)
{
for (all columns) myfile << data;
myfile << std::endl;
}
Now, I want my application to transparently write the report to ASCII or Unicode files, depending on the user specification.
Currently, you have to do it like this:
std::ofstream asciiFile;
std::wofstream unicodeFile;
if (user wants Unicode)
{
unicodeFile.open ("output.txt");
unicodeFile << reportHeader << std::endl;
}
else
{
asciiFile.open ("output.txt");
asciiFile << reportHeader << std::endl;
}
for (all columns)
{
if (user wants Unicode) unicodeFile << columnname;
else asciiFile << columnName;
}
... and so on
The disadvantages seem obvious:
- clumsy, unreadable code (especially if the write-to-file logic is spread over several methods)
- writing Unicode strings (std::wstring) to an Ascii stream doesn't even work; it produced garbage
Therefore, I need a kind of transparent stream, so that I can write the following:
transparentstream myfile;
myfile.setMode (ascii or unicode);
myfile.open ("output.txt");
myfile << reportHeader << std::endl;
for (all columns) myfile << columnname;
myfile << std::endl;
for (all records)
{
for (all columns) myfile << data;
myfile << std::endl;
}
Problems are:
- from which stream do I inherit the transparentstream?
- how do I define the transparentstream so all defined output operators keep on working?
- where do I put the conversion logic? (basic_buf? basic_filebuf?)
Of course I want something similar for input, where the stream can find out itself whether the file is Unicode (starts with 0xfffe or 0xfeff) or plain Ascii.
And as an additional challenge: is it possible to have such a transparent stream that can do something like this?
transparentstream mystream;
mystream.open("http://www.mywebsite.com/mypage.html");
mystream >> ...;
And if this is possible, how do I implement such a stream of buf class?
Did some of you already encounter problems trying to mix the STL and Unicode files?
How did you solve it?
Probably Java and .Net solve this problem in a elegant way, but I really need a solution using only STL.
Thanks for you suggestions.
Enjoy life, this is not a rehearsal !!!
Enjoy life, this is not a rehearsal !!!
|
|
|
|
|
My first thought is to encapsulate the ASCII and UNICODE streams with in your own class (or template) then duplicate the methods. It may be as simple defining operators for both char and wchar_t (I dought it thou).
class transparentstream
{
std::ofstream asciiFile;
std::wofstream unicodeFile;
...
};
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Is there a way to enumerate the windows of an application from it's process id?
thanks
|
|
|
|
|
I am not aware of a direct way.
Look at EnumWindows followed by a call to GetWindowThreadProcessId to correlate the known PID with the enumerated HWND.
To be really thorough, you can also EnumWindowStations followed by EnumDesktops followed by EnumDesktopWindows followed by GetWindowThreadProcessId
|
|
|
|
|
Hi,
I am doing a project in win32 . I use DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE messages to do certain things when a usb device is connected and disconnected.When I tested the app in XP the above messages are being called twice. ie when I plug the usb device the DBT_DEVICEARRIVAL is called and after certain time say a sec later it automatically calls DBT_DEVICEREMOVECOMPLETE and again DBT_DEVICEARRIVAL. I dont know why it does that. Do anyone have any ideas...pls help
|
|
|
|
|
|
When does the BEGIN_MESSAGE_MAP gets called to map control ID's to functions? I am asking this because in my project, a previous software engineer designed a class that is derived from a CFileDialog and attaches another dialog to the bottom of the CFileDialog as a toolbar. The issue I am having here is that the current class is dependent on a resource file for that project and for my project the resource ID's are different. I am including the file into my project using #include "..\projectname\COpenFileDlg.h" and the resources (dialog use as a toolbar).
My idea to work around this was to create static member variables that I can access/change the ID's before the constructor, BEGIN_MESSAGE_MAP and the OnInitiDialog() gets called. I know this is pretty ugly and I don't have a whole lot of time on hand to redesign it right now. But this is an easy way to work around it by having whoever (projects) that uses this customized dialog to provide their own ID's.
Any suggestions?
|
|
|
|
|
kongy79 wrote:
When does the BEGIN_MESSAGE_MAP gets called...Any suggestions?
I would suggest placing a breakpoint in the constructor, BEGIN_MESSAGE_MAP() , and OnInitiDialog() to see the calling order.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thank you for the offer. I fixed the bug already.
|
|
|
|
|
Hello,
I have some troubles to put version number in DLL generated by Message Compiler. In fact if I try to add a resource/Version, I just get some compiling errors.
Please help me.
Julien.
|
|
|
|
|
I'm working on a Windows Service and I'm looking for a straight-forward way to monitor its responsiveness while in the SERVICE_RUNNING state. I know that the Service Control Manager watches for hangs during startup with SetServiceStatus() and the checkpoint parameter, but what if the Service hangs while it's running?
I've thought about making another service to watch the service, but this seems a bit circular.
Any ideas?
Rodney
|
|
|
|
|
You ultimately have to be looking at it with something else, right?
And what can you do, or what is your goal, once you detect it is hung?
It could be sufficient to have your primary service thread (the one that MGHT hang) periodically update some counter or timestamp. A secondary thread (not likely to hang) within the same service can wake up periodically or be awoken with an event set by the first thread. It could examine the counter/time stamp. If the counter/timestamp has not bene updated 'recently' then maybe the secondary thread writes an event to the event log indicating the 'service' is hung and needs attention. Then you don't need to write two services.
An administrator can look at the event viewer to see if your service got stuck. Programs exist that can periodically scan the event log looking for particular items, and that might be sufficient to document the stuck service. There may be other things your secondary thread could do to bring attention to the stuck service.
|
|
|
|
|
Once I detect it as hung, I want to kill it and restart it. Using a counter-monitoring thread sounds good. I was also thinking of calling ::ControlService() with SERVICE_CONTROL_INTERROGATE to see if the call returns in a timely fashion, but I've heard this might not work because the Handler might still be processing commands when the rest of the service is hanging. Although, arranging the Handler to wait on an event to be set within ServiceMain() could still timeout the ::ControlService() call appropriately. Does this approach make sense, or do you think it's over-complicating things?
Rodney
|
|
|
|
|
ANY properly written Windows service should posess at least two threads. One thread does the service-specific work, and the other one services the control requests. In your case, I was proposing a third thread, which would monitor the status of your service and 'report' that it had hung. Now, I am not sure that a service can send a STOP control request to itself, this is something I have never thought to do or try. (Yoda was wrong, there is TRY and there is DO...) Anyway, you need to figure out what will 'terminate' your hung thread or cause your service to restart.
I suppose I would also encourage you to figure out why your service hangs. Is this truly unavoidable? Are you dealing with poor legacy design or something? I write and maintain a lot of code, and I don't think we have anything that we 'expect' to hang. That just does not seem right.
Maybe if you could describe for us here at CP what the underlying problem is, we could make some additional suggestions
|
|
|
|