// Private HICON TrayIcon::GetWindowIcon(HWND hWnd) { HICON hIcon; hIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, NULL); if (hIcon) { return hIcon; } hIcon = (HICON)GetClassLongPtr(hWnd, GCLP_HICONSM); if (hIcon) { return hIcon; } hIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, NULL); if (hIcon) { return hIcon; } hIcon = (HICON)GetClassLongPtr(hWnd, GCLP_HICON); if (hIcon) { return hIcon; } return hIcon; }
HICON GetWindowIcon(HWND windowHandle) { DWORD_PTR hIco = 0; int HICON1 = -14; int HICONSM = -34; SendMessageTimeout(windowHandle, 0x007f, 2, 0, 2, 200, (PDWORD_PTR)hIco); if (hIco == 0) { SendMessageTimeout(windowHandle, 0x007f, 0, 0, 2, 200, (PDWORD_PTR)hIco); } if (hIco == 0) { hIco = GetClassLongPtr(windowHandle, HICONSM); } if (hIco == 0) { hIco = GetClassLongPtr(windowHandle, HICON1); } return (HICON)hIco; //DWORD_PTR dwReturn = GetClassLongPtr(windowHandle, (-14)); //return (HICON)dwReturn; }
// Draw the System Icon void cef_dark_window::DoDrawSystemMenuIcon(HDC hdc) { if (mWindowIcon == 0) { // We haven't cached the icon yet so figure out // which one we need. // First try to load the small icon mWindowIcon = (HICON)SendMessage(WM_GETICON, ICON_SMALL, 0); // Otherwise try to use the big icon if (!mWindowIcon) mWindowIcon = (HICON)SendMessage(WM_GETICON, ICON_BIG, 0); // If that doesn't work check the window class for an icon // Start with the small if (!mWindowIcon) mWindowIcon = reinterpret_cast<HICON>(GetClassLongPtr(GCLP_HICONSM)); // Then try to load the big icon if (!mWindowIcon) mWindowIcon = reinterpret_cast<HICON>(GetClassLongPtr(GCLP_HICON)); // Otherwise we need an icon, so just use the standard Windows default // application Icon which may very between versions if (!mWindowIcon) mWindowIcon = ::LoadIcon(NULL, IDI_APPLICATION); } RECT rectIcon; ComputeWindowIconRect(rectIcon); ::DrawIconEx(hdc, rectIcon.left, rectIcon.top, mWindowIcon, ::RectWidth(rectIcon), ::RectHeight(rectIcon), 0, NULL, DI_NORMAL); }
HICON GetWindowIcon(HWND hwnd) { HICON icon; if (icon = (HICON)SendMessage(hwnd, WM_GETICON, ICON_SMALL, 0)) return icon; if (icon = (HICON)SendMessage(hwnd, WM_GETICON, ICON_BIG, 0)) return icon; if (icon = (HICON)GetClassLongPtr(hwnd, GCLP_HICONSM)) return icon; if (icon = (HICON)GetClassLongPtr(hwnd, GCLP_HICON)) return icon; return LoadIcon(NULL, IDI_WINLOGO); }
static void GetWindowIcons(HWND hwnd, HICON* phIcon, HICON* phIconSm) { _ASSERT(phIcon); BOOL fIsHungApp = FALSE; HICON hIcon = NULL; if (!SendMessageTimeout(hwnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG, HUNG_TIMEOUT, (PDWORD_PTR)&hIcon)) { DWORD dwErr = GetLastError(); if (dwErr == 0 || dwErr == 1460) { fIsHungApp = TRUE; goto _HUNG_ICON; } } if (!hIcon) hIcon = (HICON)(UINT_PTR)GetClassLongPtr(hwnd, GCLP_HICON); if (!hIcon) { _HUNG_ICON: hIcon = LoadIcon(NULL, IDI_APPLICATION); } *phIcon = hIcon; if (phIconSm) { if (fIsHungApp) goto _HUNG_ICONSM; hIcon = NULL; if (!SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG, HUNG_TIMEOUT, (PDWORD_PTR)&hIcon)) { DWORD dwErr = GetLastError(); if (dwErr == 0 || dwErr == 1460) goto _HUNG_ICONSM; } if (!hIcon) { if (!SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL2, 0, SMTO_ABORTIFHUNG, HUNG_TIMEOUT, (PDWORD_PTR)&hIcon)) { DWORD dwErr = GetLastError(); if (dwErr == 0 || dwErr == 1460) goto _HUNG_ICONSM; } } if (!hIcon) { hIcon = (HICON)(UINT_PTR)GetClassLongPtr(hwnd, GCLP_HICONSM); } if (hIcon) { *phIconSm = hIcon; } else { _HUNG_ICONSM: *phIconSm = *phIcon; } } }
HICON GetIcon(HWND iWin) { HICON hIcon = NULL; SendMessageTimeout(iWin, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG|SMTO_BLOCK, 300, (PDWORD_PTR)&hIcon); if (NULL == hIcon) hIcon = (HICON)(DWORD_PTR)GetClassLongPtr(iWin, GCLP_HICON); if (NULL == hIcon) SendMessageTimeout(iWin, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG|SMTO_BLOCK, 300, (PDWORD_PTR)&hIcon); if (NULL == hIcon) hIcon = (HICON)(DWORD_PTR)GetClassLongPtr(iWin, GCLP_HICONSM); if (NULL == hIcon) hIcon = LoadIcon(NULL, IDI_APPLICATION); return hIcon; }
void NMainWindow::updateFramelessShadow() { DWORD version = GetVersion(); DWORD major = (DWORD) (LOBYTE(LOWORD(version))); // major = 6 for vista/7/2008 if (_DwmIsCompositionEnabled() && m_framelessShadow && major == 6) SetClassLongPtr(winId(), GCL_STYLE, GetClassLongPtr(winId(), GCL_STYLE) | CS_DROPSHADOW); else SetClassLongPtr(winId(), GCL_STYLE, GetClassLongPtr(winId(), GCL_STYLE) & ~CS_DROPSHADOW); hide(); show(); }
/////////////////////////////////////////////////////////////////////// /// Function: WindowClassProc /// /// Author: $author$ /// Date: 4/6/2012 /////////////////////////////////////////////////////////////////////// static LRESULT CALLBACK WindowClassProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { LRESULT lResult = 0; XosWinWindow* target = 0; WNDPROC windowSubclassProc = 0; DWORD wndExtra; DWORD wndIndex; DWORD wndClassExtra; DWORD wndClassIndex; if (sizeof(XosWinWindow*) <= (wndExtra = GetClassLong(hWnd, GCL_CBWNDEXTRA))) if (0 <= (wndIndex = wndExtra-sizeof(XosWinWindow*))) if ((target = (XosWinWindow*)(GetWindowLongPtr(hWnd, wndIndex)))) { lResult = target->OnWindowMessage(hWnd, msg, wParam, lParam); return lResult; } else if ((WM_NCCREATE == msg)) { CREATESTRUCT* cs; if ((cs = (CREATESTRUCT*)(lParam))) if ((target = (XosWinWindow*)(cs->lpCreateParams))) if (sizeof(windowSubclassProc) <= (wndClassExtra = GetClassLong(hWnd, GCL_CBCLSEXTRA))) if (0 <= (wndClassIndex = wndClassExtra-sizeof(windowSubclassProc))) if ((windowSubclassProc = (WNDPROC)(GetClassLongPtr(hWnd, wndClassIndex)))) { SetWindowLongPtr(hWnd, wndIndex, (LONG_PTR)(target)); if (!(target->Attached())) target->Attach(hWnd); lResult = target->OnWindowMessage(hWnd, msg, wParam, lParam); return lResult; } } if (sizeof(windowSubclassProc) <= (wndClassExtra = GetClassLong(hWnd, GCL_CBCLSEXTRA))) if (0 <= (wndClassIndex = wndClassExtra-sizeof(windowSubclassProc))) windowSubclassProc = (WNDPROC)(GetClassLongPtr(hWnd, wndClassIndex)); if (windowSubclassProc) lResult = CallWindowProc (windowSubclassProc, hWnd, msg, wParam, lParam); else lResult = DefWindowProc(hWnd, msg, wParam, lParam); return lResult; }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: init_transfer -- -- DATE: Febuary 6 2014 -- REVISIONS: none -- -- DESIGNER: Ramzi Chennafi -- PROGRAMMER: Ramzi Chennafi -- -- INTERFACE: void init_transfer(HWND hwnd), takes the parent window HWND. -- -- RETURNS: void -- -- NOTES: -- Intializes a UDP or TCP transfer based on the current settings. Will generate dummy packets if the program is in -- dummy packet transfer mode, otherwise reads a file and generates packets for the file. Passes the created packets -- to their respective UDP/TCP functions. ----------------------------------------------------------------------------------------------------------------------*/ void init_transfer(HWND hwnd){ SETTINGS * st = (SETTINGS*)GetClassLongPtr(hwnd, 0); int status; char msg[MAX_SIZE]; HANDLE hf; DWORD numBytesRead = 0; int totalBytesRead = 0; DWORD packetsizes[] = {1024, 4096, 20000, 60000}; const int packet_size = packetsizes[st->packet_size]; if (st->mode == FILEMODE){ grab_file(hwnd, &hf); } activity("Sending data...\n", EB_STATUSBOX); WSABUF * wsaBuffers = (LPWSABUF)malloc(sizeof(WSABUF)* MAX_PACKETS); char * buff = (char*)malloc(sizeof(char)* packet_size); int i = 0, buffer_count = 0; while (1){ if (st->mode == FILEMODE){ status = ReadFile(hf, buff, packet_size, &numBytesRead, NULL); if (numBytesRead == 0){ CloseHandle(hf); break; } wsaBuffers[i].buf = buff; wsaBuffers[i++].len = numBytesRead; totalBytesRead += numBytesRead; buffer_count++; } else{ buffer_count = atoi(st->times_to_send); for (int g = 0; g < packet_size; g++){ buff[g] = 'p'; } buff[packet_size - 1] = '\0'; for (int p = 0; p < buffer_count; p++){ wsaBuffers[p].buf = buff; wsaBuffers[p].len = packet_size; } totalBytesRead = packet_size * buffer_count; break; } } sprintf_s(msg, "Sending %d bytes in %d packets.\n", totalBytesRead, buffer_count); activity(msg, EB_STATUSBOX); if(st->protocol == UDP) udp_deliver_packets(hwnd, totalBytesRead, packet_size, buffer_count, wsaBuffers); else tcp_deliver_packets(hwnd, wsaBuffers, st->client_socket, totalBytesRead, packet_size, buffer_count, st->mode); free(wsaBuffers); }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: client_connect -- -- DATE: Febuary 6 2014 -- REVISIONS: none -- -- DESIGNER: Ramzi Chennafi -- PROGRAMMER: Ramzi Chennafi -- -- INTERFACE: void client_connect(HWND hwnd), takes the parent window HWND as an argument. -- -- RETURNS: void -- -- NOTES: -- When the client is in TCP mode, will connect the client to the TCP server. Returns messages on failure. After -- performing a connect the client is ready to transfer files. ----------------------------------------------------------------------------------------------------------------------*/ void client_connect(HWND hwnd){ SOCKADDR_IN InternetAddr; hostent *hp; int iRc; SETTINGS * st = (SETTINGS*)GetClassLongPtr(hwnd, 0); memset((char *)&InternetAddr, 0, sizeof(SOCKADDR_IN)); InternetAddr.sin_family = AF_INET; InternetAddr.sin_port = htons(atoi(st->client_port)); if ((hp = gethostbyname(st->client_send_ip)) == NULL) { activity("Could not find the specified server address.\n", EB_STATUSBOX); return; } memcpy((char *)&InternetAddr.sin_addr, hp->h_addr, hp->h_length); iRc = connect(st->client_socket, (PSOCKADDR)&InternetAddr, sizeof(InternetAddr)); if (iRc != 0){ activity("Failed to connect to server.\n", EB_STATUSBOX); return; } setsockopt(st->client_socket, SOL_SOCKET, SO_REUSEADDR, 0, 0); SetClassLongPtr(hwnd, 0, (LONG)st); activity("Connected to server.\n", EB_STATUSBOX); return; }
BOOL CXTPSkinObjectToolBar::OnEraseBkgnd(CDC* pDC) { if (GetStyle() & (TBSTYLE_TRANSPARENT | TBSTYLE_CUSTOMERASE)) { return CXTPSkinObjectFrame::OnEraseBkgnd(pDC); } HBRUSH hbr = (HBRUSH)(DWORD_PTR)GetClassLongPtr(m_hWnd, GCLP_HBRBACKGROUND); BOOL bChanged = FALSE; if (hbr > 0 && (ULONG_PTR)hbr < (ULONG_PTR)XTP_SKINMETRICS_COLORTABLESIZE) { HBRUSH hbrTheme = GetMetrics()->m_brTheme[(ULONG_PTR)hbr - 1]; SetClassLongPtr(m_hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)hbrTheme); bChanged = TRUE; } BOOL bResult = (BOOL)::DefWindowProc(m_hWnd, WM_ERASEBKGND, (WPARAM)pDC->GetSafeHdc(), 0); if (bChanged) { SetClassLongPtr(m_hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)hbr); } return bResult; }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: init_udp_recieve -- -- DATE: Febuary 6 2014 -- REVISIONS: none -- -- DESIGNER: Ramzi Chennafi -- PROGRAMMER: Ramzi Chennafi -- -- INTERFACE: int init_udp_receive(HWND hwnd) -- -- RETURNS: int, returns values that are dealt with by read_udp. Positive values deem a transfer as over. -- -- NOTES: -- Takes a HWND to the parent window. -- -- Sets up the system to accept a UDP data transfer, reads the packet, acknowledges it and adds it to the main buffer. Once the transfer -- has been completed a message is printed or the data is saved, based on the specified mode. ----------------------------------------------------------------------------------------------------------------------*/ int init_udp_receive(HWND hwnd){ DWORD Flags = 0; int status; char msg[MAX_SIZE]; SETTINGS * st = (SETTINGS*)GetClassLongPtr(hwnd, 0); char ack[6] = ";ACK;"; char * tempBuffer = (char*)malloc(sizeof(char)* SocketInfo->packet_size); SocketInfo->DataBuf.len = SocketInfo->packet_size; SocketInfo->DataBuf.buf = tempBuffer; if ((status = WSARecvFrom(st->server_socket, &SocketInfo->DataBuf, 1, &SocketInfo->BytesRECV, &Flags, NULL, NULL, NULL, NULL)) == SOCKET_ERROR){ sprintf_s(msg, "Error %d in TCP WSARecv(data) with return of %d\n", WSAGetLastError(), status); activity(msg, EB_STATUSBOX); return 0; } acknowledge(hwnd); if (SocketInfo->mode == 0){ SocketInfo->DataBuf.buf[SocketInfo->BytesRECV - 1] = '\0'; strcat_s(buffer + SocketInfo->totalRecv, SocketInfo->BytesRECV, SocketInfo->DataBuf.buf); } SocketInfo->packets -= 1; SocketInfo->totalRecv += SocketInfo->BytesRECV; if (SocketInfo->totalRecv == SocketInfo->total_size || SocketInfo->packets == 0){ endTime = GetTickCount(); seconds = endTime - startTime; return transfer_completion(hwnd, SocketInfo->mode); } return -2; // packets remaining }
static void LoadCoreModule(void) { INITCOMMONCONTROLSEX icce = {0}; icce.dwSize = sizeof(icce); icce.dwICC = ICC_WIN95_CLASSES | ICC_USEREX_CLASSES; InitCommonControlsEx(&icce); hAPCWindow = CreateWindowEx(0, _T("ComboLBox"), NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); SetClassLongPtr(hAPCWindow, GCL_STYLE, GetClassLongPtr(hAPCWindow, GCL_STYLE) | CS_DROPSHADOW); DestroyWindow(hAPCWindow); hAPCWindow = NULL; hAPCWindow = CreateWindowEx(0, _T("STATIC"), NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); SetWindowLongPtr(hAPCWindow, GWLP_WNDPROC, (LONG_PTR)APCWndProc); SetTimer(hAPCWindow, 1, 1000, NULL); hStackMutex = CreateMutex(NULL, FALSE, NULL); hThreadQueueEmpty = CreateEvent(NULL, TRUE, TRUE, NULL); #ifdef _WIN64 HMODULE mirInst = GetModuleHandleA("miranda64.exe"); #else HMODULE mirInst = GetModuleHandleA("miranda32.exe"); #endif RecalculateTime = (void (*)()) GetProcAddress(mirInst, "RecalculateTime"); InitWinver(); InitPathUtils(); InitLogs(); InitialiseModularEngine(); InitProtocols(); InitMetaContacts(); }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: Init_Settings -- -- DATE: Febuary 3, 2014 -- REVISIONS: none -- -- DESIGNER: Ramzi Chennafi -- PROGRAMMER: Ramzi Chennafi -- -- INTERFACE: void Init_Settings(HWND hwnd) -- RETURNS: void -- -- NOTES: -- Draws the default connection settings to the Settings dialog box. Takes the parent HWND as an argument in order -- to retrieve the current settings. ----------------------------------------------------------------------------------------------------------------------*/ void Init_Settings(HWND hwnd){ HWND hDlgPTCL = GetDlgItem(hwnd, IDC_PROTSLT); HWND hDlgPORT = GetDlgItem(hwnd, IDC_PORT); HWND hDlgIP = GetDlgItem(hwnd, IDC_IP); HWND hDlgSAVE = GetDlgItem(hwnd, IDC_SDISPLAY); HWND hDlgSPORT = GetDlgItem(hwnd, IDC_SPORT); HWND hDlgSPRTCL = GetDlgItem(hwnd, IDC_SPRTCL); HWND hDlgPCKT = GetDlgItem(hwnd, IDC_PACKETSIZE); HWND hDlgTTS = GetDlgItem(hwnd, IDC_TTS); SETTINGS * st = (SETTINGS*) GetClassLongPtr(GetParent(hwnd), 0); char * packetsizes[] = { "1024", "4096", "20000", "60000"}; for (int i = 0; i < 4; i++){ ComboBox_AddString(hDlgPCKT, packetsizes[i]); } ComboBox_SetCurSel(hDlgPCKT, st->packet_size); ComboBox_AddString(hDlgSPRTCL, "TCP"); ComboBox_AddString(hDlgSPRTCL, "UDP"); ComboBox_SetCurSel(hDlgSPRTCL, st->protocol); Edit_SetText(hDlgTTS, st->times_to_send); Edit_SetText(hDlgSPORT, st->server_port); Edit_SetText(hDlgPORT, st->client_port); Edit_SetText(hDlgIP, st->client_send_ip); }
explicit window(HWND hwnd) : _hwnd(hwnd) , _hook(true) { _org_wproc = (WNDPROC)GetClassLongPtr(hwnd, GCLP_WNDPROC); SetClassLongPtr(hwnd, GCLP_WNDPROC, (LONG_PTR)hook_winproc); }
void init3(HDC hDC, HWND memhwnd) { HBRUSH hbr; hdc = hDC; if(hdc) { nxpix = hdc->hwnd->clirect.right - hdc->hwnd->clirect.left; nypix = hdc->hwnd->clirect.bottom - hdc->hwnd->clirect.top; xscale = (vec1)(nxpix-1) / nxpix * nxpix/2; yscale = (vec1)(nypix-1) / nypix * nypix/2; if(memhwnd) { hdcMem = CreateCompatibleDC(NULL); if(hdcMem) { hbmp = CreateCompatibleBitmap(hdcMem, nxpix, nypix); hbmpOrg = SelectObject(hdcMem, hbmp); hdc = hdcMem; } hbr = (HBRUSH)(ULONG_PTR)GetClassLongPtr(memhwnd, GCL_HBRBACKGROUND); FillRect(hdc, NULL, hbr); } /* create pen for setcolor3() color override*/ SelectObject(hdc, CreatePen(PS_SOLID, 1, BLACK)); } }
StripperWindow::StripperWindow(QTreeWidget *parent, HWND hwnd): QTreeWidgetItem(parent, QTreeWidgetItem::Type) { //stubbed out. handle = hwnd; HICON icon_handle = (HICON)GetClassLongPtr(handle, GCLP_HICON); //pre-empt the "failed to GetIconInfo() error" so it speeds through quickly. ICONINFO dummy; if(!GetIconInfo(icon_handle, &dummy)) { icon = QPixmap(); } else { icon = QPixmap::fromWinHICON(icon_handle); } LPWSTR lpwstr_buf = (WCHAR*)calloc(sizeof(WCHAR), 255); GetWindowText(hwnd, lpwstr_buf, 255); title = QString::fromWCharArray(lpwstr_buf, 255); free(lpwstr_buf); borderless_p = false; //this might seem like duplication... setData(0, Qt::DecorationRole, QVariant(icon)); setData(1, Qt::DisplayRole, QVariant(title)); setFont(1, QFont(QString("Verdana"), 0, QFont::Bold, false)); setData(2, Qt::CheckStateRole, QVariant(StrippedP())); }
/** @brief Window procedure for Shell_TrayWnd * * For WM_COPYDATA this executes handler if installed, otherwise returns FALSE. * For anything else we just call DefWindowProc. */ LRESULT CALLBACK ShellServiceWindow::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { ShellServiceWindow *owner = reinterpret_cast<ShellServiceWindow *>(GetClassLongPtr(hWnd, 0)); ; if (msg == m_forwarderModuleMsg) { m_forwarderModule = reinterpret_cast<HMODULE>(lParam); } switch (msg) { case WM_COPYDATA: { COPYDATASTRUCT *copyData = reinterpret_cast<COPYDATASTRUCT *>(lParam); if (owner->handlers[copyData->dwData]) return owner->handlers[copyData->dwData]->ProcessMessage(copyData->cbData, copyData->lpData); else { TRACE("Unhandled COPYDATA msg %d", copyData->dwData); return FALSE; } } default: return DefWindowProc(hWnd, msg, wParam, lParam); } }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: set_settings -- -- DATE: Febuary 6 2014 -- REVISIONS: none -- -- DESIGNER: Ramzi Chennafi -- PROGRAMMER: Ramzi Chennafi -- -- INTERFACE: void set_settings(HWND hwnd), takes the parent window HWND as an argument. -- -- RETURNS: void -- -- NOTES: -- Whenever the user hits "OK" on the settings dialog box, this function is called. The function will set the current -- value of the SETTINGS data in the Class Long Ptr to whatever is currently present in the settings dialog box. ----------------------------------------------------------------------------------------------------------------------*/ void set_settings(HWND hwnd){ char ** tempBuffers = (char**)malloc(sizeof(char*)* 4); for (int i = 0; i < 4; i++){ tempBuffers[i] = (char*) malloc(sizeof(char)* MAX_SIZE); } HWND hDlgPORT = GetDlgItem(hwnd, IDC_PORT); HWND hDlgIP = GetDlgItem(hwnd, IDC_IP); HWND hDlgSAVE = GetDlgItem(hwnd, IDC_SDISPLAY); HWND hDlgSPORT = GetDlgItem(hwnd, IDC_SPORT); HWND hDlgSPRTCL = GetDlgItem(hwnd, IDC_SPRTCL); HWND hDlgPCKT = GetDlgItem(hwnd, IDC_PACKETSIZE); HWND hDlgTTS = GetDlgItem(hwnd, IDC_TTS); SETTINGS * st = (SETTINGS*)GetClassLongPtr(GetParent(hwnd), 0); Edit_GetText(hDlgPORT, tempBuffers[0], MAX_SIZE); st->client_port = tempBuffers[0]; Edit_GetText(hDlgSPORT, tempBuffers[1], MAX_SIZE); st->server_port = tempBuffers[1]; Edit_GetText(hDlgIP, tempBuffers[2], MAX_SIZE); st->client_send_ip = tempBuffers[2]; Edit_GetText(hDlgTTS, tempBuffers[3], MAX_SIZE); st->times_to_send = tempBuffers[3]; st->packet_size = ComboBox_GetCurSel(hDlgPCKT); st->protocol = ComboBox_GetCurSel(hDlgSPRTCL); SetClassLongPtr(GetParent(hwnd), 0, (LONG)st); }
static HICON get_icon(HWND hwnd, int large) { HICON icon; if (!SendMessageTimeout(hwnd, WM_GETICON, large ? ICON_BIG : ICON_SMALL, 0, SMTO_ABORTIFHUNG, 1000, (PDWORD_PTR) & icon)) return NULL; if (icon) return icon; /* * Modern versions of Windows uses the voodoo value of 2 instead of 0 * for the small icons. */ if (!large) { if (!SendMessageTimeout(hwnd, WM_GETICON, 2, 0, SMTO_ABORTIFHUNG, 1000, (PDWORD_PTR) & icon)) return NULL; } if (icon) return icon; icon = (HICON) GetClassLongPtr(hwnd, large ? GCLP_HICON : GCLP_HICONSM); if (icon) return icon; return NULL; }
HICON getWindowIcon(HWND hwnd) { ULONG_PTR icon; #ifdef ICON_SMALL2 icon = SendMessage(hwnd, WM_GETICON, ICON_SMALL2, 0); if (icon != (ULONG_PTR) NULL) return (HICON) icon; #endif icon = SendMessage(hwnd, WM_GETICON, ICON_SMALL, 0); if (icon != (ULONG_PTR) NULL) return (HICON) icon; icon = SendMessage(hwnd, WM_GETICON, ICON_BIG, 0); if (icon != (ULONG_PTR) NULL) return (HICON) icon; icon = GetClassLongPtr(hwnd, GCLP_HICON); if (icon != (ULONG_PTR) NULL) return (HICON) icon; icon = GetClassLongPtr(hwnd, GCLP_HICONSM); if (icon !=(ULONG_PTR) NULL) return (HICON) icon; return NULL; }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: udp_deliver_packets -- -- DATE: Febuary 6 2014 -- REVISIONS: Countless. Most recent, turning it into somewhat reliable UDP. -- -- DESIGNER: Ramzi Chennafi -- PROGRAMMER: Ramzi Chennafi -- -- INTERFACE: void udp_deliver_packets(HWND hwnd, int totalBytesRead, int packet_size, int buffer_count, WSABUF * buffers) -- -- RETURNS: void -- -- NOTES: -- Takes the parent window HWND, the total bytes to be transferred (totalBytesRead), the current packet size, the amount of packets -- an an array of WSABUFs each containing a packet of data. -- -- Delivers the packets over UDP to the specified IP and port, and has some reliability for dropped packets by -- incorporating an acknowledgement system as well as a header packet containing the info passed to the function. -- If an error occurs in the recvfrom portion of the acknowledgement, consider the transfer dead and restart the program. -- -- * WILL loop endlessly if the user decides to terminate the server during a transfer. Will continously wait for ACKs. ----------------------------------------------------------------------------------------------------------------------*/ void udp_deliver_packets(HWND hwnd, int totalBytesRead, int packet_size, int buffer_count, WSABUF * buffers){ SETTINGS * st = (SETTINGS*)GetClassLongPtr(hwnd, 0); int packets_lost = 0; int status; char msg[MAX_SIZE]; DWORD numBytesSent = 0; struct sockaddr_in sin; char flags[HEADER_SIZE]; memset(flags, '\0', HEADER_SIZE); sprintf_s(flags, ";%d,%d,%d,%d;", totalBytesRead, packet_size, buffer_count, st->mode); LPWSABUF wsaHeaderBuf = (LPWSABUF)malloc(sizeof(WSABUF)); wsaHeaderBuf->len = HEADER_SIZE; wsaHeaderBuf->buf = flags; memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(atoi(st->client_port)); if ((sin.sin_addr.s_addr = inet_addr(st->client_send_ip)) == INADDR_NONE) { activity("Failed to find address\n", EB_STATUSBOX); return; } while (1){ // transferring the header packet if ((status = WSASendTo(st->client_socket, wsaHeaderBuf, 1, &numBytesSent, 0, (struct sockaddr *)&sin, sizeof(sin), NULL, NULL)) < 0){ sprintf_s(msg, "Error %d in TCP WSASend(header) with return of %d\n", WSAGetLastError(), status); activity(msg, EB_STATUSBOX); } if (receive_acknowledge(hwnd) == 1) { break; } packets_lost++; } startTime = GetTickCount(); for (int p = 0; p < buffer_count; p++){ while (1){ // transferring the actual data if ((status = WSASendTo(st->client_socket, &buffers[p], 1, &numBytesSent, 0, (struct sockaddr *)&sin, sizeof(sin), NULL, NULL)) < 0){ sprintf_s(msg, "Error %d in sendto(buffer) with return of %d\n", WSAGetLastError(), status); activity(msg, EB_STATUSBOX); return; } if (receive_acknowledge(hwnd) == 1){ break; } packets_lost++; } } endTime = GetTickCount(); seconds = endTime - startTime; sprintf_s(msg, "Data transmission completed in %d milliseconds.\n", seconds); activity(msg, EB_STATUSBOX); }
//****************************************************************** void CBCGPKeyboardPage::OnSelchangeViewType() { m_hAccelTable = NULL; m_pSelTemplate = NULL; if (m_lpAccel != NULL) { delete [] m_lpAccel; m_lpAccel = NULL; } int iIndex = m_wndViewTypeList.GetCurSel (); if (iIndex == CB_ERR) { m_wndViewIcon.SetIcon (NULL); return; } HICON hicon = NULL; CBCGPMultiDocTemplate* pTemplate = (CBCGPMultiDocTemplate*) m_wndViewTypeList.GetItemData (iIndex); if (pTemplate != NULL) { ASSERT_VALID (pTemplate); hicon = AfxGetApp ()->LoadIcon (pTemplate->GetResId ()); m_hAccelTable = pTemplate->m_hAccelTable; } else { CFrameWnd* pWndMain = DYNAMIC_DOWNCAST (CFrameWnd, m_pParentFrame); if (pWndMain != NULL) { hicon = (HICON)(LONG_PTR) GetClassLongPtr (*pWndMain, GCLP_HICON); m_hAccelTable = pWndMain->m_hAccelTable; } } if (hicon == NULL) { hicon = ::LoadIcon(NULL, IDI_APPLICATION); } m_wndViewIcon.SetIcon (hicon); ASSERT (m_hAccelTable != NULL); m_nAccelSize = ::CopyAcceleratorTable (m_hAccelTable, NULL, 0); m_lpAccel = new ACCEL [m_nAccelSize]; ASSERT (m_lpAccel != NULL); ::CopyAcceleratorTable (m_hAccelTable, m_lpAccel, m_nAccelSize); m_pSelTemplate = pTemplate; OnSelchangeCommandsList (); }
HICON UserGetWindowIcon(HWND hwnd) { HICON hIcon = 0; SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL2, 0, SMTO_ABORTIFHUNG, 1000, (PDWORD_PTR)&hIcon); if (!hIcon) hIcon = UserGetProp(hwnd, gpsi->atomIconSmProp); if (!hIcon) hIcon = UserGetProp(hwnd, gpsi->atomIconProp); if (!hIcon) hIcon = (HICON)GetClassLongPtr(hwnd, GCL_HICONSM); if (!hIcon) hIcon = (HICON)GetClassLongPtr(hwnd, GCL_HICON); if (!hIcon && (GetWindowLongW( hwnd, GWL_STYLE ) & DS_MODALFRAME)) { if (!hIcon) hIcon = gpsi->hIconSmWindows; // Both are IDI_WINLOGO Small if (!hIcon) hIcon = gpsi->hIconWindows; // Reg size. } return hIcon; }
void CSizingControlBar::OnNcPaint() { // get window DC that is clipped to the non-client area CWindowDC dc(this); // the HDC will be released by the destructor CRect rcClient, rcBar; GetClientRect(rcClient); //mpc-hc custom code start //ClientToScreen(rcClient); //mpc-hc custom code end GetWindowRect(rcBar); //mpc-hc custom code start // Convert to client coordinates to account for possible RTL layout ScreenToClient(rcBar); //mpc-hc custom code end rcClient.OffsetRect(-rcBar.TopLeft()); rcBar.OffsetRect(-rcBar.TopLeft()); CDC mdc; mdc.CreateCompatibleDC(&dc); CBitmap bm; bm.CreateCompatibleBitmap(&dc, rcBar.Width(), rcBar.Height()); CBitmap* pOldBm = mdc.SelectObject(&bm); // draw borders in non-client area CRect rcDraw = rcBar; DrawBorders(&mdc, rcDraw); // erase the NC background //mpc-hc custom code start mdc.FillRect(rcDraw, CBrush::FromHandle( (HBRUSH) GetClassLongPtr(m_hWnd, GCLP_HBRBACKGROUND))); //mpc-hc custom code end if (m_dwSCBStyle & SCBS_SHOWEDGES) { CRect rcEdge; // paint the sizing edges for (int i = 0; i < 4; i++) if (GetEdgeRect(rcBar, GetEdgeHTCode(i), rcEdge)) mdc.Draw3dRect(rcEdge, ::GetSysColor(COLOR_BTNHIGHLIGHT), ::GetSysColor(COLOR_BTNSHADOW)); } NcPaintGripper(&mdc, rcClient); // client area is not our bussiness :) dc.IntersectClipRect(rcBar); dc.ExcludeClipRect(rcClient); dc.BitBlt(0, 0, rcBar.Width(), rcBar.Height(), &mdc, 0, 0, SRCCOPY); mdc.SelectObject(pOldBm); bm.DeleteObject(); mdc.DeleteDC(); }
//---- -------------------------------------------------------------------------------------------------------- // Function: EAEUpdateGUI // Requires: HWND hwnd - window handle // bool shadow - window shadow indicator // std::wstring zposition - z-order setting for window // Returns: bool // Purpose: Set the window shadow and z-order //---- -------------------------------------------------------------------------------------------------------- HWND EAEUpdateGUI(HWND hwnd, bool shadow, std::wstring zposition) { if (shadow) { SetClassLongPtr(hwnd, GCL_STYLE, GetClassLongPtr(hwnd, GCL_STYLE) | CS_DROPSHADOW); } else { SetClassLongPtr(hwnd, GCL_STYLE, GetClassLongPtr(hwnd, GCL_STYLE) & ~CS_DROPSHADOW); } // Set window z-order if (ELToLower(zposition) == ELToLower(TEXT("Top"))) { return HWND_TOPMOST; } return HWND_NOTOPMOST; }
void get_window_icon(HWND hwnd, HICON *picon) { HICON hIco = NULL; SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG|SMTO_NORMAL, 1000, (DWORD_PTR*)&hIco); if (NULL==hIco) { SendMessageTimeout(hwnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG|SMTO_NORMAL, 1000, (DWORD_PTR*)&hIco); if (NULL==hIco) { hIco = (HICON)GetClassLongPtr(hwnd, GCLP_HICONSM); if (NULL==hIco) { hIco = (HICON)GetClassLongPtr(hwnd, GCLP_HICON); if (NULL==hIco) { return; }}}} if (*picon) DestroyIcon(*picon); *picon = CopyIcon(hIco); }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: receive_acknowledge -- -- DATE: Febuary 6 2014 -- REVISIONS: none -- -- DESIGNER: Ramzi Chennafi -- PROGRAMMER: Ramzi Chennafi -- -- INTERFACE: int receive_acknowledge(HWND hwnd), where hwnd is the HWND of the main parent window. -- -- RETURNS: int, returns 1 if an acknowledgement is received. -- -- NOTES: -- Checks if the packet received after sending a packet is an "ACK" packet. An ACK packet contains the text ";ACK;". -- *Yes this may be prone to problems, for our purposes it makes it easier. Can easily be changed. -- *Only used on the UDP side, provides reliability for the client. TCP already does this for us. ----------------------------------------------------------------------------------------------------------------------*/ int receive_acknowledge(HWND hwnd){ SETTINGS * st = (SETTINGS*)GetClassLongPtr(hwnd, 0); char ack[6]; int status, ackrecv; if ((status = recvfrom(st->server_socket, ack, ACK_SIZE, 0, 0, 0)) == -1){ activity("Error in acknowledgement, run before it blows up!\n", EB_STATUSBOX); } ackrecv = (strcmp(ack, ";ACK;") == 0) ? 1 : 0; return ackrecv; }
static void CALLBACK GetIconCallback(HWND window, UINT message, ULONG_PTR data, LRESULT result) { assert(message == WM_GETICON); switch (data) { case ICON_BIG: if (result != NULL) { sWindowData[window].largeIcon = (HICON)result; } else { HICON icon = (HICON)GetClassLongPtr(window, GCLP_HICON); if (!icon) { icon = sDefaultIcon; } sWindowData[window].largeIcon = icon; } SendMessageCallback(window, WM_GETICON, ICON_SMALL, NULL, GetIconCallback, ICON_SMALL); break; case ICON_SMALL: if (result != NULL) { sWindowData[window].smallIcon = (HICON)result; SendMessage(gWindow, NCORE_WINDOW_ICON_CHANGED, (WPARAM)window, NULL); } else { SendMessageCallback(window, WM_GETICON, ICON_SMALL2, NULL, GetIconCallback, ICON_SMALL2); } break; case ICON_SMALL2: if (result != NULL) { sWindowData[window].smallIcon = (HICON)result; } else { HICON icon = (HICON)GetClassLongPtr(window, GCLP_HICONSM); if (!icon) { icon = sDefaultIcon; } sWindowData[window].smallIcon = icon; } SendMessage(gWindow, NCORE_WINDOW_ICON_CHANGED, (WPARAM)window, NULL); break; } }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: init_client -- -- DATE: Febuary 6 2014 -- REVISIONS: none -- -- DESIGNER: Ramzi Chennafi -- PROGRAMMER: Ramzi Chennafi -- -- INTERFACE: void init_client(HWND hwnd) , takes the parent HWND as an argument. -- -- RETURNS: void -- -- NOTES: -- Intializes the client, the type of intialization depends on the chosen protocol in the settings. Binds whenever -- the connection is TCP. ----------------------------------------------------------------------------------------------------------------------*/ void init_client(HWND hwnd){ DWORD Ret; SOCKADDR_IN InternetAddr; WSADATA wsaData; SETTINGS * st = (SETTINGS*)GetClassLongPtr(hwnd, 0); if ((Ret = WSAStartup(0x0202, &wsaData)) != 0){ activity("WSAStartup failed on client.\n", EB_STATUSBOX); return; } switch(st->protocol){ case TCP: st->client_socket = socket(PF_INET, SOCK_STREAM, 0); break; case UDP: st->server_socket = socket(AF_INET, SOCK_DGRAM, 0); if ((st->client_socket = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET){ activity("Failed to create transfer socket.\n", EB_STATUSBOX); } InternetAddr.sin_family = AF_INET; InternetAddr.sin_addr.s_addr = htonl(INADDR_ANY); InternetAddr.sin_port = htons(atoi(st->server_port)); if (bind(st->server_socket, (PSOCKADDR)&InternetAddr, sizeof(InternetAddr)) == SOCKET_ERROR){ activity("bind() failed on receiving socket.\n", EB_STATUSBOX); } break; } SetClassLongPtr(hwnd, 0, (LONG)st); if(st->client_socket == INVALID_SOCKET){ activity("Failed to create receiving socket.\n", EB_STATUSBOX); } if (st->protocol == UDP){ activity("UDP Client intialized, ready to transfer.\n", EB_STATUSBOX); return; } InternetAddr.sin_family = AF_INET; InternetAddr.sin_addr.s_addr = htonl(INADDR_ANY); InternetAddr.sin_port = htons(PORT); if (bind(st->client_socket, (PSOCKADDR)&InternetAddr, sizeof(InternetAddr)) == SOCKET_ERROR){ activity("bind() failed on client.\n", EB_STATUSBOX); } activity("TCP Client intialized, ready to connect.\n", EB_STATUSBOX); }