bool KWindow::updateInsets() { /* * called by Menu assign to detect appropriate * client insets */ RECT rcl, rclc; GetClientRect( hwnd, &rclc); rcl.left = rclc.left; rcl.top = rclc.top; rcl.right = rclc.right; rcl.bottom = rclc.bottom; #if !defined(UNDER_CE) AdjustWindowRectEx( &rclc, GetWindowLong( hwnd, GWL_STYLE), (GetMenu( hwnd) != NULL), 0); #else AdjustWindowRectEx( &rclc, GetWindowLong( hwnd, GWL_STYLE), 0, 0); if ( hbar ) rclc.top += CommandBar_Height( hbar); #endif setInsets( rcl.left-rclc.left, rcl.top-rclc.top, rclc.right-rcl.right, rclc.bottom-rcl.bottom, false ); return TRUE; }
/* for pocket PC, this is zero, as it is not in the client area */ WCECOMPAT_API int __cdecl wceGetCommandBarHeight(HWND hWndCmdBar) { #ifdef POCKETPC_MENUS return 0; #else return CommandBar_Height(hWndCmdBar); #endif }
LRESULT CLogView::OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) { #if defined(OS_WINDOWS) if (m_grip.GetSafeHwnd()) { m_grip.UpdateGripPos(); } ::MoveWindow( GetDlgItem(IDC_LOGEDIT), 0,0, LOWORD(lParam), HIWORD(lParam), TRUE ); #else ::MoveWindow( GetDlgItem(IDC_LOGEDIT), 0,CommandBar_Height( m_hWndCommandBar ), LOWORD(lParam), HIWORD(lParam), TRUE ); #endif return 0; }
/*---------------------------------------------------------------------------*\ | | \*---------------------------------------------------------------------------*/ void OnSize(HWND hwnd, UINT state, int cx, int cy) { int cxBorder, cyBorder; int x, y, cxWidth, cyHeight; cxBorder = GetSystemMetrics (SM_CXBORDER); cyBorder = GetSystemMetrics (SM_CYBORDER); x = 0 - cxBorder; // y = 0 - cyBorder + CommandBar_Height(hwndCB); int cyBarHeight = CommandBar_Height(hwndCB); y = 0 = cyBorder + cy +cyBarHeight; cxWidth = cx + cxBorder; cyHeight = cy + cyBorder; SetWindowPos (hwndEdit, 0, x, y, cxWidth, cyHeight, 0); }
/*---------------------------------------------------------------------------*\ | | \*---------------------------------------------------------------------------*/ void OnPaint(HWND hwnd) { HDC hdc; PAINTSTRUCT ps; RECT rClient; hdc = BeginPaint (hwnd, &ps); if (pData) { GetClientRect(hwnd, &rClient); rClient.top = CommandBar_Height(hwndCB); DrawText(hdc, pData, -1, &rClient, DT_WORDBREAK); } EndPaint (hwnd, &ps); }
/*---------------------------------------------------------------------------*\ | | \*---------------------------------------------------------------------------*/ BOOL OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct) { HDC hdc; TEXTMETRIC tm; // Setup the HPC command bar. hwndCB = CommandBar_Create(hInst, hWnd, 1); CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0); CommandBar_AddAdornments(hwndCB, 0, 0); hdc = GetDC (hWnd); GetTextMetrics (hdc, &tm); xMargin = tm.tmAveCharWidth; yMargin = tm.tmHeight / 2 + CommandBar_Height(hwndCB); ReleaseDC (hWnd, hdc); return TRUE; }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; int wmId, wmEvent, nCmdHt; PAINTSTRUCT ps; RECT textRect; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_HELP_ABOUT: DialogBox(g_hInst, (const ACE_TCHAR*)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDOK: SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd); SendMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_SETTING_RUN: { #ifdef NO_ACE cout << ACE_TEXT("START with command line: ") << g_CommandLine << endl; CE_ARGV ce_argv(g_CommandLine); main_i(ce_argv.argc(), ce_argv.argv()); cout << ACE_TEXT("END") << endl << endl; #else cout << ACE_TEXT("START with command line: ") << g_CommandLine << endl; ACE_ARGV ce_argv(g_CommandLine); ACE::init(); ACE_LOG_MSG->msg_callback(&cout); // register call back ACE_LOG_MSG->set_flags(ACE_Log_Msg::MSG_CALLBACK); // set call back flag ace_main_i(ce_argv.argc(), ce_argv.argv()); ACE::fini(); cout << ACE_TEXT("END") << endl << endl; #endif // NO_ACE } break; case ID_SETTING_EXIT: SendMessage(hWnd, WM_DESTROY, 0, 0); break; case ID_TOOLS_SAVETOFILE: // create a dialog box to get the file name DialogBox(g_hInst, (const ACE_TCHAR*)IDD_OUTFILE, hWnd, (DLGPROC)SaveFileName); break; case ID_SETTING_COMMANDLINE: // create a dialog box to get the command line DialogBox(g_hInst, (const ACE_TCHAR*)IDD_CMDLINE, hWnd, (DLGPROC)CommandLine); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: SHMENUBARINFO mbi; memset(&mbi, 0, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hWnd; mbi.nToolBarId = IDM_MENU; mbi.hInstRes = g_hInst; mbi.nBmpId = 0; mbi.cBmpImages = 0; if (!SHCreateMenuBar(&mbi)) return 0; g_hwndCB = mbi.hwndMB; // Initialize the shell activate info structure memset (&s_sai, 0, sizeof (s_sai)); s_sai.cbSize = sizeof (s_sai); GetClientRect(hWnd, &textRect); nCmdHt = CommandBar_Height(mbi.hwndMB); hWndEdit = CreateWindow(ACE_TEXT("EDIT"), 0, WS_CHILD | WS_VISIBLE | ES_READONLY | ES_MULTILINE | WS_VSCROLL | WS_HSCROLL, 0, 0, textRect.right, textRect.bottom - MENU_HEIGHT, hWnd, 0, g_hInst, 0); cout.SetOutputWindow(hWndEdit); LoadParameterHistory(); break; case WM_PAINT: RECT rt; hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rt); EndPaint(hWnd, &ps); break; case WM_ACTIVATE: // Notify shell of our activate message SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE); break; case WM_SETTINGCHANGE: SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai); break; case WM_HIBERNATE: // low power case WM_CLOSE: case WM_DESTROY: g_Parameter.saveParameter(); // save parameters to history file CommandBar_Destroy(g_hwndCB); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/* adjust windows to fit main window layout --------------------------- | Status | +-------------------------+ | | | | | MAP | | | | | +-------------------------+ | Command pad | +-------------------------+ | Messages | --------------------------- */ void mswin_layout_main_window(HWND changed_child) { winid i; RECT client_rt, wnd_rect; POINT status_org; SIZE status_size; POINT msg_org; SIZE msg_size; POINT map_org; SIZE map_size; POINT cmd_org; SIZE cmd_size; HWND wnd_status, wnd_msg; PNHMainWindow data; #if defined(WIN_CE_POCKETPC) SIPINFO sip; RECT menu_bar; RECT visible_rt; POINT pt; #endif GetClientRect(GetNHApp()->hMainWnd, &client_rt); #if defined(WIN_CE_POCKETPC) ZeroMemory(&sip, sizeof(sip)); sip.cbSize = sizeof(sip); SHSipInfo(SPI_GETSIPINFO, 0, &sip, 0); if (GetNHApp()->bFullScreen) sip.rcVisibleDesktop.top = 0; /* adjust client rectangle size */ GetWindowRect(GetNHApp()->hMenuBar, &menu_bar); client_rt.bottom -= menu_bar.bottom - menu_bar.top; /* calcuate visible rect in client coordinates */ pt.x = sip.rcVisibleDesktop.left; pt.y = sip.rcVisibleDesktop.top; ScreenToClient(GetNHApp()->hMainWnd, &pt); SetRect(&wnd_rect, pt.x, pt.y, pt.x + sip.rcVisibleDesktop.right - sip.rcVisibleDesktop.left, pt.y + sip.rcVisibleDesktop.bottom - sip.rcVisibleDesktop.top); IntersectRect(&visible_rt, &client_rt, &wnd_rect); #else #if !defined(WIN_CE_SMARTPHONE) client_rt.top += CommandBar_Height(GetNHApp()->hMenuBar); #else /* Smartphone only */ if (GetNHApp()->bFullScreen) { RECT menu_bar; GetWindowRect(GetNHApp()->hMenuBar, &menu_bar); client_rt.bottom -= menu_bar.bottom - menu_bar.top; } #endif #endif /* get window data */ data = (PNHMainWindow) GetWindowLong(GetNHApp()->hMainWnd, GWL_USERDATA); /* get sizes of child windows */ wnd_status = mswin_hwnd_from_winid(WIN_STATUS); if (IsWindow(wnd_status)) { mswin_status_window_size(wnd_status, &status_size); } else { status_size.cx = status_size.cy = 0; } wnd_msg = mswin_hwnd_from_winid(WIN_MESSAGE); if (IsWindow(wnd_msg)) { mswin_message_window_size(wnd_msg, &msg_size); } else { msg_size.cx = msg_size.cy = 0; } cmd_size.cx = cmd_size.cy = 0; if (GetNHApp()->bCmdPad && IsWindow(GetNHApp()->hCmdWnd)) { mswin_command_window_size(GetNHApp()->hCmdWnd, &cmd_size); } /* set window positions */ /* calculate the application windows size */ #if defined(WIN_CE_POCKETPC) SetRect(&wnd_rect, visible_rt.left, visible_rt.top, visible_rt.right, visible_rt.bottom); if (sip.fdwFlags & SIPF_ON) cmd_size.cx = cmd_size.cy = 0; /* hide keypad window */ #else SetRect(&wnd_rect, client_rt.left, client_rt.top, client_rt.right, client_rt.bottom); #endif #if !defined(WIN_CE_SMARTPHONE) /* other ports have it at the bottom of the screen */ cmd_size.cx = (wnd_rect.right - wnd_rect.left); cmd_org.x = wnd_rect.left; cmd_org.y = wnd_rect.bottom - cmd_size.cy; wnd_rect.bottom -= cmd_size.cy; #endif /* status window */ switch (iflags.wc_align_status) { case ALIGN_LEFT: status_size.cx = (wnd_rect.right - wnd_rect.left) / 4; status_size.cy = (wnd_rect.bottom - wnd_rect.top); // that won't look good status_org.x = wnd_rect.left; status_org.y = wnd_rect.top; wnd_rect.left += status_size.cx; break; case ALIGN_RIGHT: status_size.cx = (wnd_rect.right - wnd_rect.left) / 4; status_size.cy = (wnd_rect.bottom - wnd_rect.top); // that won't look good status_org.x = wnd_rect.right - status_size.cx; status_org.y = wnd_rect.top; wnd_rect.right -= status_size.cx; break; case ALIGN_TOP: status_size.cx = (wnd_rect.right - wnd_rect.left); status_org.x = wnd_rect.left; status_org.y = wnd_rect.top; wnd_rect.top += status_size.cy; break; case ALIGN_BOTTOM: default: status_size.cx = (wnd_rect.right - wnd_rect.left); status_org.x = wnd_rect.left; status_org.y = wnd_rect.bottom - status_size.cy; wnd_rect.bottom -= status_size.cy; break; } /* message window */ switch (iflags.wc_align_message) { case ALIGN_LEFT: #if defined(WIN_CE_SMARTPHONE) /* smartphone has a keypad window on the right (bottom) side of the * message window */ msg_size.cx = cmd_size.cx = max(msg_size.cx, cmd_size.cx); msg_size.cy = (wnd_rect.bottom - wnd_rect.top) - cmd_size.cy; msg_org.x = cmd_org.x = wnd_rect.left; msg_org.y = wnd_rect.top; cmd_org.y = msg_org.y + msg_size.cy; #else msg_size.cx = (wnd_rect.right - wnd_rect.left) / 4; msg_size.cy = (wnd_rect.bottom - wnd_rect.top); msg_org.x = wnd_rect.left; msg_org.y = wnd_rect.top; #endif wnd_rect.left += msg_size.cx; break; case ALIGN_RIGHT: #if defined(WIN_CE_SMARTPHONE) /* smartphone has a keypad window on the right (bottom) side of the * message window */ msg_size.cx = cmd_size.cx = max(msg_size.cx, cmd_size.cx); msg_size.cy = (wnd_rect.bottom - wnd_rect.top) - cmd_size.cy; msg_org.x = cmd_org.x = wnd_rect.right - msg_size.cx; msg_org.y = wnd_rect.top; cmd_org.y = msg_org.y + msg_size.cy; #else msg_size.cx = (wnd_rect.right - wnd_rect.left) / 4; msg_size.cy = (wnd_rect.bottom - wnd_rect.top); msg_org.x = wnd_rect.right - msg_size.cx; msg_org.y = wnd_rect.top; #endif wnd_rect.right -= msg_size.cx; break; case ALIGN_TOP: #if defined(WIN_CE_SMARTPHONE) /* smartphone has a keypad window on the right side of the message * window */ msg_size.cy = cmd_size.cy = max(msg_size.cy, cmd_size.cy); msg_size.cx = (wnd_rect.right - wnd_rect.left) - cmd_size.cx; msg_org.x = wnd_rect.left; cmd_org.x = msg_org.x + msg_size.cx; msg_org.y = cmd_org.y = wnd_rect.bottom - msg_size.cy; #else msg_size.cx = (wnd_rect.right - wnd_rect.left); msg_org.x = wnd_rect.left; msg_org.y = wnd_rect.top; #endif wnd_rect.top += msg_size.cy; break; case ALIGN_BOTTOM: default: #if defined(WIN_CE_SMARTPHONE) /* smartphone has a keypad window on the right side of the message * window */ msg_size.cy = cmd_size.cy = max(msg_size.cy, cmd_size.cy); msg_size.cx = (wnd_rect.right - wnd_rect.left) - cmd_size.cx; msg_org.x = wnd_rect.left; cmd_org.x = msg_org.x + msg_size.cx; msg_org.y = cmd_org.y = wnd_rect.bottom - msg_size.cy; #else msg_size.cx = (wnd_rect.right - wnd_rect.left); msg_org.x = wnd_rect.left; msg_org.y = wnd_rect.bottom - msg_size.cy; #endif wnd_rect.bottom -= msg_size.cy; break; } map_org.x = wnd_rect.left; map_org.y = wnd_rect.top; map_size.cx = wnd_rect.right - wnd_rect.left; map_size.cy = wnd_rect.bottom - wnd_rect.top; /* go through the windows list and adjust sizes */ for (i = 0; i < MAXWINDOWS; i++) { if (GetNHApp()->windowlist[i].win && !GetNHApp()->windowlist[i].dead) { switch (GetNHApp()->windowlist[i].type) { case NHW_MESSAGE: MoveWindow(GetNHApp()->windowlist[i].win, msg_org.x, msg_org.y, msg_size.cx, msg_size.cy, TRUE); break; case NHW_MAP: MoveWindow(GetNHApp()->windowlist[i].win, map_org.x, map_org.y, map_size.cx, map_size.cy, TRUE); break; case NHW_STATUS: MoveWindow(GetNHApp()->windowlist[i].win, status_org.x, status_org.y, status_size.cx, status_size.cy, TRUE); break; case NHW_TEXT: case NHW_MENU: case NHW_RIP: { POINT menu_org; SIZE menu_size; menu_org.x = client_rt.left; menu_org.y = client_rt.top; #if defined(WIN_CE_POCKETPC) menu_size.cx = min(sip.rcVisibleDesktop.right - sip.rcVisibleDesktop.left, client_rt.right - client_rt.left); menu_size.cy = min(sip.rcVisibleDesktop.bottom - sip.rcVisibleDesktop.top, client_rt.bottom - client_rt.top); #else menu_size.cx = client_rt.right - client_rt.left; menu_size.cy = client_rt.bottom - client_rt.top; #endif #if defined(WIN_CE_SMARTPHONE) /* leave room for the command window */ if (GetNHApp()->windowlist[i].type == NHW_MENU) { menu_size.cy -= cmd_size.cy; } /* dialogs are popup windows unde SmartPhone so we need to convert to screen coordinates */ ClientToScreen(GetNHApp()->hMainWnd, &menu_org); #endif MoveWindow(GetNHApp()->windowlist[i].win, menu_org.x, menu_org.y, menu_size.cx, menu_size.cy, TRUE); } break; } ShowWindow(GetNHApp()->windowlist[i].win, SW_SHOW); InvalidateRect(GetNHApp()->windowlist[i].win, NULL, TRUE); } } if (IsWindow(GetNHApp()->hCmdWnd)) { /* show command window only if it exists and the game is ready (plname is set) */ if (GetNHApp()->bCmdPad && cmd_size.cx > 0 && cmd_size.cy > 0 && *plname) { MoveWindow(GetNHApp()->hCmdWnd, cmd_org.x, cmd_org.y, cmd_size.cx, cmd_size.cy, TRUE); ShowWindow(GetNHApp()->hCmdWnd, SW_SHOW); } else { ShowWindow(GetNHApp()->hCmdWnd, SW_HIDE); } } }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_HELP_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_FILE_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: hwndCB = CommandBar_Create(hInst, hWnd, 1); CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0); CommandBar_AddAdornments(hwndCB, 0, 0); break; case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hWnd, &ps); TEXTMETRIC tm; int x = 10; int y = CommandBar_Height(hwndCB); int cyLineHeight; GetTextMetrics(hdc, &tm); cyLineHeight = tm.tmHeight + tm.tmExternalLeading; SetTextColor(hdc, RGB(255, 0, 0)); SetBkColor(hdc, RGB(0, 255, 255)); ExtTextOut (hdc, x, y, 0, NULL, TEXT("First Line"), 10, NULL); y += cyLineHeight; SetTextColor(hdc, RGB(0, 255, 0)); SetBkColor(hdc, RGB(255, 0, 255)); ExtTextOut (hdc, x, y, 0, NULL, TEXT("Second Line"), 11, NULL); y += cyLineHeight; SetTextColor(hdc, RGB(0, 0, 255)); SetBkColor(hdc, RGB(255, 255, 0)); ExtTextOut (hdc, x, y, 0, NULL, TEXT("Third Line"), 10, NULL); y += cyLineHeight; EndPaint(hWnd, &ps); } break; case WM_DESTROY: CommandBar_Destroy(hwndCB); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
static LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { NOTIFYICONDATA nid; POINT pt; RECT rect; LPTSTR txt; #if 0 if(message!=WM_CTLCOLORSTATIC && message!=WM_TIMER) s_log(LOG_DEBUG, "Window message: %d", message); #endif switch (message) { case WM_CREATE: if (options.option.taskbar) /* taskbar update enabled? */ SetTimer(hwnd, 0x29a, 1000, NULL); /* 1-second timer */ #ifdef _WIN32_WCE /* create command bar */ hwndCB=CommandBar_Create(ghInst, hwnd, 1); if(!hwndCB) error_box(TEXT("CommandBar_Create")); if(!CommandBar_InsertMenubar(hwndCB, ghInst, IDM_MAINMENU, 0)) error_box(TEXT("CommandBar_InsertMenubar")); if(!CommandBar_AddAdornments(hwndCB, 0, 0)) error_box(TEXT("CommandBar_AddAdornments")); #endif /* create child edit window */ EditControl=CreateWindow(TEXT("EDIT"), NULL, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_READONLY, 0, 0, 0, 0, hwnd, (HMENU)IDE_EDIT, ghInst, NULL); #ifndef _WIN32_WCE SendMessage(EditControl, WM_SETFONT, (WPARAM)GetStockObject(OEM_FIXED_FONT), MAKELPARAM(FALSE, 0)); /* no need to redraw right, now */ #endif /* NOTE: there's no return statement here -> proceeding with resize */ case WM_SIZE: GetClientRect(hwnd, &rect); #ifdef _WIN32_WCE MoveWindow(EditControl, 0, CommandBar_Height(hwndCB), rect.right, rect.bottom-CommandBar_Height(hwndCB), TRUE); #else MoveWindow(EditControl, 0, 0, rect.right, rect.bottom, TRUE); #endif UpdateWindow(EditControl); /* CommandBar_Show(hwndCB, TRUE); */ return TRUE; case WM_SETFOCUS: txt=log_txt(); SetWindowText(EditControl, txt); free(txt); SetFocus(EditControl); return TRUE; case WM_TIMER: update_taskbar(); return TRUE; case WM_CLOSE: set_visible(0); return TRUE; case WM_DESTROY: #ifdef _WIN32_WCE CommandBar_Destroy(hwndCB); #else if(hmainmenu) DestroyMenu(hmainmenu); #endif if(htraymenu) DestroyMenu(htraymenu); ZeroMemory(&nid, sizeof(nid)); nid.cbSize=sizeof(NOTIFYICONDATA); nid.hWnd=hwnd; nid.uID=1; nid.uFlags=NIF_TIP; /* not really sure what to put here, but it works */ Shell_NotifyIcon(NIM_DELETE, &nid); /* this removes the icon */ PostQuitMessage(0); KillTimer(hwnd, 0x29a); return TRUE; case WM_COMMAND: switch(wParam) { case IDM_ABOUT: DialogBox(ghInst, TEXT("AboutBox"), hwnd, (DLGPROC)about_proc); break; case IDM_LOG: set_visible(!visible); break; case IDM_CLOSE: set_visible(0); break; case IDM_EXIT: DestroyWindow(hwnd); break; case IDM_SAVEAS: save_file(hwnd); break; case IDM_SETUP: MessageBox(hwnd, TEXT("Function not implemented"), win32_name, MB_ICONERROR); break; } return TRUE; case UWM_SYSTRAY: /* a taskbar event */ switch (lParam) { #ifdef _WIN32_WCE case WM_LBUTTONDOWN: /* no right mouse button on Windows CE */ GetWindowRect(GetDesktopWindow(), &rect); /* no cursor position */ pt.x=rect.right; pt.y=rect.bottom-25; #else case WM_RBUTTONDOWN: GetCursorPos(&pt); #endif SetForegroundWindow(hwnd); TrackPopupMenuEx(hpopup, TPM_BOTTOMALIGN, pt.x, pt.y, hwnd, NULL); PostMessage(hwnd, WM_NULL, 0, 0); break; #ifndef _WIN32_WCE case WM_LBUTTONDBLCLK: /* switch log window visibility */ set_visible(!visible); break; #endif } return TRUE; } return DefWindowProc(hwnd, message, wParam, lParam); }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; int wmId, wmEvent; PAINTSTRUCT ps; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_HELP_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_FILE_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: hwndCB = CommandBar_Create(hInst, hWnd, 1); CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0); CommandBar_AddAdornments(hwndCB, 0, 0); break; case WM_PAINT: { hdc = BeginPaint(hWnd, &ps); HDC hdcBitmap; HBITMAP hbm, hbmOld; HBRUSH hbr, hbrOld; int cyCB = CommandBar_Height(hwndCB); // Create bitmap & DC. { hdcBitmap = CreateCompatibleDC(hdc); hbm = CreateCompatibleBitmap(hdc, 100, 100); hbmOld = SelectBitmap(hdcBitmap, hbm); // windowsx.h macro } // Draw into bitmap and copy bitmap to drawing surface. { SelectObject(hdcBitmap, GetStockObject(GRAY_BRUSH)); Rectangle(hdcBitmap, 0, 0, 100, 100); SelectObject(hdcBitmap, GetStockObject(WHITE_BRUSH)); Rectangle(hdcBitmap, 20, 20, 80, 80); SelectObject(hdcBitmap, GetStockObject(BLACK_BRUSH)); Rectangle(hdcBitmap, 40, 40, 60, 60); SetTextColor(hdcBitmap, RGB(255, 0, 0)); ExtTextOut(hdcBitmap, 5, 5, 0, NULL, TEXT("Hello World"), 11, NULL); BitBlt(hdc, 0, cyCB, 100, 100, hdcBitmap, 0, 0, SRCCOPY); } // Cleanup bitmap & DC. { SelectObject(hdc, hbmOld); DeleteDC(hdcBitmap); DeleteObject(hbm); } // Fill an area with a blue brush. hbr = CreateSolidBrush(RGB(0, 0, 255)); hbrOld = SelectBrush(hdc, hbr); // windowsx.h macro BitBlt(hdc, 10, cyCB+110, 80, 20, NULL, 0, 0, PATCOPY); SelectObject(hdc, hbrOld); DeleteObject(hbr); BitBlt(hdc, 20, cyCB+140, 40, 40, NULL, 0, 0, BLACKNESS); BitBlt(hdc, 30, cyCB+150, 20, 20, NULL, 0, 0, WHITENESS); EndPaint(hWnd, &ps); } break; case WM_DESTROY: CommandBar_Destroy(hwndCB); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
NOEXPORT LRESULT CALLBACK window_proc(HWND main_window_handle, UINT message, WPARAM wParam, LPARAM lParam) { POINT pt; RECT rect; PAINTSTRUCT ps; SERVICE_OPTIONS *section; unsigned section_number; LPTSTR txt; #if 0 switch(message) { case WM_CTLCOLORSTATIC: case WM_TIMER: case WM_LOG: break; default: s_log(LOG_DEBUG, "Window message: 0x%x(0x%hx,0x%lx)", message, wParam, lParam); } #endif switch(message) { case WM_CREATE: #ifdef _WIN32_WCE /* create command bar */ command_bar_handle=CommandBar_Create(ghInst, main_window_handle, 1); if(!command_bar_handle) error_box(TEXT("CommandBar_Create")); if(!CommandBar_InsertMenubar(command_bar_handle, ghInst, IDM_MAINMENU, 0)) error_box(TEXT("CommandBar_InsertMenubar")); if(!CommandBar_AddAdornments(command_bar_handle, 0, 0)) error_box(TEXT("CommandBar_AddAdornments")); #endif /* create child edit window */ edit_handle=CreateWindowEx(WS_EX_STATICEDGE, TEXT("EDIT"), NULL, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_READONLY, 0, 0, 0, 0, main_window_handle, (HMENU)IDE_EDIT, ghInst, NULL); #ifndef _WIN32_WCE SendMessage(edit_handle, WM_SETFONT, (WPARAM)CreateFont(-12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH, TEXT("Courier")), MAKELPARAM(FALSE, 0)); /* no need to redraw right now */ #endif /* NOTE: there's no return statement here -> proceeding with resize */ case WM_SIZE: GetClientRect(main_window_handle, &rect); #ifdef _WIN32_WCE MoveWindow(edit_handle, 0, CommandBar_Height(command_bar_handle), rect.right, rect.bottom-CommandBar_Height(command_bar_handle), TRUE); SendMessage(command_bar_handle, TB_AUTOSIZE, 0L, 0L); CommandBar_AlignAdornments(command_bar_handle); #else MoveWindow(edit_handle, 0, 0, rect.right, rect.bottom, TRUE); #endif UpdateWindow(edit_handle); /* CommandBar_Show(command_bar_handle, TRUE); */ return 0; case WM_SETFOCUS: SetFocus(edit_handle); return 0; case WM_PAINT: BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); break; case WM_CLOSE: ShowWindow(main_window_handle, SW_HIDE); return 0; #ifdef WM_SHOWWINDOW case WM_SHOWWINDOW: visible=(BOOL)wParam; #else /* this works for Pierre Delaage, but not for me... */ case WM_WINDOWPOSCHANGED: visible=IsWindowVisible(main_window_handle); #endif if(tray_menu_handle) CheckMenuItem(tray_menu_handle, IDM_SHOW_LOG, visible ? MF_CHECKED : MF_UNCHECKED); if(visible) update_logs(); #ifdef WM_SHOWWINDOW return 0; #else break; /* proceed to DefWindowProc() */ #endif case WM_DESTROY: #ifdef _WIN32_WCE CommandBar_Destroy(command_bar_handle); #else if(main_menu_handle) { if(!DestroyMenu(main_menu_handle)) ioerror("DestroyMenu"); main_menu_handle=NULL; } #endif tray_delete(); /* remove the taskbark icon if exists */ PostQuitMessage(0); return 0; case WM_COMMAND: if(wParam>=IDM_PEER_MENU && wParam<IDM_PEER_MENU+number_of_sections) { for(section=service_options.next, section_number=0; section && wParam!=IDM_PEER_MENU+section_number; section=section->next, ++section_number) ; if(!section) return 0; if(save_text_file(section->file, section->chain)) return 0; #ifndef _WIN32_WCE if(main_menu_handle) CheckMenuItem(main_menu_handle, (UINT)wParam, MF_CHECKED); #endif if(tray_menu_handle) CheckMenuItem(tray_menu_handle, (UINT)wParam, MF_CHECKED); message_box(section->help, MB_ICONINFORMATION); return 0; } switch(wParam) { case IDM_ABOUT: DialogBox(ghInst, TEXT("AboutBox"), main_window_handle, (DLGPROC)about_proc); break; case IDM_SHOW_LOG: if(visible) { ShowWindow(main_window_handle, SW_HIDE); /* hide window */ } else { ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */ SetForegroundWindow(main_window_handle); /* bring on top */ } break; case IDM_CLOSE: ShowWindow(main_window_handle, SW_HIDE); /* hide window */ break; case IDM_EXIT: if(num_clients>=0) /* signal_pipe is active */ signal_post(SIGNAL_TERMINATE); DestroyWindow(main_window_handle); break; case IDM_SAVE_LOG: if(!cmdline.service) /* security */ save_log(); break; case IDM_EDIT_CONFIG: #ifndef _WIN32_WCE if(!cmdline.service) /* security */ edit_config(main_window_handle); #endif break; case IDM_RELOAD_CONFIG: if(num_clients>=0) /* signal_pipe is active */ signal_post(SIGNAL_RELOAD_CONFIG); else SetEvent(config_ready); /* unlock daemon_thread() */ break; case IDM_REOPEN_LOG: signal_post(SIGNAL_REOPEN_LOG); break; case IDM_MANPAGE: #ifndef _WIN32_WCE if(!cmdline.service) /* security */ ShellExecute(main_window_handle, TEXT("open"), TEXT("..\\doc\\stunnel.html"), NULL, NULL, SW_SHOWNORMAL); #endif break; case IDM_HOMEPAGE: #ifndef _WIN32_WCE if(!cmdline.service) /* security */ ShellExecute(main_window_handle, TEXT("open"), TEXT("http://www.stunnel.org/"), NULL, NULL, SW_SHOWNORMAL); #endif break; } return 0; case WM_SYSTRAY: /* a taskbar event */ switch(lParam) { #ifdef _WIN32_WCE case WM_LBUTTONDOWN: /* no right mouse button on Windows CE */ GetWindowRect(GetDesktopWindow(), &rect); /* no cursor position */ pt.x=rect.right; pt.y=rect.bottom-25; #else case WM_RBUTTONDOWN: GetCursorPos(&pt); #endif SetForegroundWindow(main_window_handle); if(tray_menu_handle) TrackPopupMenuEx(GetSubMenu(tray_menu_handle, 0), TPM_BOTTOMALIGN, pt.x, pt.y, main_window_handle, NULL); PostMessage(main_window_handle, WM_NULL, 0, 0); break; #ifndef _WIN32_WCE case WM_LBUTTONDBLCLK: /* switch log window visibility */ if(visible) { ShowWindow(main_window_handle, SW_HIDE); /* hide window */ } else { ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */ SetForegroundWindow(main_window_handle); /* bring on top */ } break; #endif } return 0; case WM_VALID_CONFIG: valid_config(); return 0; case WM_INVALID_CONFIG: invalid_config(); return 0; case WM_LOG: txt=(LPTSTR)wParam; win_log(txt); str_free(txt); return 0; case WM_NEW_CHAIN: #ifndef _WIN32_WCE if(main_menu_handle) EnableMenuItem(main_menu_handle, (UINT)(IDM_PEER_MENU+wParam), MF_ENABLED); #endif if(tray_menu_handle) EnableMenuItem(tray_menu_handle, (UINT)(IDM_PEER_MENU+wParam), MF_ENABLED); return 0; case WM_CLIENTS: tray_update((int)wParam); return 0; } return DefWindowProc(main_window_handle, message, wParam, lParam); }
NOEXPORT LRESULT CALLBACK window_proc(HWND main_window_handle, UINT message, WPARAM wParam, LPARAM lParam) { NOTIFYICONDATA nid; POINT pt; RECT rect; SERVICE_OPTIONS *section; unsigned int section_number; #if 0 if(message!=WM_CTLCOLORSTATIC && message!=WM_TIMER) s_log(LOG_DEBUG, "Window message: %d", message); #endif switch(message) { case WM_CREATE: #ifdef _WIN32_WCE /* create command bar */ command_bar_handle=CommandBar_Create(ghInst, main_window_handle, 1); if(!command_bar_handle) error_box("CommandBar_Create"); if(!CommandBar_InsertMenubar(command_bar_handle, ghInst, IDM_MAINMENU, 0)) error_box("CommandBar_InsertMenubar"); if(!CommandBar_AddAdornments(command_bar_handle, 0, 0)) error_box("CommandBar_AddAdornments"); #endif /* create child edit window */ edit_handle=CreateWindow(TEXT("EDIT"), NULL, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_READONLY, 0, 0, 0, 0, main_window_handle, (HMENU)IDE_EDIT, ghInst, NULL); #ifndef _WIN32_WCE SendMessage(edit_handle, WM_SETFONT, (WPARAM)CreateFont(-12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH, TEXT("Courier")), MAKELPARAM(FALSE, 0)); /* no need to redraw right, now */ #endif /* NOTE: there's no return statement here -> proceeding with resize */ case WM_SIZE: GetClientRect(main_window_handle, &rect); #ifdef _WIN32_WCE MoveWindow(edit_handle, 0, CommandBar_Height(command_bar_handle), rect.right, rect.bottom-CommandBar_Height(command_bar_handle), TRUE); #else MoveWindow(edit_handle, 0, 0, rect.right, rect.bottom, TRUE); #endif UpdateWindow(edit_handle); /* CommandBar_Show(command_bar_handle, TRUE); */ return TRUE; case WM_SETFOCUS: SetFocus(edit_handle); return TRUE; case WM_TIMER: if(visible) update_logs(); return TRUE; case WM_CLOSE: ShowWindow(main_window_handle, SW_HIDE); return TRUE; case WM_SHOWWINDOW: visible=wParam; /* setup global variable */ if(tray_menu_handle) CheckMenuItem(tray_menu_handle, IDM_SHOW_LOG, visible ? MF_CHECKED : MF_UNCHECKED); if(visible) update_logs(); return TRUE; case WM_DESTROY: #ifdef _WIN32_WCE CommandBar_Destroy(command_bar_handle); #else if(main_menu_handle) DestroyMenu(main_menu_handle); #endif if(tray_menu_handle) DestroyMenu(tray_menu_handle); ZeroMemory(&nid, sizeof nid); nid.cbSize=sizeof nid; nid.hWnd=main_window_handle; nid.uID=1; nid.uFlags=NIF_TIP; /* not really sure what to put here, but it works */ Shell_NotifyIcon(NIM_DELETE, &nid); /* this removes the icon */ PostQuitMessage(0); KillTimer(main_window_handle, 0x29a); return TRUE; case WM_COMMAND: if(wParam>=IDM_PEER_MENU && wParam<IDM_PEER_MENU+number_of_sections) { for(section=service_options.next, section_number=0; section && wParam!=IDM_PEER_MENU+section_number; section=section->next, ++section_number) ; if(!section) return TRUE; if(save_text_file(section->file, section->chain)) return TRUE; #ifndef _WIN32_WCE if(main_menu_handle) CheckMenuItem(main_menu_handle, wParam, MF_CHECKED); #endif if(tray_menu_handle) CheckMenuItem(tray_menu_handle, wParam, MF_CHECKED); message_box(section->help, MB_ICONINFORMATION); return TRUE; } switch(wParam) { case IDM_ABOUT: DialogBox(ghInst, TEXT("AboutBox"), main_window_handle, (DLGPROC)about_proc); break; case IDM_SHOW_LOG: if(visible) { ShowWindow(main_window_handle, SW_HIDE); /* hide window */ } else { ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */ SetForegroundWindow(main_window_handle); /* bring on top */ } break; case IDM_CLOSE: ShowWindow(main_window_handle, SW_HIDE); /* hide window */ break; case IDM_EXIT: if(!error_mode) /* signal_pipe is active */ signal_post(SIGNAL_TERMINATE); DestroyWindow(main_window_handle); break; case IDM_SAVE_LOG: if(!cmdline.service) /* security */ save_log(); break; case IDM_EDIT_CONFIG: #ifndef _WIN32_WCE if(!cmdline.service) /* security */ edit_config(main_window_handle); #endif break; case IDM_RELOAD_CONFIG: if(error_mode) /* unlock daemon_thread */ SetEvent(config_ready); else /* signal_pipe is active */ signal_post(SIGNAL_RELOAD_CONFIG); break; case IDM_REOPEN_LOG: signal_post(SIGNAL_REOPEN_LOG); break; case IDM_MANPAGE: #ifndef _WIN32_WCE if(!cmdline.service) /* security */ ShellExecute(main_window_handle, TEXT("open"), TEXT("stunnel.html"), NULL, NULL, SW_SHOWNORMAL); #endif break; case IDM_HOMEPAGE: #ifndef _WIN32_WCE if(!cmdline.service) /* security */ ShellExecute(main_window_handle, TEXT("open"), TEXT("http://www.stunnel.org/"), NULL, NULL, SW_SHOWNORMAL); #endif break; } return TRUE; case WM_SYSTRAY: /* a taskbar event */ switch(lParam) { #ifdef _WIN32_WCE case WM_LBUTTONDOWN: /* no right mouse button on Windows CE */ GetWindowRect(GetDesktopWindow(), &rect); /* no cursor position */ pt.x=rect.right; pt.y=rect.bottom-25; #else case WM_RBUTTONDOWN: GetCursorPos(&pt); #endif SetForegroundWindow(main_window_handle); TrackPopupMenuEx(GetSubMenu(tray_menu_handle, 0), TPM_BOTTOMALIGN, pt.x, pt.y, main_window_handle, NULL); PostMessage(main_window_handle, WM_NULL, 0, 0); break; #ifndef _WIN32_WCE case WM_LBUTTONDBLCLK: /* switch log window visibility */ if(visible) { ShowWindow(main_window_handle, SW_HIDE); /* hide window */ } else { ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */ SetForegroundWindow(main_window_handle); /* bring on top */ } break; #endif } return TRUE; case WM_VALID_CONFIG: valid_config(); return TRUE; case WM_INVALID_CONFIG: invalid_config(); return TRUE; case WM_LOG: win_log((LPSTR)wParam); return TRUE; case WM_NEW_CHAIN: #ifndef _WIN32_WCE if(main_menu_handle) EnableMenuItem(main_menu_handle, IDM_PEER_MENU+wParam, MF_ENABLED); #endif if(tray_menu_handle) EnableMenuItem(tray_menu_handle, IDM_PEER_MENU+wParam, MF_ENABLED); return TRUE; case WM_CLIENTS: update_tray_icon((int)wParam); return TRUE; } return DefWindowProc(main_window_handle, message, wParam, lParam); }