LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if(uMsg == WM_SHELLHOOKMESSAGE) { int i; for(i = 0; shell_list[i].pMsg; i++) { if(shell_list[i].uMsg == wParam) { AddEditText(shell_list[i].pMsg, (HWND)lParam); return 0; } } return 0; } switch(uMsg) { case WM_SIZE: { RECT rect; GetClientRect(hwnd, &rect); MoveWindow(hwndEdit, 0, 0, rect.right - rect.left, rect.bottom - rect.top, TRUE); return 0; } case WM_CREATE: { RECT rect; hwndMain = hwnd; GetClientRect(hwnd, &rect); hwndEdit = CreateWindowEx(0, WC_EDIT, NULL, WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | WS_HSCROLL | WS_VSCROLL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hwnd, (HMENU)IDC_EDIT, ((CREATESTRUCT*)lParam)->hInstance, NULL); if(!SetShellHook(hwnd)) { MessageBox(hwnd, "SetShellHook, failed.", NULL, MB_OK); } return 0; } case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CLOSE: UnSetShellHook(hwnd); DestroyWindow(hwnd); return 0; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LPNMTOOLBAR lPEvent; LPNMTBGETINFOTIP lptbgit; LPNMMOUSE lpnm; LPNMTBDISPINFO lptbdi; LPNMKEY lpnmk; HDESK a, b, z; DWORD tid; DWORD pid; //--------------------- Windows Hook Events-------------------- if (message == WM_SHELLHOOKMESSAGE) { switch (LOWORD(wParam)) { case HSHELL_WINDOWCREATED: AddToList(hWnd, lParam, "HSHELL_WINDOWCREATED"); break; case HSHELL_WINDOWDESTROYED: RemoveFromList(hWnd, lParam, "HSHELL_WINDOWDESTROYED"); break; } return 0; } //--------------------------------------------------------------- switch (message) { case WM_MYBUTTON: case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: newhWnd = (HWND) lParam; lPEvent = (LPNMTOOLBAR) lParam; lptbgit = (LPNMTBGETINFOTIP) lParam; lptbdi = (LPNMTBDISPINFO) lParam; lpnm = (LPNMMOUSE) lParam; if (HIWORD(wParam) == EN_CHANGE) { Search((HWND) lParam); } switch (wmId) { case ID_PORT_BUTTON: // When Button Pressed OutputDebugString(L"Button Pressed \n"); 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_PAINT: GetClientRect(hWnd, &rect); hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... OutputDebugStringW(L"In Paint"); EndPaint(hWnd, &ps); break; case WM_DESTROY: freeList(); ImageList_Remove(g_hImageList, -1); ImageList_Destroy(g_hImageList); DestroyWindow(hWndToolbar); UnSetShellHook(hWnd); PostQuitMessage(0); break; case WM_NOTIFY: // Capture Notification Messages lptbgit = (LPNMTBGETINFOTIP) lParam; lPEvent = (LPNMTOOLBAR) lParam; lpnm = (LPNMMOUSE) lParam; lptbdi = (LPNMTBDISPINFO) lParam; newhWnd = (HWND) lParam; lpnmk = (LPNMKEY) lParam; TCHAR szText[0x1000]; switch (lPEvent->hdr.code) { case TBN_DROPDOWN: //When Dropdown Button Pressed OutputDebugString(L"Dropdown Pressed \n"); { // Get the coordinates of the button. RECT rc; if (!SendMessage(lPEvent->hdr.hwndFrom, TB_GETRECT, (WPARAM) lPEvent->iItem, (LPARAM) & rc)) OutputDebugString(L"Error get rect"); // Convert to screen coordinates. MapWindowPoints(lPEvent->hdr.hwndFrom, HWND_DESKTOP, (LPPOINT) & rc, 2); // Get the menu. HMENU hMenuLoaded = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU2)); HICON hIcon = (HICON) GetClassLong((HWND) lPEvent->tbButton.iBitmap, GCL_HICON); GetWindowText(((HWND) lPEvent->tbButton.dwData), szText, sizeof(szText)); // Get the submenu for the first menu item. HMENU hPopupMenu = GetSubMenu(hMenuLoaded, 0); AppendMenu(hPopupMenu, MF_STRING, 0, szText); TPMPARAMS tpm; tpm.cbSize = sizeof(TPMPARAMS); tpm.rcExclude = rc; TrackPopupMenuEx(hPopupMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL, rc.left, rc.bottom, hWnd, &tpm); return TRUE; } break; //case TBN_GETINFOTIP : default: break; } switch (lptbgit->hdr.code) { case TBN_GETINFOTIP: OutputDebugString(TEXT("ToolTip Info \n")); break; default: break; } switch (lPEvent->hdr.code) { HDESK b; case NM_CLICK: // When Taskbar Button Pressed OutputDebugString(L"ButtonPressed "); b = GetThreadDesktop(GetCurrentThreadId()); /* tid = GetWindowThreadProcessId((HWND) lPEvent->tbButton.iBitmap, &pid); a = GetThreadDesktop(tid); b = GetThreadDesktop(GetCurrentThreadId()); if (GetThreadDesktop(tid) != GetThreadDesktop(GetCurrentThreadId())) { SwitchDesktop((HDESK) a); ShowWindow(((HWND) lPEvent->tbButton.iBitmap), SW_RESTORE); SetForegroundWindow((HWND) lPEvent->tbButton.iBitmap); break; } if (IsIconic(((HWND) lPEvent->tbButton.iBitmap))) ShowWindow(((HWND) lPEvent->tbButton.iBitmap), SW_RESTORE); else ShowWindow(((HWND) lPEvent->tbButton.iBitmap), SW_MINIMIZE); */ if(GetParent((HWND) lPEvent->tbButton.iBitmap) != hWnd) SetParent((HWND) lPEvent->tbButton.iBitmap,hWnd); else SetParent((HWND) lPEvent->tbButton.iBitmap,NULL); break; default: break; } break; case WM_CREATE: break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }