|
GauranG33 wrote: No I dont have Idea about that. Can you guide me through that.
Don't you have a Network Administrator?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
I have a dialog without resources which works fine.In a class derived from CDialog I have a variable of type DLGTemplate.This variable has default x,y,cx,cy values set in the constructor.
But I want to increase the height and width of the dialog box in accordance with the number of windows controls added to the dialog box.I am adding windows controls in the OnCreate() function of Dialog class like this.
CRect Rect(10,10,100,100);
CComboBox* Combo = new CComboBox;
Combo->Create(WS_VISIBLE | WS_CHILD |CBS_SORT, Rect, this, ID);
How do I find the relation between the above Rect's coordinates and the coordinates of the dialog box?
I tried MapDialogRect but I don't understand what exactly is done there?
Please help.
Thanks
Prithaa
|
|
|
|
|
The co-ordinates specified in the control's Create() call are specified in the parent's (your dialogue's) CLIENT co-ordinates.
'Client' co-ords have their (0, 0) at the top-left of the space *within* any border and title bar the dialogue has. If it has no border and no title bar, then this is the same as the top-left of the full dialogue.
If you want to know how far the control is from the top-left of yoour dialogue and you have a title bar and / or border, then you need to get the dialogues 'window' rect, and the control's 'window' rect, and then you can calculate the offset.
Note, though, that if you ask a control for its client rect, it gives you co-ordinates relative to *its*own* client area, not its parent.
If you ask a control or window for its 'window' rect, it gicves you co-ords relative to *the*screen's* top-left.
So, to get the offset from a dialogue's client arrea to a control's top-left, do this:
CRect rctControl ;
MyControl.GetWindowRect(&rctControl);
// It's relative to top-left of screen.
MyDlg.ScreenToClient(&rctControl);
// Now, relative to top-left of dlg's client area.
To get it relative to the full dlg's top-left (ignoring title bar and border):
CRect rctControl ;
MyControl.GetWindowRect(&rctControl);
// It's relative to top-left of screen.
CRect rctDlg ;
MyDlg.GetWindowRect(&rctDlg);
rctControl.OffsetRect(rctDlg.left - rctControl.left,
rctDlg.top - rctControl.top);
// Now, relative to top-left of dlg's full area.
|
|
|
|
|
If you know your client area size, and you want to calculate the window
size that will give you that client area size, you can use:
CWnd::CalcWindowRect() (MFC)
or
AdjustWindowRect()/AdjustWindowRectEx() (Win32)
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi All,
I am writing an application which checks LPT signal for doing something. My code looks like:
void LPTThread()
{
while (1)
{
if (ReadLPT(pinX) = signal level Y) {do something;}
}
//pin is one of pin of LPT port
//signal level of each pin is 0 or 1 at a time
}
This loop cause the CPU usage always 100%, is there any way to prevent it? Can we catch this change by any event handler, it mean when a change occurs at LPT or, this event handler will be called?
Thank you for your help.
|
|
|
|
|
I never heard about a function called ReadLPT (and google wasn't of any help), from where is that coming from ? Can you give more details ?
Anyway, for serial communication (so COM ports), you can use functions like WaitCommEvent. I suppose there should be something similar for you.
|
|
|
|
|
Dear Moonen,
Thank for your answer. But I need to clarify that ReadLPT is just only my pseudo code - the code that is responsible for reading LPT port signal/information.
Thanks.
|
|
|
|
|
Ok but that doesn't help. Which functions are you using exactly to access the port ?
|
|
|
|
|
Thanks for you reply. I use Inp32 function which is in the inpout32.dll library - a very common used.
|
|
|
|
|
Hi,
I don't know much about LPT signal.
but i got simmiler problem in one of my project.
you do one thing begin main thread once some where in Oninitdialog() or On InitInstance().In main thread function in while(1) loop call child thread
& do your work in child thread & you must end that childthread in that childthread itself.
have a look on given sample....
OnInitInstance()
{
begin MyMainthread()...
}
void MyMainthread()
{
while(1)
{
begin mychildthread()
::Sleep(400);
}
}
void mychildthread()
{
//Do your work here....
........
.....
_EndThread();
}
I hope this will reduce your CPU Uses.....
Rahul Vaishnav
|
|
|
|
|
Thanks for your reply.
But the problem is the thread cannot sleep every 400ms before checking LPT port. The application must ensure that, where the LPT signal changes, it will immediately handle that.
|
|
|
|
|
If the particular pin isn't one of the ones that is monitored by WaitCommEvent, there is no built-in notification mechanism. Short of writing a parallel port driver to implement notification, try putting your busy-wait loop into a seperate thread that runs at a lower priority than the rest of your program.
Judy
|
|
|
|
|
Also, you use the work "immediately" - how immediate is immediate? Windows is not a real-time OS, and as such, does not guarantee response times, even within drivers.
|
|
|
|
|
TPN wrote: This loop cause the CPU usage always 100%...
And rightly so since you are not yielding control of the CPU. Consider a message pump/loop.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have used this code in my project for diduction of CPU uses..
it is working fine at my end.
if you dont want to use Sleep() then remove it & add WaitForSingleObject() as shown in given sample.
try it....i hope it will work...
while(1)
{
HANDLE hThread;
hThread = (HANDLE)_beginthread(CallchildFunction,0,NULL);
WaitForSingleObject(hThread, INFINITE);
::Sleep(500);
}
Rahul Vaishnav
|
|
|
|
|
node->next = (struct ListEntry *) malloc(sizeof(struct ListEntry));
what does it mean,i want go get a particular answer,thanks
|
|
|
|
|
void main(void)
{
int i;
struct ListEntry {
int number;
struct ListEntry *next;
} start, *node;
start.next = NULL; /* Empty list*/
node = &start; /* Point to the start of the list*/
for (i = 1; i <= 10; i++)
{
node->next = (struct ListEntry *) malloc(sizeof( ListEntry));
node = node->next; //here the pointer is setted to node?
node->number = i;
node->next = NULL; // what does this mean?
}
/* Display the list*/
node = start.next;
while (node)
{
printf("%d ", node->number);
node = node->next;
}
}
maybe there are some unnecessary sentences,can you help me find out them that let me feel more clear
|
|
|
|
|
what's your question here ?
please reuse the other post, and reply to my answer if you want more...
also, when you post some code samples, please use the <pre></pre> html tags to format your message.
|
|
|
|
|
Mister youbo,
i'm goin to answer you, but before, here some comments i have to say to you, which i want you to take from the good, wise side...
you've been asking several question like this one, which are obviously from a beginner. You still can ask when you don't understand, but a better solution would be to learn the C/C++ languages a bit deeper to get rid of these by yourself.
ok then, let's go:
youbo wrote: node->next = (struct ListEntry *) malloc(sizeof(struct ListEntry));
it seems to me that you have a linked list, and that you code in C (correct me if i'm wrong).
a linked list is compound of nodes; each node stores a value, and has a link (pointer) to the node next to it in the list.
for what i understand here, node might be defined as a struct (ListEntry ), and next is defined inside it to being a pointer to another node (ListEntry* ).
for the right par of the assignment operator, we have a call the the malloc() function.
malloc() is used to allocate memory dynamically on the heap. you give it an integer parameter which tells it the amount of memory to allocate. here, sizeof(struct ListEntry) ; that mean, "allocate the amount which a ListEntry structure regularly takes in memory".
then, as malloc() returns a void* (a pointer to anything), we must translate it to the type of pointer which will store the returned value, by using a cast operation. that's performed with the (struct ListEntry*) prepending the malloc call.
then, once the memory is allocated, the address of that memory is returned, and casted to the type of a "pointer to a node in the list", we can assign this to the next member of the node struct (thus the syntax node->next )
any more questions ?
|
|
|
|
|
I gave you a 5; even though I found your explanation a bit confusing and I know multiple ways to link structures together: Single, Double, Single with parent child, Double with parent child, and various trees.
They really do need to spend some quality time trying to figure it out on their own.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
John R. Shaw wrote: gave you a 5; even though I found your explanation a bit
thanks John.
please, tell me what's confusing you, so that i can modify the most consequently
also, i too know veral kind of linked lists, but as the OP is a beginner, I didn't want to give him too much useless explanations...
|
|
|
|
|
Your wording was confusing (at first glance) and an example would have helped, especially for a beginner. “baeten” gave an example (although it is not a unidirectional list), since I posted, and that combined with what you said should help them figure it out.
If I was not so tired, I probably would have made it simpler (like ‘baeten”):
It is trying to allocate the next node in a linked list, which is equivalent to adding a new link to a chain. The allocation may fail so make sure that malloc does not return NULL.
node : A memory pointer to type ListEntry ; that is the address of a memory block containing a ListEntry structure (a node).
node->next : The next link in the chain; a pointer to the next structure (node).
….
A linked list looks like this in memory node->next->next->next->NULL , where NULL is the end of the list (or chain).
…
Or something like that; I am not in the right frame of mind right now. You did a good job and they need to search for a tutorial and spend time playing with lists.
Good night, or day (5 A.M. here).
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Hi,
that's a unidirectional list.
if your struct ListEntry is :
struct ListEntry {
char value[50];
struct ListEntry * next;
}
you allocate the first element, so you have a string and a blank pointer.
struct ListEntry *First = (struct ListEntry*)malloc(sizeof(struct ListEntry*));
First->next = NULL;
strcpy(First->value,"empty");
now you set the next-pointer to a new allocation of a new struct.
First->next = (struct ListEntry*)malloc(sizeof(struct ListEntry*));
So you can reach the new Element by dereferencing the node->next : node->next->value.
You should always store and save the first element.
Each time you like to add a new element you need to loop from the first element to the last
( which is the element with the next-pointer as NULL )
If you have 5 elements with numbers into it, it can be represented this way :
|"one"|0x4567| ---> |"two"|0x4568| --> |"three"|0x4569| ---> |"four"|0x4570| ---> |"five"|NULL|
|
|
|
|
|
OK,i will remember your idea!toxxct
|
|
|
|
|
If you want to reply to toxcct , than you have to use the reply button at the end of the message comes from toxcct .
This is an hidden rule of this forum-board.
-- modified at 4:57 Thursday 27th September, 2007
Russell
|
|
|
|
|