|
yes. sorry.
the code has been edited.
|
|
|
|
|
#include < stdio.h >
void main()
{
int counter,fact=1,num=5;
counter = num;
clrscr();
while(counter > 0)
{
fact = fact * counter;
counter--;
}
printf("fact of %d is: %d",num,fact);
getch();
}
|
|
|
|
|
dear brother, can you tell me how to hook the messages of a short-cut menu?
for example, the short-cut menu on the desktop
|
|
|
|
|
Menu commands are sent using WM_COMMAND .
You should be able to intercept them using SetWindowsHookEx with WH_CALLWNDPROC .
|
|
|
|
|
i can see one message WM_ENTERMENULOOP that sends to menu, but i don't see any messages of mouse sent to menu, how can i hook these message
|
|
|
|
|
sunen wrote: for example, the short-cut menu on the desktop
What exactly do you mean by this, the start menu or the context menu (right-click)?
|
|
|
|
|
aha, what i want is the context menu, thank you
|
|
|
|
|
sunen wrote: what i want is the context menu
In that case I think you may have to hook the WM_CONTEXTMENU message. See the MSDN docuentation for more details.
|
|
|
|
|
i have seen the msdn, but i still have no idea to implement it , can you give me some tips, thank you very much
|
|
|
|
|
maybe i need clear what i exactly want?
the scene:
i have right-clicked on the desktop,
so i receive the WM_CONTEXTMENU message and get one short-cut menu,
now i am operating mouse and produce some message,
for example, WM_MOUSEMOVE, WM_LBUTTONDOWN, and so on,
the key point is how can i hook these message?
|
|
|
|
|
You need to use the SetWindowsHookEx()[^] function to monitor the messages going through the system, then activate whatever you need when you see the message that you are interested in. The following CodeProject Article[^] explains how you can utilise this feature.
|
|
|
|
|
Hello,
I am trying to create a trim function for char pointer. The lTrim can work perfectly. But, run time error occurs at rTrim.
Below is the error msg :
"Unhandled exception at 0x00411b37 in Test2.exe: 0xC0000005: Access violation writing location 0x00418cf7."
Full code provided below :
<code>
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
int isspace ( char c );
char * lTrim ( char * p );
char * rTrim ( char * p );
char * Trim( char * p );
int isspace ( char c )
{
return c == ' ' || c == '\t' ||
c == '\v' || c == '\f' ;
}
char * lTrim ( char * p )
{
while ( p && isspace(*p) ) ++p ;
return p ;
}
char * rTrim ( char * p )
{
char * temp = 0;
if (!p) return p;
temp = (char *)(p + strlen(p)-1);
while ( (temp>=p) && isspace(*temp) ) --temp;
*(temp+1) = '\0';
return p;
}
char * Trim( char * p )
{
return lTrim(rTrim(p));
}
int main()
{
char * str = " This is utterly brilliant ";
printf(">>%s<<\n", str);
str = Trim(str);
printf(">>%s<<\n", str);
getch();
return 0;
}
</code>
Your guidance on solving this problem is very much appreciated.
Thanks,
Goutam
|
|
|
|
|
Try changing char* str in the main function to char str[]
|
|
|
|
|
Hello Superman,
Thanks for trying.
It does not work. It has to be char * at the main.
The run time error occurs when I am writing memory location at rTrim.
|
|
|
|
|
char * str = " This is utterly brilliant ";
i think this sentence makes error, in that the pointer str is pointing to a constant string, so it can't modified by any way
you can test your method by following code:
char str[256] = {0};
snprintf(str, 256, "%s", " This is utterly brilliant ");
modified on Tuesday, December 1, 2009 2:38 AM
|
|
|
|
|
Try calling:
char str[256];
strcpy_s( str, " This is utterly brilliant " );
instead of:
char * str = " This is utterly brilliant ";
EDIT: I think this is what «_Superman_» was trying to suggest also
|
|
|
|
|
Constant strings cannot be modified. You can try as follows:
char * str = " This is utterly brilliant ";
char* s = _strdup(str);
printf(">>%s<<\n", s);
str = Trim(s);
printf(">>%s<<\n", s);
free(s);
getch();
|
|
|
|
|
Thank you very much.
Using "char * s = _strdup(str);" solved my problem.
Thanks for everyone who tried.
|
|
|
|
|
ggoutam7 wrote: char * lTrim ( char * p )
{
while ( p && isspace(*p) ) ++p ;
return p ;
}
Although this loop works it is slightly flawed in concept. The first part should check whether you have reached the end of the string thus:
while ( *p && isspace(*p) ) ++p ;
|
|
|
|
|
Thank you very much.
With the amendments, it works better.
cheers,
Goutam
|
|
|
|
|
Happy to help, good luck with your programming.
|
|
|
|
|
I couldn't understand the following things:
1) What's HANDLE and what function is it doing in this program?
2) When i run the prog, it gives an error message that "Expected initiliazer before int"? How to remove it? I have tried using int main(void) but no effect so far...
#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<process.h>
// Second Thread Funtion
void ThreadProc(void *param)
//First thread
int main(){
int n,i,val=0;
HANDLE handle;
printf("\t Thread Demo\n");
printf("Enter the number of threads: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
val=i;
handle=(HANDLE)_beginthread(ThreadProc,0,&val); //create thread
WaitForSingleObject(handle,INFINITE);
}
return 0;
}
void ThreadProc(void *param)
{
int h=*((int*)param);
printf("%d Thread is running! \n",h);
_endthread();
}
|
|
|
|
|
Is the error compile time or run time?
In which line of code does the error occur?
|
|
|
|
|
1) HANDLE represents an instance of the thread. WaitForSingleObject function is waiting on this thread handle until the thread execution is finished.
2) Looks like a semicolon(;)is missing after the declaration of ThreadProc(). Moreover, the #include statements are not complete.
|
|
|
|
|
hi, guys
I am newer to MFC and have a question here
----------------
| |
| |
| A |
|_______________|
| |
| B |
|_______________|
Area A and B is two zones, I have a Button in A, and if i click the button, B disappears, showing below, only A; if i click the button again, B shows like above pic
----------------
| |
| |
| A |
|_______________|
my question is how to implenment this function? could you guys give me some idea? thank you very much
|
|
|
|