htmlgui32.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
|
![]() |
![]() |
HTML2POP3 |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
| Metric | Description | |
|---|---|---|
/*
* HTML2POP3 server - win32 gui
*
* Copyright 2004 Matteo Baccan
* www - http://www.baccan.it
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
* their web site at http://www.gnu.org/).
*
*/
/**
* Title: WIN32 gui
* Description: Server POP3
* Copyright: Copyright (c) 2004
* Company:
* @author Matteo Baccan
* @version 1.0
*/
import com.ms.wfc.core.Event;
import com.ms.wfc.core.EventHandler;
import com.ms.dll.*;
import com.ms.wfc.ui.*;
import org.html2pop3.utils.*;
/** @dll.import(auto) */
public class htmlgui32 {
public static int IDI_ICON = 10;
public static void main(String args[]){
// Abilito il log su file
logStreamMemo psm = new logStreamMemo( System.out, "html2pop3.log" );
System.setOut( psm );
System.setErr( psm );
// Imposto l'eventuale config
html2pop3.parseCommandLine( args );
// Lancio il server
html2pop3 html2pop3 = new html2pop3();
html2pop3.start();
int hicon = LoadIcon(0, IDI_EXCLAMATION);
// Note: passing in a root address rather than BreakHandler itself.
// That's to prevent BreakHandler from being garbage-collected
// as soon as SetConsoleCtrlHandler returns.
SetConsoleCtrlHandler(DllLib.addrOf(Root.alloc(new BreakHandler())), true);
// Window class
WNDCLASS wndclass = new WNDCLASS();
wndclass.lpfnWndProc = DllLib.addrOf(TBarWndProcRoot);
wndclass.lpszClassName = "htmlgui32";
if (0 == RegisterClass(wndclass)) {
throw new RuntimeException("RegisterClass failed.");
}
m_hwnd = CreateWindow(wndclass.lpszClassName,
"htmlgui32",
WS_OVERLAPPEDWINDOW,
0,0,
0,0,
0, 0, 0, 0);
if (0 == m_hwnd) {
throw new RuntimeException("CreateWindow failed.");
}
NOTIFYICONDATA nid = new NOTIFYICONDATA();
nid.hWnd = m_hwnd;
nid.uID = 1;
nid.uFlags = nid.NIF_MESSAGE|nid.NIF_ICON|nid.NIF_TIP;
nid.uCallbackMessage = WM_HTMLGUI32;
nid.hIcon = hicon;
//nid.hIcon = LoadIcon(0, 1);
//nid.hIconSm = LoadImage(0, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON,
//nid.hIcon = LoadImage(0, IDI_ICON, IMAGE_ICON,
//GetSystemMetrics(SM_CXSMICON),
//GetSystemMetrics(SM_CYSMICON), 0);
//nid.hIcon = LoadImage(0, IDI_ICON, IMAGE_ICON, 0, 0, 0);
nid.szTip = "HTML2POP3 " +version.getVersion() +" su " +html2pop3.getHost() +":" +html2pop3.getPort() +"/" +html2pop3.getPortSMTP() +"/" +html2pop3.getPortNNTP() +". Click destro per uscire";
if (!Shell_NotifyIcon(NIM_ADD, nid)) {
throw new RuntimeException("Could not add taskbar icon.");
}
m_fTBarIconActive = true;
// Ciclo dei messaggi
MSG msg = new MSG();
while (GetMessage(msg, 0, 0, 0)) {
TranslateMessage(msg);
DispatchMessage(msg);
}
}
static int m_hwnd;
static boolean m_fTBarIconActive = false;
static void destroyTBarIcon()
{
if (m_fTBarIconActive) {
m_fTBarIconActive = false;
NOTIFYICONDATA nid = new NOTIFYICONDATA();
nid.hWnd = m_hwnd;
nid.uID = 1;
nid.uFlags = nid.NIF_ICON;
Shell_NotifyIcon(NIM_DELETE, nid);
}
}
static final int TBarWndProcRoot = Root.alloc(new TBarWndProc());
static final int WM_HTMLGUI32 = 0x500;
/** @dll.import("KERNEL32") */
static native boolean SetConsoleCtrlHandler(int pHandlerRoutine,
boolean fAdd);
/** @dll.import("SHELL32") */
static native boolean Shell_NotifyIcon(int dwMsg, NOTIFYICONDATA pnid);
static final int NIM_ADD = 0x00000000;
static final int NIM_MODIFY = 0x00000001;
static final int NIM_DELETE = 0x00000002;
/** @dll.import("USER32") */
static native int LoadIcon(int hinstance, int iconid);
static final int IDI_EXCLAMATION = 32516;
//static final int IDI_EXCLAMATION = 32515;
static final int IDI_APPLICATION = 32512;
/** @dll.import("USER32") */
static native boolean GetMessage(MSG msg,
int hwnd,
int uMsgFilterMin,
int uMsgFilterMax);
/** @dll.import("USER32") */
static native boolean TranslateMessage(MSG msg);
/** @dll.import("USER32") */
static native int DispatchMessage(MSG msg);
/** @dll.import("USER32") */
static native int RegisterClass(WNDCLASS wc);
/** @dll.import("USER32") */
static native int CreateWindowEx(int dwExStyle,
String lpszClassName,
String lpszWindowName,
int style,
int x,
int y,
int nWidth,
int nHeight,
int hwndParent,
int hMenu,
int hInst,
int pvParam);
static int CreateWindow(String lpszClassName,
String lpszWindowName,
int style,
int x,
int y,
int nWidth,
int nHeight,
int hwndParent,
int hMenu,
int hInst,
int pvParam)
{
return CreateWindowEx(0, lpszClassName, lpszWindowName, style,
x, y, nWidth, nHeight, hwndParent, hMenu, hInst,
pvParam);
}
static final int WS_OVERLAPPEDWINDOW = 0x00CF0000;
}
//===================================================================
// Callback to receive window messages from the Taskbar Icon.
//===================================================================
/** @dll.import(auto) */
class TBarWndProc extends Callback
{
static final int WM_DESTROY = 0x0002;
static final int WM_LBUTTONDOWN = 0x0201;
static final int WM_LBUTTONUP = 0x0202;
static final int WM_LBUTTONDBLCLK = 0x0203;
static final int WM_RBUTTONDOWN = 0x0204;
static final int WM_RBUTTONUP = 0x0205;
static final int WM_RBUTTONDBLCLK = 0x0206;
public int callback(int hwnd, int message, int wParam, int lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case htmlgui32.WM_HTMLGUI32:
{
switch (lParam) {
case WM_LBUTTONDOWN:
//System.out.println("Left button clicked.....................");
//ContextMenu treePopup = new ContextMenu();
//treePopup.addOnPopup(new EventHandler(this.processTreePopup));
//treePopup.show(null,new Point(105, 103));
//MessageBox.show("This is my message", "Title!", MessageBox.YESNO);
//java.awt.PopupMenu p = new java.awt.PopupMenu( "xiao" );
//System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
//p.add("1");
//System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
//p.show(null,100,100);
//System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
break;
case WM_LBUTTONDBLCLK:
break;
case WM_RBUTTONDOWN:
//if( MessageBox.show("Vuoi uscire dal programma?\nUscendo non potrai piu scaricare la posta", "Uscita da HTML2POP3 " +version.getVersion() +" win32", MessageBox.YESNO)==DialogResult.YES ){
MsgBox messagebox = new MsgBox("Uscita da HTML2POP3 " +version.getVersion() +" win32" , "Vuoi uscire dal programma? Uscendo non potrai piu scaricare la posta", true);
//if( MessageBox.show("Vuoi uscire dal programma?\nUscendo non potrai piu scaricare la posta", "Uscita da HTML2POP3 " +version.getVersion() +" win32", MessageBox.YESNO)==DialogResult.YES ){
if( messagebox.id ){
htmlgui32.destroyTBarIcon();
System.exit(0);
}
break;
case WM_RBUTTONDBLCLK:
break;
}
}
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
/** @dll.import("USER32") */
static native void PostQuitMessage(int nExitCode);
/** @dll.import("USER32") */
static native int DefWindowProc(int hwnd, int msg, int wParam, int lParam);
}
//===================================================================
// Handler for ctrl-C.
//===================================================================
/** @dll.import(auto) */
class BreakHandler extends Callback
{
static final int CTRL_C_EVENT = 0;
static final int CTRL_BREAK_EVENT = 1;
public boolean callback(int ctrlType)
{
if (ctrlType == CTRL_C_EVENT || ctrlType == CTRL_BREAK_EVENT) {
htmlgui32.destroyTBarIcon();
return false;
}
return false;
}
/** @dll.import("USER32") */
static native void PostQuitMessage(int nExitCode);
}
/** @dll.struct(auto) */
class NOTIFYICONDATA
{
public int cbSize = DllLib.sizeOf(getClass());
public int hWnd;
public int uID;
public int uFlags;
public int uCallbackMessage;
public int hIcon;
/** @dll.structmap([type=TCHAR[64]]) */
public String szTip;
static public final int NIF_MESSAGE = 0x00000001;
static public final int NIF_ICON = 0x00000002;
static public final int NIF_TIP = 0x00000004;
}
/** @dll.struct(auto) */
class WNDCLASS
{
int style;
int lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
int hInstance;
int hIcon;
int hCursor;
int hbrBackground;
String lpszMenuName;
String lpszClassName;
}
/** @dll.struct(auto) */
class MSG
{
int hwnd;
int message;
int wParam;
int lParam;
int time;
int ptx;
int pty;
}
The table below shows all metrics for htmlgui32.java.
| Metric | Value | Description | |
|---|---|---|---|


