-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistenurl.c
87 lines (70 loc) · 2.23 KB
/
listenurl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "trayicon.h"
#include "network.h"
#include "shellapi.h"
#define SOCKET_MESSAGE (WM_APP + 100)
void on_close_listener( HWND );
LRESULT app_window_proc( HWND, UINT, WPARAM, LPARAM );
// Entry point
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE prev, LPSTR cmdline, int show )
{
HWND hWnd;
MSG msg;
BOOL bRet;
// Detect previous instance, and bail if there is one.
if ( FindWindow( THIS_CLASSNAME, THIS_TITLE ) )
return 0;
// We have to have a window, even though we never show it. This is
// because the tray icon uses window messages to send notifications to
// its owner. Starting with Windows 2000, you can make some kind of
// "message target" window that just has a message queue and nothing
// much else, but we'll be backwardly compatible here.
RegisterApplicationClass( hInst );
hWnd = CreateWindow( THIS_CLASSNAME, THIS_TITLE,
0, 0, 0, 100, 100, NULL, NULL, hInst, NULL );
if ( ! hWnd ) {
MessageBox( NULL, _T("Ack! I can't create the window!"), THIS_TITLE,
MB_ICONERROR | MB_OK | MB_TOPMOST );
return 1;
}
app_close_listener = &on_close_listener;
WindowProc_fallback = &app_window_proc;
network_start( hWnd, SOCKET_MESSAGE );
// Message loop
while ( TRUE ) {
bRet = GetMessage( &msg, NULL, 0, 0 );
if ( bRet == 0 || bRet == -1)
break;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
UnregisterClass( THIS_CLASSNAME, hInst );
return msg.wParam;
}
void on_close_listener( HWND hWnd )
{
network_stop();
}
HINSTANCE invoke_url(LPCTSTR url) {
return ShellExecute(NULL, _T("open"), _T("invoke-url.js"), url, NULL, SW_SHOWNORMAL );
}
LRESULT app_window_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
case SOCKET_MESSAGE:
switch(WSAGETSELECTEVENT(lParam))
{
case FD_ACCEPT:
network_accept();
return 0;
case FD_READ:
network_recv_invoke(wParam, &invoke_url);
return 0;
}
MessageBox( NULL, _T("This aint right..."), THIS_TITLE,
MB_ICONERROR | MB_OK | MB_TOPMOST );
return -1;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
}