Skip to content

Commit

Permalink
PSOI2:
Browse files Browse the repository at this point in the history
Changed the logic test connectivity clients;
Imaging the logo in splash screen moved on resources;
Fix: now, the application icon is removed from the system tray on WM_DESTROY;

git-svn-id: http://frl.googlecode.com/svn/trunk@159 daf5c975-553e-0410-8cda-3135a9dfd8f3
  • Loading branch information
gmist committed Dec 8, 2008
1 parent 470e3b8 commit 9ff1356
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
2 changes: 2 additions & 0 deletions projects/opc/psoi2/include/global_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace global_var

extern const int height;
extern const int width;

extern bool is_minimized;
}

extern Bool exit_if_all_client_disconnected;
Expand Down
3 changes: 2 additions & 1 deletion projects/opc/psoi2/resource/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ IDB_FRL_LOGO BITMAP "bitmaps\\logo_text.bmp"

IDD_SPLASH_DIALOG DIALOGEX 0, 0, 150, 75
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_SYSMENU
EXSTYLE WS_EX_TOPMOST
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_SPLASH_IMAGE,"Static",SS_BITMAP | SS_CENTERIMAGE,5,5,140,65
CONTROL 104,IDC_SPLASH_IMAGE,"Static",SS_BITMAP | SS_CENTERIMAGE,5,5,140,65
END

IDD_ABOUT_DIALOG DIALOGEX 0, 0, 178, 180
Expand Down
2 changes: 2 additions & 0 deletions projects/opc/psoi2/src/global_var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace global_var

const int height = 425;
const int width = 225;

bool is_minimized = false;
}
Bool exit_if_all_client_disconnected = False;
std::map< HTREEITEM, ChannelDescr > channels_map;
Expand Down
59 changes: 44 additions & 15 deletions projects/opc/psoi2/src/main_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define WM_MENU_ABOUT (WM_APP) + 201
#define WM_MENU_EXIT (WM_APP) + 202
#define TM_CHECK_CN (WM_APP) + 401
#define TM_CHECK_CN_LONG (WM_APP) + 402

// Helper for adding items to menu
BOOL createMenuHelper( HMENU menu_handle, frl::Char *data, UINT pos, UINT id, HMENU sub_menu, UINT type )
Expand Down Expand Up @@ -45,10 +46,17 @@ void systrayIconHelper( HINSTANCE hinstance, HWND hwnd, bool add )
nid.hIcon = LoadIcon( hinstance, MAKEINTRESOURCE(IDI_ICON_MAIN) );
lstrcpy( nid.szTip,TEXT("Double-click to maxmize!") );

if( add )
if( add && ! global_var::main_wnd::is_minimized )
{
global_var::main_wnd::is_minimized = true;
::Shell_NotifyIcon( NIM_ADD, &nid );
else
}

if( ! add && global_var::main_wnd::is_minimized )
{
global_var::main_wnd::is_minimized = false;
::Shell_NotifyIcon( NIM_DELETE, &nid );
}
}

// Helper for create tree view with channels list
Expand Down Expand Up @@ -179,24 +187,35 @@ BOOL initInstance( HINSTANCE hInstance, int nCmdShow )

LRESULT CALLBACK mainFunc( HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param )
{
static bool is_client_connected = false;

switch( msg )
{
case WM_TIMER:
{
// if clients no connected
if( w_param == TM_CHECK_CN_LONG )
{
::KillTimer( hwnd, TM_CHECK_CN_LONG );
::SendMessage( hwnd, WM_DESTROY, 0, 0 );
}

// checking connection of clients
if( w_param == TM_CHECK_CN )
{
static bool is_first_run = true;

if( is_first_run ) // after wait first connection
if( ! is_client_connected )
{
::KillTimer( hwnd, TM_CHECK_CN ); // clean up long checking timer
is_first_run = false;
::SetTimer( hwnd, TM_CHECK_CN, 2000, (TIMERPROC)NULL ); // and set short checking time
if( frl::opc::factory.isServerInUse() )
{
is_client_connected = true;
::KillTimer( hwnd, TM_CHECK_CN_LONG );
}
}
else
{
if( ! frl::opc::factory.isServerInUse() )
::SendMessage( hwnd, WM_DESTROY, 0, 0 );
}

if( ! frl::opc::factory.isServerInUse() )
SendMessage( hwnd, WM_DESTROY, 0, 0 );
}
}
break; // WM_TIMER
Expand All @@ -205,8 +224,8 @@ LRESULT CALLBACK mainFunc( HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param )
{
if( w_param == SIZE_MINIMIZED )
{
systrayIconHelper( global_var::main_wnd::h_instance, hwnd, true );
::ShowWindow( hwnd, SW_HIDE );
systrayIconHelper( global_var::main_wnd::h_instance, hwnd, true );
}
}
break; // WM_SIZE
Expand Down Expand Up @@ -265,8 +284,15 @@ LRESULT CALLBACK mainFunc( HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param )

case WM_DESTROY:
{
if( global_var::exit_if_all_client_disconnected ) // if checked client connections
::KillTimer( hwnd, TM_CHECK_CN ); // clean up timer
if( global_var::exit_if_all_client_disconnected )
{
::KillTimer( hwnd, TM_CHECK_CN );
if( ! is_client_connected )
::KillTimer( hwnd, TM_CHECK_CN_LONG );
}

// remove icon from system tray
systrayIconHelper( global_var::main_wnd::h_instance, hwnd, false );

::PostQuitMessage( 0 );
return 0;
Expand Down Expand Up @@ -319,5 +345,8 @@ void createCheckConnectionTimer()
{
HWND hwnd = ::FindWindow( global_var::main_wnd::class_name, global_var::main_wnd::title );
if( hwnd )
::SetTimer( hwnd, TM_CHECK_CN, 20000, (TIMERPROC)NULL );
{
::SetTimer( hwnd, TM_CHECK_CN, 2000, (TIMERPROC)NULL ); // check connection status every 2 sec
::SetTimer( hwnd, TM_CHECK_CN_LONG, 20000, (TIMERPROC)NULL ); // wait 20 sec for first connection
}
}
3 changes: 0 additions & 3 deletions projects/opc/psoi2/src/splash_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ BOOL CALLBACK splashFunc( HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param )

case WM_INITDIALOG:
{
bit_map_handle = ::LoadBitmap( global_var::main_wnd::h_instance, MAKEINTRESOURCE( IDB_SPLASH ) );
HWND img_static_hwnd = ::GetDlgItem( hwnd, IDC_SPLASH_IMAGE );
::SendMessage( img_static_hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bit_map_handle );
::SetTimer( hwnd, ID_SPLASH_TIMER, 2000, (TIMERPROC)NULL );
}
break;
Expand Down

0 comments on commit 9ff1356

Please sign in to comment.