void CXTPPropertyGridInplaceList::Create(CXTPPropertyGridItem* pItem, CRect rect) { ASSERT(pItem && pItem->GetGrid()); if (!pItem) return; CRect rcValue(rect); rcValue.left = pItem->GetGrid()->GetDividerPos() + 1; CWnd* pParent = (CWnd*)pItem->GetGrid(); m_pItem = pItem; DestroyWindow(); if (!m_hWnd) { CListBox::CreateEx(WS_EX_TOOLWINDOW | (pParent->GetExStyle() & WS_EX_LAYOUTRTL), _T("LISTBOX"), _T(""), LBS_NOTIFY | WS_CHILD | WS_VSCROLL | WS_BORDER | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS, CRect(0, 0, 0, 0), pParent, 0); SetOwner(pParent); if (m_bShowShadow && XTPSystemVersion()->IsWinXPOrGreater()) SetClassLongPtr(m_hWnd, GCL_STYLE, GetClassLongPtr(m_hWnd, GCL_STYLE) | 0x00020000); } SetFont(pParent->GetFont()); ResetContent(); CXTPPropertyGridItemConstraints* pList = pItem->GetConstraints(); int dx = rect.right - rcValue.left; CWindowDC dc(pParent); CXTPFontDC font(&dc, pParent->GetFont()); int nHeight = dc.GetTextExtent(_T(" "), 1).cy + 3; for (int i = 0; i < pList->GetCount(); i++) { CXTPPropertyGridItemConstraint* pConstraint = pList->GetConstraintAt(i); CString str = pConstraint->m_strConstraint; int nIndex = AddString(str); SetItemDataPtr(nIndex, pConstraint); CSize sz = pItem->OnMergeItemConstraint(&dc, pConstraint); dx = max(dx, sz.cx); nHeight = max(nHeight, sz.cy); if (pItem->GetValue() == str) SetCurSel(nIndex); } SetItemHeight(0, nHeight); rect.top = rect.bottom; rect.bottom += nHeight * __min(pItem->GetDropDownItemCount(), GetCount()) + 2; rect.left = rect.right - __min(dx, rect.Width() - XTP_PGI_EXPAND_BORDER); pParent->ClientToScreen(&rect); CRect rcWork = XTPMultiMonitor()->GetWorkArea(rect); if (rect.bottom > rcWork.bottom && rect.top > rcWork.CenterPoint().y) { rect.OffsetRect(0, - rect.Height() - rcValue.Height() - 1); } if (rect.left < rcWork.left) rect.OffsetRect(rcWork.left - rect.left, 0); if (rect.right > rcWork.right) rect.OffsetRect(rcWork.right - rect.right, 0); SetFocus(); SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, 0); ModifyStyle(WS_CHILD, WS_POPUP); SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, (LONG_PTR)pParent->m_hWnd); SetWindowPos(&CWnd::wndTopMost, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOOWNERZORDER); CXTPMouseMonitor::SetupHook(this); }
void CMainDlg::CloseDialog(int nVal) { DestroyWindow(); ::PostQuitMessage(nVal); }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // 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; PAINTSTRUCT ps; HDC hdc,bmp_dc; HGDIOBJ oldbmp; OGUI::Image target(640, 480, (unsigned char*)bitmap_pixels); RECT rect; int x, y; rect.left = rect.top = 0; rect.right = 640; rect.bottom = 480; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_TIMER: if (OGUI::OGUIManager::instance()->get_desktop()->draw(target, OGUI::Rect(0, 0, 640, 480))) InvalidateRect(hWnd, &rect, FALSE); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); bmp_dc = CreateCompatibleDC(hdc); oldbmp=SelectObject(bmp_dc, bitmap); BitBlt(hdc, 0, 0, 640, 480, bmp_dc, 0, 0, SRCCOPY); SelectObject(bmp_dc, oldbmp); DeleteDC(bmp_dc); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN: x = GET_X_LPARAM(lParam); y = GET_Y_LPARAM(lParam); OGUI::OGUIManager::instance()->mouse_down(0, x, y); break; case WM_LBUTTONUP: x = GET_X_LPARAM(lParam); y = GET_Y_LPARAM(lParam); OGUI::OGUIManager::instance()->mouse_up(0, x, y); break; case WM_MOUSEMOVE: x = GET_X_LPARAM(lParam); y = GET_Y_LPARAM(lParam); OGUI::OGUIManager::instance()->mouse_move(x, y); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/* * OnCommand() */ void mfd_OnCommand(HWND mtfDlg, UINT ctrlID, HWND ctrl, UINT notify) { switch (ctrlID) { /* * Menus */ case IDM_RETRIEVE_MTF: TX81Z_RetrieveData(Prog_midi, REQ_MTF, &Prog_snapshot); SendMessage(Prog_mainWnd, WM_COMMAND , MAKEWPARAM(IDD_MTFDLG, EDN_CHANGE) , (LPARAM) mtfDlg); MTGen_InitControlValues(&mfd_dlgData); break; case IDM_TRANSMIT_MTF: TX81Z_SendData(Prog_midi, REQ_MTF, &Prog_snapshot); break; case IDM_EXIT: PostMessage(Prog_mainWnd, WM_COMMAND, IDM_EXIT, 0L); case IDM_CLOSE: case IDCANCEL: DestroyWindow(mtfDlg); return; case IDM_UNDO: Undo_Undo(mfd_dlgData.undo, MTGen_Undo, mtfDlg); goto UpdateUndoMenus; case IDM_REDO: Undo_Redo(mfd_dlgData.undo, MTGen_Redo, mtfDlg); UpdateUndoMenus: EnableMenuItem(mfd_dlgData.menu, IDM_UNDO , MF_BYCOMMAND | (Undo_AnyUndoes(mfd_dlgData.undo) ? MF_ENABLED : MF_GRAYED)); EnableMenuItem(mfd_dlgData.menu, IDM_REDO , MF_BYCOMMAND | (Undo_AnyRedoes(mfd_dlgData.undo) ? MF_ENABLED : MF_GRAYED)); return; case IDM_KYBDDLG: case IDM_REMOTEWND: case IDM_MAINWND: case IDM_VOICEDLG: case IDM_PFMDLG: case IDM_FXDLG: case IDM_PCDLG: case IDM_MTODLG: case IDM_MTFDLG: case IDM_SYSDLG: SendMessage(Prog_mainWnd, WM_COMMAND, ctrlID, 0); return; case IDM_HELP: Prog_OpenHelp(mtfDlg, _T("microtunings_editors.html")); return; } /* * Init microtunings menu items. */ if (ctrlID >= IDM_EQUAL_TEMPERED && ctrlID <= IDM_1_8_TONE) { memcpy(&Prog_snapshot.mtf.data , &TX81Z_initMtf[ctrlID - IDM_EQUAL_TEMPERED][0] , mfd_initCnt << 1); TX81Z_SendData(Prog_midi, REQ_MTF, &Prog_snapshot); MTGen_InitControlValues(&mfd_dlgData); SendNotification(Prog_mainWnd, IDD_MTFDLG, mtfDlg, EDN_CHANGE); } /* * LCD Controls */ if (ctrlID >= IDC_MT_NOTE_1 && ctrlID < IDC_MT_FREQ_1 && notify == LCN_SELCHANGE) { int value = LcdCtrl_GetValue(ctrl); /* * If the control is a full tuning LCD. */ if (ctrlID >= IDC_MT_FULL_1 && ctrlID < IDC_MT_FREQ_1) { MTGen_FullLcdChange(&mfd_dlgData, ctrlID, value); /* * If the control is a note LCD. */ } else if ((ctrlID & 1) == 0) { MTGen_NoteLcdChange(&mfd_dlgData, ctrlID, value); /* * Else the control is a fine frequency LCD. */ } else { MTGen_FineLcdChange(&mfd_dlgData, ctrlID, value); } } }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // 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) { switch (message) { case 1998: { SetWindowText(hWnd, L"Catch"); if (!hNew) { hNew = CreateWindow(TEXT("BUTTON"), TEXT("NEW"), WS_CHILD | WS_VISIBLE, x1, y1, x2, y2, ::hWnd, (HMENU)995, nullptr, nullptr); } else { DestroyWindow(hNew); hNew = CreateWindow(TEXT("BUTTON"), TEXT("NEW"), WS_CHILD | WS_VISIBLE, x1, y1, x2, y2, ::hWnd, (HMENU)995, nullptr, nullptr); } //InvalidateRect(hNew, NULL, FALSE); //UpdateWindow(hWnd); break; } case WM_COMMAND: { int wmId = LOWORD(wParam); // Parse the menu selections: switch (wmId) { case 999: { if (!hDlg) { hDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DLGPROC(DlgProc)); } else { DestroyWindow(hDlg); hDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DLGPROC(DlgProc)); } SetWindowText(hWnd, L"Wait enter..."); ShowWindow(hDlg, 1); } break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code that uses hdc here... EndPaint(hWnd, &ps); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK DeviceStatus::WindowsMessageCallback( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { // Setup window user data with device status object pointer. LPCREATESTRUCT create_struct = reinterpret_cast<LPCREATESTRUCT>(lParam); void *lpCreateParam = create_struct->lpCreateParams; DeviceStatus *pDeviceStatus = reinterpret_cast<DeviceStatus*>(lpCreateParam); SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pDeviceStatus)); } return 0; // Return 0 for successfully handled WM_CREATE. case WM_DEVICECHANGE: { WORD loword = LOWORD(wParam); if (loword != DBT_DEVICEARRIVAL && loword != DBT_DEVICEREMOVECOMPLETE) { // Ignore messages other than device arrive and remove complete // (we're not handling intermediate ones). return TRUE; // Grant WM_DEVICECHANGE request. } DEV_BROADCAST_DEVICEINTERFACE* hdr; hdr = (DEV_BROADCAST_DEVICEINTERFACE*) lParam; if (hdr->dbcc_devicetype != DBT_DEVTYP_DEVICEINTERFACE) { // Ignore non interface device messages. return TRUE; // Grant WM_DEVICECHANGE request. } LONG_PTR userData = GetWindowLongPtr(hwnd, GWLP_USERDATA); OVR_ASSERT(userData != NULL); // Call callback on device messages object with the device path. DeviceStatus* pDeviceStatus = (DeviceStatus*) userData; String devicePathStr(hdr->dbcc_name); pDeviceStatus->MessageCallback(loword, devicePathStr); } return TRUE; // Grant WM_DEVICECHANGE request. case WM_CLOSE: { LONG_PTR userData = GetWindowLongPtr(hwnd, GWLP_USERDATA); OVR_ASSERT(userData != NULL); DeviceStatus* pDeviceStatus = (DeviceStatus*) userData; pDeviceStatus->hMessageWindow = NULL; DestroyWindow(hwnd); } return 0; // We processed the WM_CLOSE message. case WM_DESTROY: PostQuitMessage(0); return 0; // We processed the WM_DESTROY message. } return DefWindowProc(hwnd, message, wParam, lParam); }
/* PauseBox */ int WDPROC PauseBox(LPPW lppw) { HDC hdc; int width, height; TEXTMETRIC tm; RECT rect; char *current_pause_title = lppw->Title; #ifdef USE_MOUSE /* Do not try to wait for mouse events when there's no graph window open. */ if (paused_for_mouse && !MousableWindowOpened()) paused_for_mouse = 0; if (!paused_for_mouse) #endif { if (!lppw->hPrevInstance) CreatePauseClass(lppw); GetWindowRect(GetDesktopWindow(), &rect); if ((lppw->Origin.x == CW_USEDEFAULT) || (lppw->Origin.x == 0)) lppw->Origin.x = (rect.right + rect.left) / 2; if ((lppw->Origin.y == CW_USEDEFAULT) || (lppw->Origin.y == 0)) lppw->Origin.y = (rect.bottom + rect.top) / 2; hdc = GetDC(NULL); SelectObject(hdc, GetStockObject(SYSTEM_FONT)); GetTextMetrics(hdc, &tm); width = max(24, 4 + strlen(lppw->Message)) * tm.tmAveCharWidth; width = min(width, rect.right-rect.left); height = 28 * (tm.tmHeight + tm.tmExternalLeading) / 4; ReleaseDC(NULL,hdc); lppw->hWndPause = CreateWindowEx( WS_EX_DLGMODALFRAME | WS_EX_APPWINDOW, szPauseClass, current_pause_title, /* HBB 981202: WS_POPUPWINDOW would have WS_SYSMENU in it, but we don't * want, nor need, a System menu in our Pause windows. */ WS_POPUP | WS_BORDER | WS_CAPTION, lppw->Origin.x - width/2, lppw->Origin.y - height/2, width, height, lppw->hWndParent, NULL, lppw->hInstance, lppw); ShowWindow(lppw->hWndPause, SW_SHOWNORMAL); BringWindowToTop(lppw->hWndPause); UpdateWindow(lppw->hWndPause); lppw->bPause = TRUE; lppw->bPauseCancel = IDCANCEL; while (lppw->bPause && !ctrlc_flag) { if (term->waitforinput == NULL) { /* Only handle message queue events */ WinMessageLoop(); if (lppw->bPause && !ctrlc_flag) WaitMessage(); } else { /* Call the non-blocking sleep function, which also handles console input (caca terminal) and mousing of the current terminal (e.g. qt) */ win_sleep(50); } } DestroyWindow(lppw->hWndPause); return lppw->bPauseCancel; } #ifdef USE_MOUSE else { /* Don't show the pause "OK CANCEL" dialog for "pause mouse ..." Note: maybe gnuplot should display a message like "gnuplot pausing (waiting for mouse click)" in the window status or title bar or somewhere else. */ while (paused_for_mouse && !ctrlc_flag) { if (term->waitforinput == NULL) { /* Only handle message queue events */ WinMessageLoop(); if (paused_for_mouse && !ctrlc_flag) WaitMessage(); } else { /* Call the non-blocking sleep function, which also handles console input (caca terminal) and mousing of the current terminal (e.g. qt) */ win_sleep(50); } } return !ctrlc_flag; } #endif }
void CloseProgressDialog() { ReleaseDC(hWndMainWindow,hStartupDC); DestroyWindow(hStartupWindow); hStartupWindow=NULL; doinitprogress=true; }
BOOL ipod_browse_photo_dialog::DialogProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) { switch(msg) { case WM_INITDIALOG: { m_this=this; //m_wnd=wnd; ShowWindow(m_viewer.create(wnd, NULL), SW_SHOWNORMAL); modeless_dialog_manager::g_add(wnd); RECT rc; GetClientRect(wnd, &rc); on_size(wnd, rc.right, rc.bottom); refresh_photo(); } break; case WM_COMMAND: switch (wp) { case IDCANCEL: DestroyWindow(wnd); return 0; case IDC_NEXT: if (m_index + 1< m_library.artwork_object.image_list.get_count()) { m_index++; m_format=0; refresh_photo(); } return 0; case IDC_LAST: if (m_library.artwork_object.image_list.get_count()) { m_index = m_library.artwork_object.image_list.get_count()-1; m_format=0; refresh_photo(); } return 0; case IDC_PREVIOUS: if (m_index) { m_index--; m_format=0; refresh_photo(); } return 0; case IDC_PREVIOUS_FORMAT: if (m_format) { m_format--; refresh_photo(); } return 0; case IDC_NEXT_FORMAT: if (m_index < m_library.artwork_object.image_list.get_count() && m_format + 1 < m_library.artwork_object.image_list[m_index].image_names.get_count()) { m_format++; refresh_photo(); } return 0; } break; case WM_SIZE: on_size (wnd, LOWORD(lp), HIWORD(lp)); return 0; case WM_DESTROY: m_viewer.destroy(); return 0; case WM_NCDESTROY: modeless_dialog_manager::g_remove(wnd); SetWindowLongPtr(wnd, DWL_USER, NULL); m_this.release(); break; } return FALSE; }
void SettingsEncoding::DestroyPane() { DestroyWindow(hwnd); hwnd = NULL; }
void CModelessDialog::OnCancel() { DestroyWindow(); }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { WNDCLASS wc; HWND hWnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit = FALSE; float theta = 0.0f; /* register window class */ wc.style = CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "GLSample"; RegisterClass (&wc); /* create main window */ hWnd = CreateWindow ( "GLSample", "OpenGL Sample", WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, 0, 0, 256, 256, NULL, NULL, hInstance, NULL); /* enable OpenGL for the window */ EnableOpenGL (hWnd, &hDC, &hRC); /* program main loop */ while (!bQuit) { /* check for messages */ if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { /* handle or dispatch messages */ if (msg.message == WM_QUIT) { bQuit = TRUE; } else { TranslateMessage (&msg); DispatchMessage (&msg); } } else { /* OpenGL animation code goes here */ glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glClear (GL_COLOR_BUFFER_BIT); glPushMatrix (); glRotatef (theta, 0.0f, 0.0f, 1.0f); glBegin (GL_TRIANGLES); glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (0.0f, 1.0f); glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.87f, -0.5f); glColor3f (0.0f, 0.0f, 1.0f); glVertex2f (-0.87f, -0.5f); glEnd (); glPopMatrix (); SwapBuffers (hDC); theta += .5f; Sleep (1); } } /* shutdown OpenGL */ DisableOpenGL (hWnd, hDC, hRC); /* destroy the window explicitly */ DestroyWindow (hWnd); return msg.wParam; }
void WindowsPlatform::destroyWindow(void) { ReleaseDC(window, deviceContext); DestroyWindow(window); }
BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HMENU hMenu; HWND comboControl1; HWND comboControl2; HWND comboControl3; comboControl1=GetDlgItem(hwnd,IDC_COMBO1); comboControl2=GetDlgItem(hwnd,IDC_COMBO2); comboControl3=GetDlgItem(hwnd,IDC_COMBO3); BOOL status = FALSE; JABIA_Character * ptr = 0; // character address switch (message) { case WM_INITDIALOG: BringWindowToTop(hwnd); // add menu hMenu = LoadMenu(g_hModule, MAKEINTRESOURCE(IDR_MENU1)); SetMenu(hwnd,hMenu); // add icon HICON hIcon; hIcon = (HICON)LoadImage( g_hModule, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0); if(hIcon) { SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); } // add characters to drop down list for(unsigned long i = 0; i < jabia_characters.size(); i++) { SendMessage(comboControl1,CB_ADDSTRING,0,reinterpret_cast<LPARAM>((LPCTSTR)jabia_characters.at(i)->merc_name)); char buf[255]; wsprintf(buf, "In init, Character at 0x%X", jabia_characters.at(i)); OutputDebugString(buf); } // select fist item in list SendMessage(comboControl1, CB_SETCURSEL, last_character_selected_index, 0); // add weapons slots to their combo box SendMessage(comboControl2,CB_ADDSTRING,0,reinterpret_cast<LPARAM>((LPCTSTR)"1")); SendMessage(comboControl2,CB_ADDSTRING,0,reinterpret_cast<LPARAM>((LPCTSTR)"2")); SendMessage(comboControl2,CB_ADDSTRING,0,reinterpret_cast<LPARAM>((LPCTSTR)"3")); // select fist item in list SendMessage(comboControl2, CB_SETCURSEL, last_weaponslot_selected_index, 0); // add inventory slots to their combo box for(int i = 0; i < JABIA_CHARACTER_INV_SLOTS; i++) { char buf[5]; //wsprintf(buf, "%i", i); SendMessage(comboControl3,CB_ADDSTRING,0,reinterpret_cast<LPARAM>((LPCTSTR)buf)); } // select fist item in list SendMessage(comboControl3, CB_SETCURSEL, 0, 0); break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_COMBO1: switch(HIWORD(wParam)) { case CBN_CLOSEUP: // use combo box selected index to get a character out of the vector last_character_selected_index = SendMessage(comboControl1, CB_GETCURSEL, 0, 0); ptr = jabia_characters.at(last_character_selected_index); fillDialog(hwnd, ptr); break; } break; case IDC_COMBO2: switch(HIWORD(wParam)) { case CBN_CLOSEUP: // use combo box selected index to get weapon from inventory last_weaponslot_selected_index = SendMessage(comboControl2, CB_GETCURSEL, 0, 0); ptr = jabia_characters.at(last_character_selected_index); fillDialog(hwnd, ptr); break; } break; case IDC_COMBO3: switch(HIWORD(wParam)) { case CBN_CLOSEUP: // use combo box selected index to get weapon from inventory last_inventory_selected_index = SendMessage(comboControl3, CB_GETCURSEL, 0, 0); ptr = jabia_characters.at(last_character_selected_index); fillDialog(hwnd, ptr); break; } break; case IDSET: //char buf[50]; //wsprintf(buf, "Setting"); ptr = jabia_characters.at(last_character_selected_index); setCharacter(hwnd, ptr); break; case IDM_HEAL_CHARACTER: ptr = jabia_characters.at(last_character_selected_index); heal_character(ptr); fillDialog(hwnd, ptr); break; case IDM_KILL_CHARACTER: ptr = jabia_characters.at(last_character_selected_index); kill_character(ptr); fillDialog(hwnd, ptr); break; case IDM_STUN_CHARACTER: ptr = jabia_characters.at(last_character_selected_index); stun_character(ptr); fillDialog(hwnd, ptr); break; case IDM_EQUIPMENT1: ptr = jabia_characters.at(last_character_selected_index); give_equipment1(ptr); fillDialog(hwnd, ptr); break; case IDM_DUMP_CHARACTER: ptr = jabia_characters.at(last_character_selected_index); dump_current_character(hwnd, ptr); break; case IDM_DUMP_ALL: dump_all_characters(hwnd); break; case IDCANCEL: DestroyWindow(hwnd); PostQuitMessage(0); break; } break; default: return FALSE; } return FALSE; }
static INT_PTR CALLBACK PerfCounterDialogProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { PPH_PERFMON_SYSINFO_CONTEXT context = NULL; if (uMsg == WM_INITDIALOG) { context = (PPH_PERFMON_SYSINFO_CONTEXT)lParam; SetProp(hwndDlg, L"Context", (HANDLE)context); } else { context = (PPH_PERFMON_SYSINFO_CONTEXT)GetProp(hwndDlg, L"Context"); if (uMsg == WM_DESTROY) { PhDeleteLayoutManager(&context->LayoutManager); PhDeleteGraphState(&context->GraphState); if (context->GraphHandle) DestroyWindow(context->GraphHandle); PhUnregisterCallback(&PhProcessesUpdatedEvent, &context->ProcessesUpdatedRegistration); RemoveProp(hwndDlg, L"Context"); } } if (context == NULL) return FALSE; switch (uMsg) { case WM_INITDIALOG: { PPH_LAYOUT_ITEM panelItem; context->WindowHandle = hwndDlg; // Create the graph control. context->GraphHandle = CreateWindow( PH_GRAPH_CLASSNAME, NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 0, 0, 3, 3, hwndDlg, NULL, (HINSTANCE)PluginInstance->DllBase, NULL ); Graph_SetTooltip(context->GraphHandle, TRUE); PhInitializeGraphState(&context->GraphState); PhInitializeLayoutManager(&context->LayoutManager, hwndDlg); PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_COUNTERNAME), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT | PH_LAYOUT_FORCE_INVALIDATE); panelItem = PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_GRAPH_LAYOUT), NULL, PH_ANCHOR_ALL); PhAddLayoutItemEx(&context->LayoutManager, context->GraphHandle, NULL, PH_ANCHOR_ALL, panelItem->Margin); SendMessage(GetDlgItem(hwndDlg, IDC_COUNTERNAME), WM_SETFONT, (WPARAM)context->SysinfoSection->Parameters->LargeFont, FALSE); SetDlgItemText(hwndDlg, IDC_COUNTERNAME, context->SysinfoSection->Name.Buffer); PhRegisterCallback( &PhProcessesUpdatedEvent, ProcessesUpdatedHandler, context, &context->ProcessesUpdatedRegistration ); PerfCounterUpdateGraphs(context); } break; case WM_SIZE: PhLayoutManagerLayout(&context->LayoutManager); break; case WM_NOTIFY: { NMHDR* header = (NMHDR*)lParam; if (header->hwndFrom == context->GraphHandle) { switch (header->code) { case GCN_GETDRAWINFO: { PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)header; PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo; drawInfo->Flags = PH_GRAPH_USE_GRID; context->SysinfoSection->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(L"ColorCpuKernel"), 0); PhGraphStateGetDrawInfo( &context->GraphState, getDrawInfo, context->HistoryBuffer.Count ); if (!context->GraphState.Valid) { FLOAT maxGraphHeight = 0; for (ULONG i = 0; i < drawInfo->LineDataCount; i++) { context->GraphState.Data1[i] = (FLOAT)PhGetItemCircularBuffer_ULONG(&context->HistoryBuffer, i); if (context->GraphState.Data1[i] > maxGraphHeight) maxGraphHeight = context->GraphState.Data1[i]; } // Scale the data. PhxfDivideSingle2U( context->GraphState.Data1, maxGraphHeight, drawInfo->LineDataCount ); context->GraphState.Valid = TRUE; } } break; case GCN_GETTOOLTIPTEXT: { PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)header; if (getTooltipText->Index < getTooltipText->TotalCount) { if (context->GraphState.TooltipIndex != getTooltipText->Index) { ULONG itemUsage = PhGetItemCircularBuffer_ULONG( &context->HistoryBuffer, getTooltipText->Index ); PhSwapReference2(&context->GraphState.TooltipText, PhFormatString( L"%u\n%s", itemUsage, ((PPH_STRING)PHA_DEREFERENCE(PhGetStatisticsTimeString(NULL, getTooltipText->Index)))->Buffer )); } getTooltipText->Text = context->GraphState.TooltipText->sr; } } break; } } } break; case MSG_UPDATE: PerfCounterUpdateGraphs(context); break; } return FALSE; }
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static int nWidth, nHeight; switch(iMsg) { case WM_CREATE: { SpiderWnd.Create(hwnd, 0, WS_CHILD | WS_VISIBLE, 0, 0, 100, 100); dwDifficulty = IDC_DIF_ONECOLOR; CreateSpider(); SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER); dwAppStartTime = GetTickCount(); return 0; } case WM_DESTROY: PostQuitMessage(0); return 0; case WM_SIZE: nWidth = LOWORD(lParam); nHeight = HIWORD(lParam); MoveWindow(SpiderWnd, 0, 0, nWidth, nHeight, TRUE); return 0; case WM_GETMINMAXINFO: { MINMAXINFO *mmi; mmi = (MINMAXINFO *)lParam; mmi->ptMinTrackSize.x = NUM_STACKS * __cardwidth + (NUM_STACKS + 3) * X_BORDER + 12; // Border left and right of 6px mmi->ptMinTrackSize.y = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYMENU) + 2 * Y_BORDER + 3 * __cardheight + 6 * yRowStackCardOffset; return 0; } case WM_COMMAND: switch(LOWORD(wParam)) { case IDM_GAME_NEW: NewGame(); return 0; case IDM_GAME_DECK: ShowDeckOptionsDlg(hwnd); return 0; case IDM_HELP_CONTENTS: WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play"); return 0; case IDM_HELP_ABOUT: MessageBox(hwnd, MsgAbout, szAppName, MB_OK|MB_ICONINFORMATION); return 0; case IDM_GAME_EXIT: PostMessage(hwnd, WM_CLOSE, 0, 0); return 0; } return 0; case WM_CLOSE: if (fGameStarted == false) { DestroyWindow(hwnd); return 0; } else { int ret; ret = MessageBox(hwnd, MsgQuit, szAppName, MB_YESNO|MB_ICONQUESTION); if (ret == IDYES) { WinHelp(hwnd, szHelpPath, HELP_QUIT, 0); DestroyWindow(hwnd); } } return 0; } return DefWindowProc (hwnd, iMsg, wParam, lParam); }
GLvoid KillGLWindow( GLvoid ) // Корректное разрушение окна { if( fullscreen ) { // Мы в полноэкранном режиме? ChangeDisplaySettings( NULL, 0 ); // Если да, то переключаемся обратно в оконный режим ShowCursor( TRUE ); // Показать курсор мышки } if( hRC ) // Существует ли Контекст Рендеринга? { if( !wglMakeCurrent( NULL, NULL ) ) // Возможно ли освободить RC и DC? { MessageBox( NULL, "Release Of DC And RC Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION ); } if( !wglDeleteContext( hRC ) ) // Возможно ли удалить RC? { MessageBox( NULL, "Release Rendering Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION ); } hRC = NULL; // Установить RC в NULL } if( hDC && !ReleaseDC( hWnd, hDC ) ) // Возможно ли уничтожить DC? { MessageBox( NULL, "Release Device Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION ); hDC = NULL; // Установить DC в NULL } if(hWnd && !DestroyWindow(hWnd)) // Возможно ли уничтожить окно? { MessageBox( NULL, "Could Not Release hWnd.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION ); hWnd = NULL; // Установить hWnd в NULL } if( !UnregisterClass( "OpenGL", hInstance ) ) // Возможно ли разрегистрировать класс { MessageBox( NULL, "Could Not Unregister Class.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); hInstance = NULL; // Установить hInstance в NULL } }
// // Destroys the control communication window. // static void destroy_control_window() { DestroyWindow(cwindow); cwindow = NULL; UnregisterClass(klass.lpszClassName, klass.hInstance); }
static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { MButtonCtrl *bct = (MButtonCtrl *) GetWindowLongPtr(hwndDlg, 0); switch (msg) { case WM_NCCREATE: { SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLong(hwndDlg, GWL_STYLE) | BS_OWNERDRAW); bct = reinterpret_cast<MButtonCtrl *>(malloc(sizeof(MButtonCtrl))); if (bct == NULL) return FALSE; bct->hwnd = hwndDlg; bct->stateId = PBS_NORMAL; bct->focus = 0; bct->hFont = reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)); bct->arrow = NULL; bct->defbutton = 0; bct->hIcon = bct->hIconPrivate = 0; bct->iIcon = 0; bct->hIml = 0; bct->hBitmap = NULL; bct->pushBtn = 0; bct->pbState = 0; bct->hThemeButton = NULL; bct->hThemeToolbar = NULL; bct->cHot = 0; bct->flatBtn = 0; bct->bThemed = FALSE; bct->bSkinned = bct->bSendOnDown = 0; bct->buttonItem = NULL; LoadTheme(bct); SetWindowLongPtr(hwndDlg, 0, (LONG_PTR) bct); if (((CREATESTRUCTA *) lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *) lParam)->lpszName); return TRUE; } case WM_DESTROY: { if (bct) { if (hwndToolTips) { TOOLINFO ti; ZeroMemory(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR) bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM) &ti)) { SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM) &ti); } if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM) &ti) == 0) { DestroyWindow(hwndToolTips); hwndToolTips = NULL; } } if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); DestroyTheme(bct); free(bct); } SetWindowLongPtr(hwndDlg, 0, 0); break; // DONT! fall thru } case WM_SETTEXT: { bct->cHot = 0; if ((char*) lParam) { char *tmp = (char *) lParam; while (*tmp) { if (*tmp == '&' && *(tmp + 1)) { bct->cHot = tolower(*(tmp + 1)); break; } tmp++; } InvalidateRect(bct->hwnd, NULL, TRUE); lstrcpyn(bct->szText, (TCHAR *)lParam, 127); bct->szText[127] = 0; } break; } case WM_SYSKEYUP: if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == tolower((int) wParam)) { if (bct->pushBtn) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; InvalidateRect(bct->hwnd, NULL, TRUE); } if(!bct->bSendOnDown) SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); return 0; } break; case WM_THEMECHANGED: { if (bct->bThemed) LoadTheme(bct); InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it break; } case WM_SETFONT: // remember the font so we can use it later { bct->hFont = (HFONT) wParam; // maybe we should redraw? break; } case WM_NCPAINT: case WM_PAINT: { PAINTSTRUCT ps; HDC hdcPaint; hdcPaint = BeginPaint(hwndDlg, &ps); if (hdcPaint) { PaintWorker(bct, hdcPaint); EndPaint(hwndDlg, &ps); } break; } case BM_GETIMAGE: if(wParam == IMAGE_ICON) return (LRESULT)(bct->hIconPrivate ? bct->hIconPrivate : bct->hIcon); break; case BM_SETIMAGE: if(!lParam) break; bct->hIml = 0; bct->iIcon = 0; if (wParam == IMAGE_ICON) { ICONINFO ii = {0}; BITMAP bm = {0}; if (bct->hIconPrivate) { DestroyIcon(bct->hIconPrivate); bct->hIconPrivate = 0; } GetIconInfo((HICON) lParam, &ii); GetObject(ii.hbmColor, sizeof(bm), &bm); if (bm.bmWidth > g_cxsmIcon || bm.bmHeight > g_cysmIcon) { HIMAGELIST hImageList; hImageList = ImageList_Create(g_cxsmIcon, g_cysmIcon, IsWinVerXPPlus() ? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0); ImageList_AddIcon(hImageList, (HICON) lParam); bct->hIconPrivate = ImageList_GetIcon(hImageList, 0, ILD_NORMAL); ImageList_RemoveAll(hImageList); ImageList_Destroy(hImageList); bct->hIcon = 0; } else { bct->hIcon = (HICON) lParam; bct->hIconPrivate = 0; } DeleteObject(ii.hbmMask); DeleteObject(ii.hbmColor); bct->hBitmap = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } else if (wParam == IMAGE_BITMAP) { bct->hBitmap = (HBITMAP) lParam; if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIcon = bct->hIconPrivate = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; case BM_SETPRIVATEICON: bct->hIml = 0; bct->iIcon = 0; { if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIconPrivate = DuplicateIcon(g_hInst, (HICON) lParam); bct->hIcon = 0; break; } case BM_SETIMLICON: { if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIml = (HIMAGELIST) wParam; bct->iIcon = (int) lParam; bct->hIcon = bct->hIconPrivate = 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; } case BM_SETSKINNED: bct->bSkinned = (DWORD)lParam; bct->bThemed = bct->bSkinned ? FALSE : bct->bThemed; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BM_SETBTNITEM: bct->buttonItem = (ButtonItem *)lParam; break; case BM_SETASMENUACTION: bct->bSendOnDown = wParam ? TRUE : FALSE; return 0; case BM_SETCHECK: if (!bct->pushBtn) break; if (wParam == BST_CHECKED) { bct->pbState = 1; bct->stateId = PBS_PRESSED; } else if (wParam == BST_UNCHECKED) { bct->pbState = 0; bct->stateId = PBS_NORMAL; } InvalidateRect(bct->hwnd, NULL, TRUE); break; case BM_GETCHECK: if (bct->pushBtn) { return bct->pbState ? BST_CHECKED : BST_UNCHECKED; } return 0; case BUTTONSETARROW: // turn arrow on/off if (wParam) { if (!bct->arrow) bct->arrow = (HICON) LoadImage(g_hInst, MAKEINTRESOURCE(IDI_MINIMIZE), IMAGE_ICON, g_cxsmIcon, g_cysmIcon, 0); } else { if (bct->arrow) { DestroyIcon(bct->arrow); bct->arrow = NULL; } } InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETDEFAULT: bct->defbutton = wParam ? 1 : 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASPUSHBTN: bct->pushBtn = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASFLATBTN: bct->flatBtn = lParam == 0 ? 1 : 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASFLATBTN + 10: bct->bThemed = lParam ? TRUE : FALSE; bct->bSkinned = bct->bThemed ? 0 : bct->bSkinned; break; case BUTTONADDTOOLTIP: { TOOLINFO ti; if (!(char*) wParam) break; if (!hwndToolTips) { hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); SetWindowPos(hwndToolTips, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); } ZeroMemory(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR) bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM) &ti)) { SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM) &ti); } ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.uId = (UINT_PTR) bct->hwnd; ti.lpszText = (TCHAR *) wParam; SendMessage(hwndToolTips, TTM_ADDTOOL, 0, (LPARAM) &ti); break; } case WM_SETFOCUS: // set keybord focus and redraw bct->focus = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_KILLFOCUS: // kill focus and redraw bct->focus = 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_WINDOWPOSCHANGED: InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_ENABLE: // windows tells us to enable/disable { bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED; InvalidateRect(bct->hwnd, NULL, TRUE); break; } case WM_MOUSELEAVE: // faked by the WM_TIMER { if (bct->stateId != PBS_DISABLED) { // don't change states if disabled bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; } case WM_LBUTTONDOWN: { if (bct->stateId != PBS_DISABLED && bct->stateId != PBS_PRESSED) { bct->stateId = PBS_PRESSED; InvalidateRect(bct->hwnd, NULL, TRUE); if(bct->bSendOnDown) { SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } } break; } case WM_LBUTTONUP: { if (bct->pushBtn) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; } if (bct->stateId != PBS_DISABLED) { // don't change states if disabled if (msg == WM_LBUTTONUP) bct->stateId = PBS_HOT; else bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } if(!bct->bSendOnDown) SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); break; } case WM_MOUSEMOVE: if (bct->stateId == PBS_NORMAL) { bct->stateId = PBS_HOT; InvalidateRect(bct->hwnd, NULL, TRUE); } // Call timer, used to start cheesy TrackMouseEvent faker SetTimer(hwndDlg, BUTTON_POLLID, BUTTON_POLLDELAY, NULL); break; case WM_NCHITTEST: { LRESULT lr = SendMessage(GetParent(hwndDlg), WM_NCHITTEST, wParam, lParam); if(lr == HTLEFT || lr == HTRIGHT || lr == HTBOTTOM || lr == HTTOP || lr == HTTOPLEFT || lr == HTTOPRIGHT || lr == HTBOTTOMLEFT || lr == HTBOTTOMRIGHT) return HTTRANSPARENT; break; } case WM_TIMER: // use a timer to check if they have did a mouseout { if (wParam == BUTTON_POLLID) { RECT rc; POINT pt; GetWindowRect(hwndDlg, &rc); GetCursorPos(&pt); if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave PostMessage(hwndDlg, WM_MOUSELEAVE, 0, 0L); KillTimer(hwndDlg, BUTTON_POLLID); } } break; } case WM_ERASEBKGND: return 1; } return DefWindowProc(hwndDlg, msg, wParam, lParam); }
///////////////////////////////////////////////////////////////////// // Main window message procedure. This is the window manager for // the application LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HDC hDC = NULL; // GDI Device context static HGLRC hRC = NULL; // OpenGL Rendering context switch (message) { // Window is created, the application is starting case WM_CREATE: { hDC = GetDC(hWnd); static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // Size of struct 1, // Version of struct PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // PFD_TYPE_RGBA, // Always put this 32, // Always put this, size of the color buffer 0,0,0,0,0,0,0,0,0,0,0,0,0, // You have no control over 16, // Depth of the Z buffer 8, // Stencil buffer 0,0,0,0,0,0 }; // Either obsolete, or we don't care about int nPF = ChoosePixelFormat(hDC, &pfd); SetPixelFormat(hDC, nPF, &pfd); // Create rendering context hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); glRenderer.Initialize(); } break; // Do not validate, this is sent repeatedly case WM_PAINT: glRenderer.Render(); SwapBuffers(hDC); if(!glRenderer.GetAnimated()) ValidateRect(hWnd, NULL); break; case WM_SIZE: glRenderer.Resize(LOWORD(lParam), HIWORD(lParam)); break; // Window is destroyed, it's the end of the application case WM_DESTROY: // Cleanup glRenderer.Shutdown(); wglMakeCurrent(hDC, NULL); wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); PostQuitMessage(0); break; // Window is either full screen, or not visible case WM_ACTIVATE: { // Only handled when full screen mode if(glRenderer.GetFullScreen()) { WINDOWPLACEMENT wndPlacement; wndPlacement.length = sizeof(WINDOWPLACEMENT); wndPlacement.flags = WPF_RESTORETOMAXIMIZED; wndPlacement.ptMaxPosition.x = 0; wndPlacement.ptMaxPosition.y = 0; wndPlacement.ptMinPosition.x = 0; wndPlacement.ptMinPosition.y = 0; wndPlacement.rcNormalPosition.bottom = gDevMode.dmPelsHeight; wndPlacement.rcNormalPosition.left = 0; wndPlacement.rcNormalPosition.top = 0; wndPlacement.rcNormalPosition.right = gDevMode.dmPelsWidth; if(LOWORD(wParam) == WA_INACTIVE) { wndPlacement.showCmd = SW_SHOWMINNOACTIVE; SetWindowPlacement(hWnd, &wndPlacement); ShowCursor(TRUE); } else { wndPlacement.showCmd = SW_RESTORE; SetWindowPlacement(hWnd, &wndPlacement); ShowCursor(FALSE); } } } break; // Handle keyboard input case WM_CHAR: // Close program on ESC key press if(wParam == 27) DestroyWindow(hWnd); break; case WM_CLOSE: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // 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; PAINTSTRUCT ps; HDC hdc; HPEN oldPen, hPen; HBRUSH oldBrush, pieceBrush[2], boardBrush[3]; RECT rect; static HWND msgbox; static bool show = true; static int step = 0; static PieceAct rc = { -1, -1, -1, -1, -1, -1, -1, -1}; static enum State state = Start; static short role = BLACK; static short board[8][8] = {}; short x_mouse = 0, y_mouse = 0; static CString s; const int ID_TIMER = 1; static time_t start, finish, elapsed; struct tm * ptm; switch (message) { case WM_CREATE: msgbox = CreateWindowEx(NULL, L"ListBox", L"Message",WS_VISIBLE, 750, 50, 250, 250, hWnd, NULL, hInst, NULL); ShowWindow(msgbox, SW_SHOW); UpdateWindow(msgbox); memcpy(board,initboard,sizeof(board)); start = time(0); state = NextState(0,0,state,board,&role,&rc); hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; s.Format(L"Welcome to checker!"); TextOut(hdc, 20,125,s, s.GetLength()); switch (state){ case MovePick: s.Format(L"Action: Pick a piece to move."); break; case MoveDrop: s.Format(L"Action: Drop a piece to move."); break; case JumpPick: s.Format(L"Action: Pick a piece to jump."); break; case JumpDrop: s.Format(L"Action: Drop a piece to jump."); break; case MultiJump: s.Format(L"Action: You can jump again."); break; default: s.Format(L"Game Stop!"); break; } TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); if (state == Animate) { step = STEP; SetTimer(hWnd, ID_TIMER, 10 , NULL); //update every 10 milliseconds } break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case ID_RESET: step = 0; rc.x_pick = -1; rc.y_pick = -1; rc.x_drop = -1; rc.y_drop = -1; rc.x_jump2 = -1; rc.y_jump2 = -1; rc.x_jump3 = -1; rc.y_jump3 = -1; state = Start; role = BLACK; //curent role memcpy(board,initboard,sizeof(board)); start = time(0); state = NextState(0,0,state,board,&role,&rc); ShowWindow(msgbox, SW_HIDE); ShowWindow(msgbox, SW_SHOW); UpdateWindow(msgbox); hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; s.Format(L"Game Reset!"); TextOut(hdc, 20,125,s, s.GetLength()); switch (state){ case MovePick: s.Format(L"Action: Pick a piece to move."); break; case MoveDrop: s.Format(L"Action: Drop a piece to move."); break; case JumpPick: s.Format(L"Action: Pick a piece to jump."); break; case JumpDrop: s.Format(L"Action: Drop a piece to jump."); break; case MultiJump: s.Format(L"Action: You can jump again."); break; default: s.Format(L"Game Stop!"); break; } TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); if (state == Animate) { step = STEP; SetTimer(hWnd, ID_TIMER, 10 , NULL); //update every 10 milliseconds } InvalidateRect (hWnd, NULL, TRUE) ; break; case ID_SHOW: show = !show; if (show) ShowWindow(msgbox, SW_SHOW); else ShowWindow(msgbox, SW_HIDE); UpdateWindow(msgbox); SetFocus(hWnd); break; case ID_DIFFICULTY_LEVEL1: maxDepth = 1; break; case ID_DIFFICULTY_LEVEL2: maxDepth = 4; break; case ID_DIFFICULTY_LEVEL3: maxDepth = 8; break; case ID_DIFFICULTY_LEVEL4: maxDepth = 15; break; case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_LBUTTONDOWN: if(state == Animate) break; // do not react while moving x_mouse = short(HIWORD (lParam)/LENGTH); y_mouse = short(LOWORD (lParam)/LENGTH); state = NextState(x_mouse,y_mouse,state,board,&role,&rc); if (state == Animate) { step = STEP; SetTimer(hWnd, ID_TIMER, 10 , NULL); //update every 10 milliseconds if (role == BLACK) start = time(0); } else if (state != GameStop) { hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; switch (state){ case MovePick: s.Format(L"Next Action: Pick a piece to move."); break; case MoveDrop: s.Format(L"Next Action: Drop a piece to move."); break; case JumpPick: s.Format(L"Next Action: Pick a piece to jump."); break; case JumpDrop: s.Format(L"Next Action: Drop a piece to jump."); break; case MultiJump: s.Format(L"Next Action: You can jump again."); break; default: s.Format(L"Game Stop!"); break; } TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); } InvalidateRect (hWnd, NULL, TRUE) ; break; case WM_TIMER: if (step--==0) { state = NextState(0,0,state,board,&role,&rc); KillTimer(hWnd, ID_TIMER); if (state == GameStop && show!=false) { // update the message box ShowWindow(msgbox, SW_HIDE); ShowWindow(msgbox, SW_SHOW); UpdateWindow(msgbox); hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; s.Format(L"Game finished!"); TextOut(hdc, 20,110,s, s.GetLength()); int b_score = 0, w_score = 0; for(int i = 0; i<8; i++) for(int j = 0; j<8; j++) { if(board[i][j] == BLACK) if (i == 0) b_score += 2; else b_score ++; if(board[i][j] == WHITE) if (i == 7) w_score += 2; else w_score ++; } s.Format(L"Black Score : %d",b_score); TextOut(hdc, 20,140,s, s.GetLength()); s.Format(L"White Score : %d",w_score); TextOut(hdc, 20,170,s, s.GetLength()); if (b_score>w_score) s.Format(L"You Win!"); if (b_score==w_score) s.Format(L"Draw!"); if (b_score<w_score) s.Format(L"You Lost!"); TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); } else if (role == BLACK && state != Animate) { finish = time(0); elapsed = static_cast<time_t>(difftime(finish,start)); ptm = gmtime (&elapsed); // update the message box if (show) { ShowWindow(msgbox, SW_HIDE); ShowWindow(msgbox, SW_SHOW); UpdateWindow(msgbox); hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; s.Format(L"Maximum tree depth: %d.",treeDepth); TextOut(hdc, 20,50,s, s.GetLength()); s.Format(L"Node generated: %d.",genNode); TextOut(hdc, 20,80,s, s.GetLength()); s.Format(L"MAX-VALUE pruned: %d.",pruneMax); TextOut(hdc, 20,110,s, s.GetLength()); s.Format(L"MIN-VALUE pruned: %d.",pruneMin); TextOut(hdc, 20,140,s, s.GetLength()); s.Format(L"Running Time: %2d:%2d.", ptm->tm_min, ptm->tm_sec); TextOut(hdc, 20, 170,s, s.GetLength()); switch (state){ case MovePick: s.Format(L"Next Action: Pick a piece to move."); break; case MoveDrop: s.Format(L"Next Action: Drop a piece to move."); break; case JumpPick: s.Format(L"Next Action: Pick a piece to jump."); break; case JumpDrop: s.Format(L"Next Action: Drop a piece to jump."); break; case MultiJump: s.Format(L"Next Action: You can jump again."); break; default: s.Format(L"BLACK move first!"); break; } TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); } } else if (state == Animate) { step = STEP; SetTimer(hWnd, ID_TIMER, 10 , NULL); //update every 10 milliseconds } } InvalidateRect (hWnd, NULL, TRUE) ; break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... //create the pen & brush inside "case" and delete before leave! hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); // black pieceBrush[0] = CreateSolidBrush(RGB(255, 255, 255)); // white pieceBrush[1] = CreateSolidBrush(RGB(0, 0, 0)); // black boardBrush[0] = CreateSolidBrush(RGB(255, 255, 255)); // white boardBrush[1] = CreateSolidBrush(RGB(200, 200, 200)); // gray boardBrush[2] = CreateSolidBrush(RGB(0, 200, 0)); // green // Select our green pen into the device context and remember previous pen oldPen = (HPEN)SelectObject(hdc, hPen); oldBrush = (HBRUSH)SelectObject(hdc, pieceBrush[0]); // draw back ground board for (int i = 0 ; i < 8 ; i++) for (int j = 0 ; j < 8 ; j++) { rect.top = i * LENGTH; rect.bottom = (i + 1) * LENGTH; rect.left = j * LENGTH; rect.right = (j + 1) * LENGTH; FillRect(hdc, &rect, boardBrush[(i+j)%2]); } // draw pick board if (state == MoveDrop || state == JumpDrop || state == MultiJump || state == Animate){ rect.top = rc.x_pick * LENGTH; rect.bottom = (rc.x_pick + 1) * LENGTH; rect.left = rc.y_pick * LENGTH; rect.right = (rc.y_pick + 1) * LENGTH; FillRect(hdc, &rect, boardBrush[2]); } // draw piece for (int i = 0 ; i < 8 ; i++) for (int j = 0 ; j < 8 ; j++) { if(board[i][j] != 0) // i & j is transpost in board { SelectObject(hdc, pieceBrush[(board[i][j]+1)%2]); // WHITE % 2 = 1, BLACK % 2 = 0; Ellipse (hdc, j * LENGTH + 10, i * LENGTH + 10, (j+1) * LENGTH - 10, (i+1) * LENGTH - 10) ; SelectObject(hdc, pieceBrush[board[i][j]%2]); Ellipse (hdc, j * LENGTH + 30, i * LENGTH + 30, (j+1) * LENGTH - 30, (i+1) * LENGTH - 30) ; } } // draw moving piece if (state == Animate){ int xCurrent = (STEP - step) * (rc.x_drop * LENGTH - rc.x_pick * LENGTH)/STEP + rc.x_pick * LENGTH; int yCurrent = (STEP - step) * (rc.y_drop * LENGTH - rc.y_pick * LENGTH)/STEP + rc.y_pick * LENGTH; SelectObject(hdc, pieceBrush[(role+1)%2]); Ellipse (hdc, yCurrent + 10, xCurrent + 10, yCurrent + LENGTH - 10, xCurrent + LENGTH - 10) ; SelectObject(hdc, pieceBrush[role%2]); Ellipse (hdc, yCurrent + 30, xCurrent + 30, yCurrent + LENGTH - 30, xCurrent + LENGTH - 30) ; } // Do not forget to clean up. // Select the old pen back into the device context SelectObject(hdc, oldPen); DeleteObject(hPen); SelectObject(hdc, oldBrush); DeleteObject(pieceBrush[0]); DeleteObject(pieceBrush[1]); DeleteObject(boardBrush[0]); DeleteObject(boardBrush[1]); DeleteObject(boardBrush[2]); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
// // 函数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: 处理主窗口的消息。 // // WM_COMMAND - 处理应用程序菜单 // WM_PAINT - 绘制主窗口 // WM_DESTROY - 发送退出消息并返回 // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static HWND hwndNextViewer; HGLOBAL hGlobal; PTSTR pGlobal; RECT rect; switch (message) { case WM_CREATE: hwndNextViewer = SetClipboardViewer(hWnd); break; case WM_CHANGECBCHAIN: if((HWND)wParam == hwndNextViewer) hwndNextViewer = (HWND)lParam; else if(hwndNextViewer) SendMessage(hwndNextViewer, message, wParam, lParam); //return 0; break; case WM_DRAWCLIPBOARD: if(hwndNextViewer) SendMessage(hwndNextViewer, message, wParam, lParam); InvalidateRect(hWnd, NULL, TRUE); //return 0; break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 分析菜单选择: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 在此添加任意绘图代码... // OpenClipboard, GetClipboardData, CloseClipboard GetClientRect(hWnd, &rect); OpenClipboard(hWnd); #ifdef UNICODE hGlobal = GetClipboardData(CF_UNICODETEXT); #else hGlobal = GetClipboardData(CF_TEXT); #endif if(hGlobal != NULL) { pGlobal = (PTSTR)GlobalLock(hGlobal); DrawText(hdc, pGlobal, -1, &rect, DT_EXPANDTABS); GlobalUnlock(hGlobal); } CloseClipboard(); EndPaint(hWnd, &ps); break; case WM_DESTROY: ChangeClipboardChain(hWnd, hwndNextViewer); PostQuitMessage(0); //return 0; break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; //RECT rect; int num=0; switch (message) { case WM_CREATE: StartUp(); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_FILE_NEW: StartUp(); WinCheck(); if(wongame==true) StartUp(); InvalidateRect(hWnd,NULL,FALSE); break; case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); //GetClientRect(hWnd,&rect); for(int i=0;i<4;i++) for(int j=0;j<4;j++) OnPaint(hdc,j*64,i*64,Pole[i][j]); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_LBUTTONDOWN: POINT pt; GetCursorPos(&pt); ScreenToClient(hWnd,&pt); SwapNum((int)pt.x/64,(int)pt.y/64); InvalidateRect(hWnd,NULL,FALSE); if(wongame == true) MessageBox(hWnd,"You Won The Game!","Congradulations !",NULL); break; case WM_WINDOWPOSCHANGED: //case WM_MOVE: InvalidateRect(hWnd,NULL,FALSE); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // 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; PAINTSTRUCT ps; HDC hdc; static RECT rcce = { 0 }; static RECT rcst = { 0 }; static RECT rcsd = { 200, 200, 200, 200 }; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_NCLBUTTONDOWN: { POINT pt = { 0 }; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); RECT rc = { 0 }; ::GetWindowRect(hWnd, &rc); // Cursor to edge rcce.left = rc.left - pt.x; rcce.top = rc.top - pt.y; rcce.right = rc.right - pt.x; rcce.bottom = rc.bottom - pt.y; return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_ENTERSIZEMOVE: { // Snap zone = Work area ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rcst, 0); } break; case WM_EXITSIZEMOVE: break; case WM_MOVING: { LPRECT lprc = (LPRECT)lParam; POINT pt = { 0 }; ::GetCursorPos(&pt); ::SnapUnsnapRect(lprc, &pt, &rcce, &rcst, &rcsd); } break; case WM_SIZING: { PRECT prc = (PRECT)lParam; switch (wParam) { case WMSZ_LEFT: if (prc->left < rcst.left + rcsd.left) prc->left = rcst.left; break; case WMSZ_RIGHT: if (prc->right > rcst.right - rcsd.right) prc->right = rcst.right; break; case WMSZ_TOP: if (prc->top < rcst.top + rcsd.top) prc->top = rcst.top; break; case WMSZ_TOPLEFT: if (prc->left < rcst.left + rcsd.left) prc->left = rcst.left; if (prc->top < rcst.top + rcsd.top) prc->top = rcst.top; break; case WMSZ_TOPRIGHT: if (prc->right > rcst.right - rcsd.right) prc->right = rcst.right; if (prc->top < rcst.top + rcsd.top) prc->top = rcst.top; break; case WMSZ_BOTTOM: if (prc->bottom > rcst.bottom - rcsd.bottom) prc->bottom = rcst.bottom; break; case WMSZ_BOTTOMLEFT: if (prc->left < rcst.left + rcsd.left) prc->left = rcst.left; if (prc->bottom > rcst.bottom - rcsd.bottom) prc->bottom = rcst.bottom; break; case WMSZ_BOTTOMRIGHT: if (prc->right > rcst.right - rcsd.right) prc->right = rcst.right; if (prc->bottom > rcst.bottom - rcsd.bottom) prc->bottom = rcst.bottom; break; } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void SettingsAdvanced::DestroyPane() { DestroyWindow(hwnd); hwnd = NULL; }
//取消 void CDlgInsureGame::OnCancel() { DestroyWindow(); }
INT_PTR CALLBACK DlgProc( _In_ HWND hDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { int wmId, wmEvent; static ChromeInfo chromeInfo; static TCHAR ltcChromeDetected[MAX_LOADSTRING]; static TCHAR ltcChromeNotDetected[MAX_LOADSTRING]; static TCHAR ltcSendSuccess[MAX_LOADSTRING]; static TCHAR ltcSendFailed[MAX_LOADSTRING]; static char szVariable[MAX_LOADSTRING]; static char sRawFilepath[MAX_PATH]; static char sUrl[MAX_PATH]; static tstringstream os; switch (uMsg) { case WM_INITDIALOG: { HINSTANCE hInstance = reinterpret_cast<HINSTANCE>(lParam); TCHAR szTemp[MAX_LOADSTRING]; if (0 != LoadString(hInstance, IDS_APP_TITLE, szTemp, MAX_LOADSTRING)){ SetWindowText(hDlg, szTemp); } if (0 != LoadString(hInstance, IDS_BTN_SEND_CAPTION, szTemp, MAX_LOADSTRING)){ SetDlgItemText(hDlg, IDC_BTN_SEND, szTemp); } LoadStringOrDefault(hInstance, ltcChromeDetected, MAX_LOADSTRING, IDS_CHROME_DETECTED, g_tcChromeDetected); LoadStringOrDefault(hInstance, ltcChromeNotDetected, MAX_LOADSTRING, IDS_CHROME_NOTDETECTED, g_tcChromeNotDetected); SetDlgItemText(hDlg, IDC_LBL_CHROME_STATUS, ltcChromeNotDetected); LoadStringOrDefault(hInstance, ltcSendFailed, MAX_LOADSTRING, IDS_SEND_FAILED, g_tcSendFailed); LoadStringOrDefault(hInstance, ltcSendSuccess, MAX_LOADSTRING, IDS_SEND_SUCCESS, g_tcSendSuccess); SetDlgItemText(hDlg, IDC_LBL_SEND_STATUS, TEXT("")); if (0 != SetTimer(hDlg, IDT_REFRESH_CHROME_STATUS, int(1000 / refreshratehz), NULL)) { ShowWindow(GetDlgItem(hDlg, IDC_BTN_REFRESH), SW_HIDE); } else { if (0 != LoadString(hInstance, IDS_BTN_REFRESH_CAPTION, szTemp, MAX_LOADSTRING)){ SetDlgItemText(hDlg, IDC_BTN_REFRESH, szTemp); } ShowWindow(GetDlgItem(hDlg, IDC_BTN_REFRESH), SW_SHOW); } char* pTemp = 0; if (AllocAndCopyTCtoMB(&pTemp, g_tcRawFilepath, MAX_PATH)) { StringCbCopyA(sRawFilepath, MAX_PATH, pTemp); delete[] pTemp; } pTemp = 0; if (AllocAndCopyTCtoMB(&pTemp, g_tcUrl, MAX_PATH)) { StringCbCopyA(sUrl, MAX_PATH, pTemp); delete[] pTemp; } StringCbCopyA(szVariable, MAX_LOADSTRING, "filearg"); UpdateField(hDlg, IDC_EDT_FILEPATH, sRawFilepath, MAX_PATH, true); UpdateField(hDlg, IDC_EDT_SEND_URL, sUrl, MAX_PATH, true); } return TRUE; case WM_TIMER: switch (wParam) { case IDT_REFRESH_CHROME_STATUS: if(DetectChrome(&chromeInfo, g_tcImageName)){ os.str(TEXT("")); os.clear(); os<<ltcChromeDetected<<" (pid: "<<chromeInfo.dwProcId<<")"<<std::endl; SetDlgItemText(hDlg, IDC_LBL_CHROME_STATUS, os.str().c_str()); } else { SetDlgItemText(hDlg, IDC_LBL_CHROME_STATUS, ltcChromeNotDetected); } return TRUE; } break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); switch (wmId) { case IDCANCEL: SendMessage(hDlg, WM_CLOSE, 0, 0); return TRUE; case IDC_BTN_SEND:{ UpdateField(hDlg, IDC_EDT_FILEPATH, sRawFilepath, MAX_PATH); UpdateField(hDlg, IDC_EDT_SEND_URL, sUrl, MAX_PATH); TCHAR tcRawFilepath[MAX_PATH]; TCHAR tcUrl[MAX_PATH]; TCHAR* pTemp = 0; if (AllocAndCopyMBtoTC(&pTemp, sUrl, MAX_PATH)) { StringCbCopy(tcUrl, MAX_PATH, pTemp); delete[] pTemp; } pTemp = 0; if (AllocAndCopyMBtoTC(&pTemp, sRawFilepath, MAX_PATH)) { StringCbCopy(tcRawFilepath, MAX_PATH, pTemp); delete[] pTemp; } TCHAR tcFullPath[MAX_PATH]; TCHAR *tcFilenamePart; if(CreateFullPath(tcRawFilepath, tcFullPath, sizeof(tcFullPath)/ sizeof(TCHAR), &tcFilenamePart) ) { char* pFilenamePart = 0; if (AllocAndCopyTCtoMB(&pFilenamePart, tcFilenamePart, MAX_PATH)) if(SendFile(GetFile(tcFullPath), tcUrl, szVariable, pFilenamePart)) { SetDlgItemText(hDlg, IDC_LBL_SEND_STATUS, ltcSendSuccess); } else { SetDlgItemText(hDlg, IDC_LBL_SEND_STATUS, ltcSendFailed); } if(pFilenamePart) delete[] pFilenamePart; } } return TRUE; case IDC_BTN_REFRESH: if(DetectChrome(&chromeInfo, g_tcImageName, true)){ SetDlgItemText(hDlg, IDC_LBL_CHROME_STATUS, ltcChromeDetected); } else { SetDlgItemText(hDlg, IDC_LBL_CHROME_STATUS, ltcChromeNotDetected); } return TRUE; } break; case WM_CLOSE: KillTimer(hDlg, IDT_REFRESH_CHROME_STATUS); DestroyWindow(hDlg); return TRUE; case WM_DESTROY: PostQuitMessage(0); return TRUE; } return FALSE; }
LRESULT APIENTRY WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hwndChild[4]; static TCHAR * szChildClass[] = { TEXT("Child1"), TEXT("Child2"), TEXT("Child3"), TEXT("Child4") }; static WNDPROC ChildProc[] = { WndProc1, WndProc2, WndProc3, WndProc4 }; HINSTANCE hInstance; int i, cxClient, cyClient; WNDCLASS wndclass; switch (message) { case WM_CREATE: hInstance = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = NULL; wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; for (i = 0; i < 4; i++) { wndclass.lpfnWndProc = ChildProc[i]; wndclass.lpszClassName = szChildClass[i]; RegisterClass(&wndclass); hwndChild[i] = CreateWindow(szChildClass[i], NULL, WS_CHILDWINDOW | WS_BORDER | WS_VISIBLE, 0, 0, 0, 0, hwnd, (HMENU)i, hInstance, NULL); } return 0; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); for (i = 0; i < 4; i++) MoveWindow(hwndChild[i], (i % 2) * cxClient / 2, (i > 1) * cyClient / 2, cxClient / 2, cyClient / 2, TRUE); return 0; case WM_CHAR: if (wParam == '\x1B') DestroyWindow(hwnd); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
///////////////////////////////////////////////////////// // // DlgProc // // The DlgProc function is an application-defined // function that processes messages sent to the dialog // // Parameters: // HWND hwnd : [in] handle to dialog window // UINT uMsg : [in] message identifier // WPARAM wParam : [in] first message parameter // LPARAM lParam : [in] second message parameter // // Return Values: // The return value is the result of the // message processing and depends on the message sent // ///////////////////////////////////////////////////////// BOOL CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM /* lParam */) { BOOL bReturn = FALSE; // the value to return switch (uMsg) { case WM_INITDIALOG: { // Initialize the COM if (FAILED(CoInitialize(NULL))) { MessageBoxW(NULL, L"Unable to initialize the COM library", gc_wszAppName, MB_OK | MB_ICONINFORMATION); PostMessage(hwnd, WM_CLOSE, 0, 0); break; } // Gather and show the information we're interested in // Check out if Microsoft Tablet PC Platform components of the // Microsoft Windows XP Professional Operating System are enabled int bTabletPC = GetSystemMetrics(SM_TABLETPC); SetDlgItemTextW(hwnd, IDC_TABLETPC, bTabletPC ? L"Available" : L"Not available"); // Get the version of the Text Services Framework components SInfo info; if (GetComponentInfo(CLSID_TF_ThreadMgr, info) == TRUE) { SetDlgItemTextW(hwnd, IDC_TSF, info.wchVersion); } // Find out the name and the version of the default handwriting recognizer // Create the enumerator for the installed recognizers IInkRecognizers* pIInkRecognizers = NULL; HRESULT hr = CoCreateInstance(CLSID_InkRecognizers, NULL, CLSCTX_INPROC_SERVER, IID_IInkRecognizers, (void **)&pIInkRecognizers); if (SUCCEEDED(hr)) { IInkRecognizer* pIInkRecognizer = NULL; // The first parameter is the language id, passing 0 means that the language // id will be retrieved using the user default-locale identifier hr = pIInkRecognizers->GetDefaultRecognizer(0, &pIInkRecognizer); if (SUCCEEDED(hr)) { // Get the recognizer's friendly name BSTR bstr; if (SUCCEEDED(pIInkRecognizer->get_Name(&bstr))) { SetDlgItemTextW(hwnd, IDC_HWR_NAME, bstr); SysFreeString(bstr); } else { SetDlgItemTextW(hwnd, IDC_HWR_NAME, L"Failed"); } // Get the recognizer's vendor info if (SUCCEEDED(pIInkRecognizer->get_Vendor(&bstr))) { SetDlgItemTextW(hwnd, IDC_HWR_VENDOR, bstr); SysFreeString(bstr); } else { SetDlgItemTextW(hwnd, IDC_HWR_VENDOR, L"Failed"); } // Release it pIInkRecognizer->Release(); pIInkRecognizer = NULL; } // Release the collection object pIInkRecognizers->Release(); pIInkRecognizers = NULL; } // Find out the name and the version of the default speech recognizer // Open key to find path of application HKEY hkeySpeech; if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, gc_wszSpeechKey, 0, KEY_READ, &hkeySpeech) == ERROR_SUCCESS) { // Query value of key to get the name of the component WCHAR wchValue[265]; ULONG cSize = sizeof(wchValue); if (RegQueryValueExW(hkeySpeech, L"DefaultDefaultTokenId", NULL, NULL, (BYTE*)wchValue, &cSize) == ERROR_SUCCESS) { int ndx = lstrlenW(L"HKEY_LOCAL_MACHINE\\"); int len = lstrlenW(wchValue); if (ndx < len && RegOpenKeyExW(HKEY_LOCAL_MACHINE, &wchValue[ndx], 0, KEY_READ, &hkeySpeech) == ERROR_SUCCESS) { cSize = sizeof(wchValue); if (RegQueryValueExW(hkeySpeech, NULL, NULL, NULL, (BYTE*)wchValue, &cSize) == ERROR_SUCCESS) { SetDlgItemTextW(hwnd, IDC_SPR_NAME, wchValue); } } } } // Find out which of the controls are installed and show their version info for (int i = 0, j = 0; i < NUM_CONTROLS; i++) { // Get the component info CLSID clsid; if (SUCCEEDED(CLSIDFromProgID(gc_wszProgId[i], &clsid)) && GetComponentInfo(clsid, info) == TRUE) { SetDlgItemTextW(hwnd, gc_uiCtrlId[j][0], info.wchName); SetDlgItemTextW(hwnd, gc_uiCtrlId[j][1], info.wchVersion); j++; } } // Done with the COM CoUninitialize(); break; } case WM_DESTROY: PostQuitMessage(0); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCLOSE: // User clicked on the "Close" button in the dialog. case IDCANCEL: // User clicked the close button ([X]) in the caption // or pressed Alt+F4. DestroyWindow(hwnd); bReturn = TRUE; break; } break; } return bReturn; }
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); }