![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: May 2005
Location: ma
Posts: 130
Rep Power: 4
![]() |
How to make a message pop up when a program starts in windows.
Hi im trying to write a small little program that will have a message start up when a particular program starts. I think it wouldn't be too complicated, but thought so of other projects then you get into and realize it seemed easy because you didn't think of everything. lol. the problem is i am a *nix user so don't know much of windows programming. I am familar with GTK so that is what i'll probably use to try to generate the window - unless there is something windows native to windows that would be simpler. This is how i think it would have to work. The program would sleep till it recieved a signal from the particular program then execute to display the window. (Pretty new to programming so sorry if that isn't even near correct and sounds retarded. lol) Im not even sure what to google for to look for help - also i didn't know how helpful microsoft is to amateur/hobbyist programmers. thanks for any help in advance.
|
|
|
|
|
|
#2 | |
|
Professional Programmer
|
Quote:
One way I could think of doing this at the moment is by editing the program you're launching to open up the dialog and then recompile it. However, I'm guessing that's not an option. The only other way is by starting a program that looks for the window handle or process ID of the other program, and launches when it finds it. However, that takes a lot of resources. What exactly are you trying to do, i.e, what program and what message are you wanting to display?
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: May 2005
Location: ma
Posts: 130
Rep Power: 4
![]() |
well i want the program to trigger when yahoo messenger starts up. My parents think she chats too much so i want the message to say like "Why don't you take a walk" or something to try to encourage her to get off because she won't listen to my parents and if we delete yahoo she will install it again and if we block her from installing it she will get pissed and it will make living with her even more of a pain. They can't really ground her - she is in her 30's. At the very least maybe the pop up every time she wants to get on would be enough of an annoyance for her to not want to go on as much. I don't know about you but i'd start thinking more about doing something when even my computer starts to nag me!
|
|
|
|
|
|
#4 |
|
Professional Programmer
|
Well in that case, you could also do some grungy socket work to keep track of how many times the program accesses the Yahoo Messenger protocol, and after a while pop up a message. This can also be tweaked to how long she's been on the internet in general.
A bit higher level would be to set up a bot to send messages to her screen name every once in a while and ask her to do something else, but the user can just be blocked I'm sure. I don't know if these answers are what you're looking for, as I'm not a seasoned windows programmer either. But each one of them should work in its own way.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: May 2005
Location: ma
Posts: 130
Rep Power: 4
![]() |
yeah i thought of ways to extend it as well. For instance i know they have those taskbar programs that display the current temp as given by weather.com or something. I could have it check that and only to display the message "Try taking a walk" if it is over a certain degree and if under say "Try reading a book" But i'll be luckily to get a message to work. lol
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
if she's in her 30's...why does anyone care?
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
You can probably make a program that sits in the backgrounds and enumerates all the open windows every few seconds and then checks if messenger is running by looking at the title bar text. and then displaying a pop-up window.
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#8 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Here is a small Win32 App that checks(every 10 sec) for windows having title bar text Yahoo! and displays a Message box if it finds one. It's "quick and dirty".
#include<windows.h>
BOOL CALLBACK EnumProc(HWND parent,LPARAM l);
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
int _stdcall WinMain(HINSTANCE i,HINSTANCE j,LPSTR k,int l)
{
WNDCLASS wc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=i;
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.lpszClassName="myclass";
wc.lpszMenuName=NULL;
wc.style = CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wc);
HWND hwnd;
hwnd = CreateWindow("myclass","Timer Demo",WS_OVERLAPPEDWINDOW|WS_MAXIMIZE,
CW_USEDEFAULT,CW_USEDEFAULT,400,400,NULL,NULL,NULL,NULL);
//ShowWindow(hwnd,SW_SHOWNORMAL);
SetTimer(hwnd,1,10000,NULL);
MSG msg;
while(GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
switch(msg)
{
case WM_TIMER:
EnumWindows(EnumProc,0);
break;
default:
return DefWindowProc(hwnd,msg,wparam,lparam);
}
return 0L;
}
BOOL CALLBACK EnumProc(HWND hwnd,LPARAM l)
{
char buff[100];
GetWindowText(hwnd,buff,100);
if(strncmp(buff,"Yahoo!",6)==0)
MessageBox(NULL,"Try taking a walk","Hello",MB_OK);
return TRUE;
}HTH
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
|
Could you please explain to me why in the hell you took the time to create a window and set up a timer when in a lot less code you could have simply done a Sleep(); call inside a while loop?
Using a program like SPY++, you can find the windows simply by doing something similar to this as I have done with AOL Messenger. Once you do that it will take you to a scroll down box in which case you can right click and select 'messages' to monitor messages sent to the window. If you notice, you can indeed see a lot of messages being sent, try diagnosing these. When you find one, in my case I have chosen the WM_COMMAND message, and I have seen that when you log onto AIM, a EN_KILLFOCUS message is sent in coordnance. (When a WM_COMMAND message is sent you can switch off the high and low bytes of both lParam and wParam of a window proc to get additional information over a message such as which control a message came from. In this case, using MSDN I have deduced that if a WM_COMMAND message is sent I can see if a EN_KILLFOCUS message is sent by looking at the high word of the wParam message, i.e. like this: if(HIWORD(wParam) == EN_KILLFOCUS) MessageBox(NULL,"Why not go outside?","You should.",MB_OK); Luckly, there is a special mechanism inside the Win32 API that allows you to spy on messages sent to a window: global hooks. By using a global hook of type WH_CALLWNDPROC, and if we specify 0 as the last parameter to SetWindowsHookEx, we can spy on all of the messages. Basically it includes these steps: Use a spy tool (SPY++ was used in my explaination) to spy on the Yahoo! IM program, monitor messages sent to the logon until you find one that looks a little out of the average (otherwise you'll get crazy amounts of message boxes), and then write a program that installs a WH_CALLWNDPROC hook on all programs, even ones spawned. Once that happens, it's as easy for checking for your message. I am deeply sorry if this confused you, but Windows is a whole different ballpark than Linux is, and it has a much tigher and very hierarchical API. I might be able to take an hour off sometime and try to explain this to you a little more (since I like to think I know a little more about windows than the average customer.) |
|
|
|
|
|
#10 | |||
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Quote:
Quote:
Quote:
![]()
__________________
PFO - My daily dose of technology. |
|||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|