|
My Question do you want to line to appear inside CEdit Control or outside edit control?
If inside, you have to overide CEdit OnPaint function
if outside, you ClientToScreen or ScreenToClient function to get exact location of point
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I use ScreenToClient().It works.
Thank you so much.
Anu
|
|
|
|
|
Shameless plug: Please vote for answer
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Dear all,
I want to develop a service (that is written by unmanaged C++) in Win7.
This service can detect status of UPS, example: low battery, out of electric, etc..
It connect with UPS by RS232C cable through COM port.
I google and find some funtions: GetCommState, SetCommState, GetCommModemStatus but don't know how to use it to check status of UPS (low battery, out of electric, ...)
Pls. help me to solve it .
Thanks a lot.
Ratkit!
|
|
|
|
|
You havnt said what you want to DO with the UPS status once you've found it - lets assume you wish to write it to the Windows Event Log for start..
I would appoach it in a number of 'phases', not knowing what experience you have
1) build a console mode program capable of writing application events to the event log
2) use something like Serial library for C++[^] in a console mode program to be able to read the UPS data from the serial port - somewhere in the specs for the UPS it will tell you how to interpret the data to give you the status
3) then write a service, make sure you can do the normal things - start, stop, use the knowledge gained from (1) to write an event to the log on a timed basis - eg, every 5 minutes
4) once youve gotten here, you then re-do the service to use the knowledge gained in step 2, to determine and log the UPS status to the event log
Once your service is up and running, you can expand the logging event to (for example) send an email if the UPS needs attention, or (for example) add a system-tray applet and change the colour of it to red
'g'
|
|
|
|
|
Check out the Win32_UninterruptiblePowerSupply WMI class.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
According to the documentation on Win32_UninterruptiblePowerSupply: "Beginning with Windows Vista, this class is obsolete and not available because the UPS service is no longer available."
http://msdn.microsoft.com/en-us/library/aa394503(VS.85).aspx
Can you suggest another way to help me solve it?
|
|
|
|
|
In addition to what David said, you can call GetSystemPowerStatus() to get that information.
|
|
|
|
|
Hi,
I have noticed a problem in windows programming that I am unable to solve. I have created a new thread which should run as a separate process. In this thread I continually update a counter so that I Can visually see if and when my thread is interrupted.
If I put a CComboBox control on my dialog my thread is momentarily interrupted when the CComboBox is clicked and the list drops down.
I have tried creating my thread with realtime priority and the combobox still interrupts my thread when dropped down. Obviously the dropping down of the combobox does not interrupt other applications that are running in separate processes so I do not understand why it would interrupt my thread.
<br />
unsigned threadID;<br />
HANDLE hThread = (HANDLE)_beginthreadex( NULL, 0, &UpdateThread, (void*)this, 0, &threadID );<br />
SetPriorityClass(hThread, HIGH_PRIORITY_CLASS);<br />
SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);<br />
How can I create a thread that will not be interrupted by the dropping down of the combobox?
Thanks,
Greg
|
|
|
|
|
I would start looking at how the threaded procedure is communicating with the dialog
There are a number of good articles around on comms between a dialog and a worker thread - Im almost tempted to point you here http://www.flounder.com/workerthreads.htm[^]
'g'
|
|
|
|
|
I using PostMessage to send a user defined message on the main GUI thread which then calls SetWindowText on the static control that I am using for a counter. From what I have read this is the only safe way to update the GUI From a separate thread. I am still lost on why the dropping down of the combo box would interrupt the drawing of my counter control.
|
|
|
|
|
Greg Ellis wrote: I have created a new thread which should run as a separate process.
What does this mean? Is it a thread in the same process or a separate process?
How does the thread report its progress exactly?
Steve
|
|
|
|
|
R u trying to update the counter in dialog and viewing? if drow down box painter u can see some delay in the counter updation in dialog.
|
|
|
|
|
You say you have a worker thread posting messages to the UI thread.
Your worker thread is not being interrupted any differently than it was when the combobox is not being used. Windows runs multiple threads by time slicing. Higher priority threads get more slices more often.
It appears to you that the thread is interupted by the click but it is not. As your using post message, the UI thread updates the control content. This is the same thread that handles the users click on the combobox. While the UI thread is handling the click combo drop event, any messages posted by the worker thread are being added to the message queue for the UI thread to process once it returns from its current work.
The issue you have is that the drop event of the combo is animated and due to this appears to pause the UI while this happens. Apart from re-writing how a combo box works (or some how disabling the animation) I do not beleive there is anything you can do about this.
As a test to show its not affectig the worker thread. Time how long it takes for your on screen counter to increment to a set count. Then check that its takes the equivalent time (within a dop of the combobox time threadshold) it should still reach the same count.
If you vote me down, my score will only get lower
|
|
|
|
|
The visual studio c++ program compiles and build without errors. When i try to run it from the black screen, it says: Prgram.exe has encountered a problem and needs to close. We are sorry for the inconvenience. I believe I wrote this code before and it worked without problems. I don't understand why it will not work now. I could be wrong, it's been awhile. PLEASE KINDLY HELP?
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
string fileName,line;
ifstream infile;
cout<<"Enter the file name and complete path: ";
cin>>fileName;
int Adder=0,count=0;
string *A;
infile.open(fileName.c_str());
while(!infile.eof())
{
getline(infile,line);
if(line[count]=='A'||line[count]=='a')
{
A=new string[Adder];
A[Adder]=strlen(line.c_str());//THIS LINE IS CAUSING ERROR
cout<<a[adder]<<endl;
adder++;
="" }
="" return="" 0;
}
<div="" class="signature">
modified on Thursday, May 20, 2010 9:48 PM
|
|
|
|
|
That is a bad post. Please read the "how to ask a question" sticky message, use PRE tags, and provide an accurate description of the things that happen against your expectation. Then people will be willing and able to help you.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
This use to be a cool place where individuals of all knowledge level came to share ideas, problems and solutions. With all due respect, this site is not the cool entity it used to be. Now it seems like asking a simple question is extremely very complicated. I tried reading the posting instructions and got totally lost in its comprehension. What Happen to Code Project?
|
|
|
|
|
without proper formatting, your code is hard to read. And it is strange:
- I see a "count" variable that starts at zero and remains zero;
- I see things getting stored in a string array for no good reason; maybe it is the beginning of something bigger?
- I see something that probably is sufficiently wrong to cause a crash:
new string[Adder] probably creates an array (a new one each time!), of which the elements are indexed from 0 to Adder-1, yet the very next line attempts to access the element with index=Adder which is beyond the array. Boom.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Can you please tell me if following instructions is correct: A[0]=strlen(line.c_str());
|
|
|
|
|
If new string[Adder] does what I expect, it creates an array with size zero since Adder is zero the first time around. So there is no way you can store anything in it.
You probably need new string[Adder+1] to fix that, and it would fix the illegal access too, since now you have room for elements 0, 1, ... up to Adder.
When you read from the array (in a cout statement IIRC), you should only read elements that have been written to earlier in that very same array; so changing one index to zero and keeping the other at Adder, will fail each time but the first.
However, as I said before, I see no point in creating an entire array each time around, while only filling one element of that array. I fail to understand what it all is going to do, and I find it hard to believe it used to work before.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
It is a string array and i am string load the array with a string such as a name. I am not trying to load a single character. I saw your point with and i did try:
A=new string[Adder+1];
A[Adder]=strlen(line.c_str());
cout<
|
|
|
|
|
Your compiler is probably screaming blue murder at you over the line you're interested in - see what it's saying and fix it. On one of my compilers it'll say something like: "conversion from 'size_t' to 'char', possible loss of data" which is a pretty big hint that it's not storing what you want in your array.
I know I've said it before in my previous post - using built in arrays and pointers is complete overkill for this sort of problem. std::vector and std::string are your friends here.
|
|
|
|
|
I have to say it was a bit of a trial reading your code, not just 'cause of the formatting! Before slagging people off for their attitude in helping you remember it pays to give them the respect they deserve by posting code that actually compiles - as you couldn't be bothered to stick you code in
tags we can't see your include files for example. Also some idea of what the program does is helpful when it's not obvious from the code (and in this case it aint obvious - are you trying to count the lines that start with A or a or just echo a file to the console?)
Look into these things:
- Don't use low level constructs (pointer, arrays, dynamic memory allocation) where a couple of local objects would have done (i.e. use <code>std::vector<std::string> lines( number_of_lines );</code> )
- use variable names that describe what you're doing - i.e. rename adder and A
- Learn how IOStreams work - <code>cin >> fileName;</code> won't work if you have spaces in the filename
- Grab a textbook and have a look at the difference between initialisation and assignment. For example there's no reason to not create your input file object and open it at the same time
- using strlen is completely pointless in a C++ program that's using std::string. Look up the interface to std::string in a decent reference and you'll find a member that does the right thing
Cheers,
Ash
|
|
|
|
|
Dear Sir, concerning your little search engine that finds A's in text files ..
Well, it works perfectly now, some minor alterations were made.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class FileSearcher
{
public:
string fileName,line;
char filename[256];
unsigned long fileSize, begin,end;
int Adder,count;
string *A;
public:
FileSearcher(char *file )
{
Adder=0;
count=0;
runMe(file);
}
~FileSearcher()
{
delete []A;
}
public:
void runMe(char *file)
{
cout<<"Enter the file name and complete path:> ";
cin>>filename;
fileName.assign( filename );
ifstream infile(filename);
infile.seekg (0, ios::end);
fileSize = infile.tellg();
infile.close();
cout << "size is: " << (fileSize) << " bytes.\n";
A=new string[fileSize+1];
infile.open(fileName.c_str());
Adder=0;
count=0;
while(!infile.eof())
{
getline(infile,line);
if(line[count]=='A'|| line[count]=='a')
{
cout<<"FOUND an A here ("<<line[count]<<") Line= "<<Adder<<": \n\n"<<line.c_str()<<"\n";
A[Adder]=strlen(line.c_str());
count++;
}
count=0;
Adder++;
}
infile.close();
cout<<"\n\n";
}
};
int main()
{
FileSearcher *myFileSearcher = new FileSearcher("c:\\t.txt");
return 0;
}
..
modified on Saturday, May 22, 2010 6:58 AM
|
|
|
|
|
It is perfect, for some strange version of perfection that I'm not sure that most experienced C++ programmers would recognise.
Faux pas the first: #pragma warning( disable : 4101 ) . Why are you disabling this warning? What defects does it hide in your code?
Faux pas the second: Using arrays when, in this example you just need std::string
Faux pas the third: Redundancy - reading stuff into a character array then assigning to a string when you could just read straight into the string
Faux pas the fourth: Closing the file, why not just rewind it to the beginning. Or stick getting the filesize in it's own function.
Faux pas the fifth: What are Adder and count for? Where I come from an Adder is a snake and the count is on Sesame Street. They're initialised, incremented and assigned and, er, pointless.
Faux pas the sixth: What's the point of an array of empty string, one per character in the input file?
Faux pas the seventh: Declaring variables miles away from using them
Faux pas the eighth: You can't see this one as you disabled the warning, bummer!
|
|
|
|