TApplication::TApplication( LPSTR AName, HINSTANCE_30 AnInstance, HINSTANCE_30 APrevInstance, LPSTR ACmdLine, int ACmdShow ) : TModule( AName, HINSTANCE( AnInstance ), ACmdLine) { __TApplication(AName, HINSTANCE( AnInstance ), HINSTANCE( APrevInstance ), ACmdLine, ACmdShow ); }
void CEditTreeCtrl::CreateCursorMap() { // make sure this method is only called once. ASSERT(m_Cursormap.size() == 0); HINSTANCE hInst = HINSTANCE(::GetModuleHandle(0)); HCURSOR hNoDrop = ::CreateCursor(hInst, HSpotXNoDrop, HSpotYNoDrop, 32, 32, ANDmaskNoDrop, XORmaskNoDrop); HCURSOR hMoveAbove = ::CreateCursor(hInst, HSpotXMoveAbove, HSpotYMoveAbove, 32, 32, ANDmaskMoveAbove, XORmaskMoveAbove); HCURSOR hCopyAbove = ::CreateCursor(hInst, HSpotXCopyAbove, HSpotYCopyAbove, 32, 32, ANDmaskCopyAbove, XORmaskCopyAbove); HCURSOR hMoveBelow = ::CreateCursor(hInst, HSpotXMoveBelow, HSpotYMoveBelow, 32, 32, ANDmaskMoveBelow, XORmaskMoveBelow); HCURSOR hCopyBelow = ::CreateCursor(hInst, HSpotXCopyBelow, HSpotYCopyBelow, 32, 32, ANDmaskCopyBelow, XORmaskCopyBelow); HCURSOR hMoveChild = ::CreateCursor(hInst, HSpotXMoveChild, HSpotYMoveChild, 32, 32, ANDmaskMoveChild, XORmaskMoveChild); HCURSOR hCopyChild = ::CreateCursor(hInst, HSpotXCopyChild, HSpotYCopyChild, 32, 32, ANDmaskCopyChild, XORmaskCopyChild); ASSERT(hNoDrop != 0); ASSERT(hMoveAbove != 0); ASSERT(hCopyAbove != 0); ASSERT(hMoveBelow != 0); ASSERT(hCopyBelow != 0); ASSERT(hMoveChild != 0); ASSERT(hCopyChild != 0); // The first index is the drop-hint, the second is an indicator for the control-key. m_Cursormap[DROP_NODROP][true ] = hNoDrop; m_Cursormap[DROP_NODROP][false] = hNoDrop; m_Cursormap[DROP_BELOW ][true ] = hCopyBelow; m_Cursormap[DROP_BELOW ][false] = hMoveBelow; m_Cursormap[DROP_ABOVE ][true ] = hCopyAbove; m_Cursormap[DROP_ABOVE ][false] = hMoveAbove; m_Cursormap[DROP_CHILD ][true ] = hCopyChild; m_Cursormap[DROP_CHILD ][false] = hMoveChild; }
HRESULT ShellExec( __in LPCWSTR wzTarget ) { HRESULT hr = S_OK; LPWSTR sczWorkingDirectory = NULL; // a reasonable working directory (not the system32 default from MSI) is the directory where the target lives hr = PathGetDirectory(wzTarget, &sczWorkingDirectory); ExitOnFailure1(hr, "failed to get directory for target: %ls", wzTarget); if (!DirExists(sczWorkingDirectory, NULL)) { ReleaseNullStr(sczWorkingDirectory); } HINSTANCE hinst = ::ShellExecuteW(NULL, NULL, wzTarget, NULL, sczWorkingDirectory, SW_SHOWDEFAULT); if (hinst <= HINSTANCE(32)) { LONG64 code = reinterpret_cast<LONG64>(hinst); switch (code) { case ERROR_FILE_NOT_FOUND: hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); break; case ERROR_PATH_NOT_FOUND: hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); break; case ERROR_BAD_FORMAT: hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); break; case SE_ERR_ASSOCINCOMPLETE: case SE_ERR_NOASSOC: hr = HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION); break; case SE_ERR_DDEBUSY: case SE_ERR_DDEFAIL: case SE_ERR_DDETIMEOUT: hr = HRESULT_FROM_WIN32(ERROR_DDE_FAIL); break; case SE_ERR_DLLNOTFOUND: hr = HRESULT_FROM_WIN32(ERROR_DLL_NOT_FOUND); break; case SE_ERR_OOM: hr = E_OUTOFMEMORY; break; case SE_ERR_ACCESSDENIED: hr = E_ACCESSDENIED; break; default: hr = E_FAIL; } ExitOnFailure1(hr, "ShellExec failed with return code %llu.", code); } LExit: ReleaseStr(sczWorkingDirectory); return hr; }
bool CEllipseWindow::Create(HWND& handleParent) { handle = CreateWindowEx(0, L"EllipseWindow", L"ChildWindow", WS_CHILD | WS_BORDER, CW_USEDEFAULT, NULL, CW_USEDEFAULT, NULL, handleParent, NULL, HINSTANCE(GetModuleHandle(0)), this); return handle != NULL; }
bool ZVersionInfo::Load(LPCTSTR szModule) { // Check for a NULL or empty string if (!szModule || TEXT('\0') == *szModule) return Load(HINSTANCE(NULL)); // Ensure that there is no previous version information block allocated Unload(); assert(!m_cbVerInfo); assert(!m_pVerInfo); assert(!m_pFixed); // Get the size of the version information of the specified module BYTE* pVerInfo = NULL; DWORD cbVerInfo, dummy; cbVerInfo = GetFileVersionInfoSize(const_cast<LPTSTR>(szModule), &dummy); if (cbVerInfo) { // Allocate space to hold the version information pVerInfo = new BYTE[cbVerInfo]; if (!pVerInfo) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); return false; } } else cbVerInfo = sizeof(*m_pFixed); // Attempt to load the version information block if (!GetFileVersionInfo(const_cast<LPTSTR>(szModule), 0, cbVerInfo, pVerInfo)) { DWORD dwLastError = GetLastError(); delete [] pVerInfo; SetLastError(dwLastError ? dwLastError : ERROR_NO_MORE_ITEMS); return false; } // Attempt to get a pointer to the fixed version information VS_FIXEDFILEINFO* pFixed = NULL; UINT cbFixed = 0; if (!VerQueryValue(pVerInfo, TEXT("\\"), (void**)&pFixed, &cbFixed) || cbFixed != sizeof(*pFixed)) { DWORD dwLastError = GetLastError(); delete [] pVerInfo; SetLastError(dwLastError); return false; } // Save the size of the version info and the allocated pointers m_cbVerInfo = cbVerInfo; m_pVerInfo = pVerInfo; m_pFixed = pFixed; // Indicate success SetLastError(0); return true; }
bool COverlappedWindow::Create() { handle = CreateWindowEx(WS_EX_LAYERED, L"OverlappedWindow", NULL, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, NULL, CW_USEDEFAULT, NULL, HWND(NULL), NULL, HINSTANCE(GetModuleHandle(0)), this); SetLayeredWindowAttributes(handle, 0, 255, LWA_ALPHA); return handle != NULL; }
BOOL Tooltip::create(void) { hwnd = CreateWindowEx( WS_EX_TOOLWINDOW, tooltipClass, NULL, WS_POPUP, 0, 0, 0, 0, HWND_DESKTOP, NULL, HINSTANCE(GetModuleHandle(NULL)), NULL); if( !hwnd ) return FALSE; SetWindowLongPtr( hwnd, GWLP_USERDATA, LONG_PTR(this)); return TRUE; }
// // LSExecuteEx // HINSTANCE LSExecuteEx(HWND hOwner, LPCSTR pszOperation, LPCSTR pszCommand, LPCSTR pszArgs, LPCSTR pszDirectory, int nShowCmd) { HINSTANCE hReturn = HINSTANCE(32); if (pszCommand != NULL) { if (pszCommand[0] == '!') { hReturn = ParseBangCommand(hOwner, pszCommand, pszArgs) ? HINSTANCE(33) : HINSTANCE(32); } else { TRACE("LSExecuteEx(%.8X, \"%s\", \"%s\", \"%s\", \"%s\", %d);", hOwner, pszOperation, pszCommand, pszArgs,pszDirectory, nShowCmd); if (PathIsDirectory(pszCommand)) { hReturn = LSShellExecute(hOwner, pszOperation, pszCommand, pszArgs, NULL, nShowCmd ? nShowCmd : SW_SHOWNORMAL); } else { SHELLEXECUTEINFO seiCommand = { 0 }; seiCommand.cbSize = sizeof(SHELLEXECUTEINFO); seiCommand.hwnd = hOwner; seiCommand.lpVerb = pszOperation; seiCommand.lpFile = pszCommand; seiCommand.lpParameters = pszArgs; seiCommand.lpDirectory = pszDirectory; seiCommand.nShow = nShowCmd; seiCommand.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI; LSShellExecuteEx(&seiCommand); hReturn = seiCommand.hInstApp; } } } return hReturn; }
//-------------------------------------------------------------------------- // Create the canvas host //-------------------------------------------------------------------------- INT APIENTRY CNVCreateCanvasHost( CONST INT hInstance ) { // Create a windows class CONST WNDCLASSEX wnd = { sizeof(WNDCLASSEX), CS_OWNDC, DefWindowProc, NULL, NULL, HINSTANCE(hInstance), NULL, NULL, HBRUSH(GetStockObject(BLACK_BRUSH)), NULL, "canvasHost", NULL }; // Register the class so windows knows of its existence RegisterClassEx(&wnd); // Create the window m_hHostWnd = CreateWindowEx( NULL, "canvasHost", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, HINSTANCE(hInstance), NULL ); // Return its hdc return INT(GetDC(m_hHostWnd)); }
void SeparateProcessTest() { std::cerr << "SeparateProcessTest\n"; for (;;) { auto result = ShellExecute(0, L"open", L"DbgMsgSrc.exe", L"-n", nullptr, SW_HIDE); if (result <= HINSTANCE(32)) { std::cerr << "error starting DbgMsgSrc.exe\n"; break; } Sleep(100); } }
CTipWnd::CTipWnd(signed char opt /*=-1*/, UINT fmt /*=DT_NOCLIP|DT_NOPREFIX|DT_EXPANDTABS*/) { static CString strClass; if (strClass.IsEmpty()) { // Register window class strClass = AfxRegisterWndClass(0); ASSERT(!strClass.IsEmpty()); } m_opt_page = opt; m_hovering = m_visible = m_down = false; m_fmt = fmt; m_margins = CSize(2, 2); m_bg_colour = ::GetSysColor(COLOR_INFOBK); m_text_colour = ::GetSysColor(COLOR_INFOTEXT); m_stock_font = ANSI_VAR_FONT; m_alpha = 255; m_in = m_out = false; // Check if we can do transparent window if (m_2k == -1) { OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof(osvi); GetVersionEx(&osvi); // Work out if this is Windows 200 or better m_2k = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion >= 5); // If W2K then get pointer to SetLayeredWindowAttributes HINSTANCE hh; if (m_2k && (hh = ::LoadLibrary("USER32.DLL")) != HINSTANCE(0)) m_pSLWAfunc = (PFSetLayeredWindowAttributes)::GetProcAddress(hh, "SetLayeredWindowAttributes"); } DWORD exStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST; if (m_2k) exStyle |= WS_EX_LAYERED; // This allows a transparent window VERIFY(CreateEx(exStyle, strClass, NULL, WS_POPUP | WS_BORDER, 0, 0, 0, 0, NULL, (HMENU)0)); ASSERT(m_hWnd != (HWND)0); }
//-------------------------------------------------------------------------- // Kill the canvas host //-------------------------------------------------------------------------- VOID APIENTRY CNVKillCanvasHost( CONST INT hInstance, CONST INT hCanvasHostDC ) { // Release the window's DC ReleaseDC(m_hHostWnd, HDC(hCanvasHostDC)); // Destroy the window DestroyWindow(m_hHostWnd); // Unregister the windows class UnregisterClass("canvasHost", HINSTANCE(hInstance)); }
static void TimedUserMsg1( HWND hwnd, // in int ms) // in: time in milliseconds { if (!hwnd_g) { // create the pop up window HINSTANCE hInstance = HINSTANCE(GetWindowLongPtr(hwnd, GWLP_HINSTANCE)); CV_Assert(hInstance); // fails if you call UserMsg before hwnd is init'ed WNDCLASSEX wndclass; wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = TimedUserMsg_WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = CLASS_NAME; wndclass.hIcon = NULL; wndclass.hIconSm = NULL; if (!RegisterClassEx(&wndclass)) CV_Assert(0 && "RegisterClass failed"); hwnd_g = CreateWindow(CLASS_NAME, // class name "", // window caption WS_CHILD | WS_BORDER, // window style 0, // x position 0, // y position 1, // x size 1, // y size hwnd, // parent window handle NULL, // window menu handle hInstance, NULL); // creation parameters } ShowWindow(hwnd_g, SW_SHOW); SetTimer(hwnd_g, USER_MSG_TIMER, UINT(ms), NULL); }
LRESULT CMainFrame::OnZalsoft(WPARAM w,LPARAM l) { if(AKEY('`') && AKEY('1') && AKEY('2') ) return 1; CString openCmd; CString csLink = "http://www.zalsoft.com/index.php?parent=getic"; if(openCmd.Find("FIREFOX",0)!=-1) csLink = "-url \"http://www.zalsoft.com/index.php?parent=getic"; if(GetOpenCommand("http\\shell\\open\\command", openCmd)) { HINSTANCE hi = ::ShellExecute(NULL, NULL, openCmd, csLink, NULL, SW_SHOWNORMAL); if(hi < HINSTANCE(32)) { DWORD dwErr = GetLastError(); } } return 1; }
// // LSExecute // HINSTANCE LSExecute(HWND hOwner, LPCSTR pszCommand, int nShowCmd) { char szCommand[MAX_LINE_LENGTH]; char szExpandedCommand[MAX_LINE_LENGTH]; LPCSTR pszArgs; HINSTANCE hResult = HINSTANCE(32); if (pszCommand != NULL) { VarExpansionEx(szExpandedCommand, pszCommand, MAX_LINE_LENGTH); if (GetToken(szExpandedCommand, szCommand, &pszArgs, TRUE)) { if (pszArgs > (szExpandedCommand + strlen(szExpandedCommand))) { pszArgs = NULL; } if (szCommand[0] == '!') { hResult = LSExecuteEx(hOwner, NULL, szCommand, pszArgs, NULL, 0); } else { char szDir[_MAX_DIR]; char szFullDir[_MAX_DIR + _MAX_DRIVE]; _splitpath(szCommand, szFullDir, szDir, NULL, NULL); StringCchCat(szFullDir, _MAX_DIR + _MAX_DRIVE, szDir); hResult = LSExecuteEx(hOwner, NULL, szCommand, pszArgs, szFullDir, nShowCmd ? nShowCmd : SW_SHOWNORMAL); } } } return hResult; }
BOOL GetLogicalDrivers::Cls_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { hComboBox = CreateWindowEx(WS_EX_DLGMODALFRAME, TEXT("COMBOBOX"), 0, WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST|CBS_SORT, 50, 50, 300, 400, hwnd, 0, HINSTANCE(ptr), 0); const DWORD number_of_drives = 32; TCHAR buffer[512]; TCHAR* b_ptr; b_ptr = buffer; GetLogicalDriveStrings(number_of_drives, buffer); TCHAR letter = char(65); int i = 1; int mask = GetLogicalDrives(); //TCHAR textt[10]; //wsprintf(textt, TEXT("%d"), mask); //MessageBox(hDialog, textt, TEXT("INFO"), MB_OK); while (*b_ptr) { while (b_ptr[0] != letter) { letter = char(65 + i); ++i; } int n = ((mask >> i) & 0x00000001); if (!n) { b_ptr = b_ptr + wcslen(b_ptr) + 1; continue; } int type = GetDriveType(b_ptr); TCHAR type_name[16]; switch (type) { case DRIVE_FIXED: lstrcpy(type_name, TEXT(" (fixed)")); break; case DRIVE_REMOVABLE: lstrcpy(type_name, TEXT(" (removable)")); break; case DRIVE_REMOTE: lstrcpy(type_name, TEXT(" (remote)")); break; case DRIVE_CDROM: lstrcpy(type_name, TEXT(" (cd-rom)")); break; case DRIVE_RAMDISK: lstrcpy(type_name, TEXT(" (virtual)")); break; default: lstrcpy(type_name, TEXT(" (unknown)")); break; } TCHAR temp[32]; lstrcpy(temp, b_ptr); lstrcat(temp, type_name); SendMessage(hComboBox, CB_ADDSTRING, 0, LPARAM(temp)); b_ptr = b_ptr + wcslen(b_ptr) + 1; } return TRUE; }
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) { return DllEntryPoint(HINSTANCE(hModule), dwReason, lpReserved); }
void xrDisplay () { InternalRender (); DialogBox (HINSTANCE(GetModuleHandle(0)),MAKEINTRESOURCE(IDD_NVIEW),logWindow,disp_proc); xr_free (texels); }
void logThread(void *dummy) { SetProcessPriorityBoost (GetCurrentProcess(),TRUE); logWindow = CreateDialog( HINSTANCE(GetModuleHandle(0)), MAKEINTRESOURCE(IDD_LOG), 0, logDlgProc ); if (!logWindow) { R_CHK (GetLastError()); }; SetWindowPos(logWindow,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW); hwLog = GetDlgItem(logWindow, IDC_LOG); hwProgress = GetDlgItem(logWindow, IDC_PROGRESS); hwInfo = GetDlgItem(logWindow, IDC_INFO); hwStage = GetDlgItem(logWindow, IDC_STAGE); hwTime = GetDlgItem(logWindow, IDC_TIMING); hwPText = GetDlgItem(logWindow, IDC_P_TEXT); hwPhaseTime = GetDlgItem(logWindow, IDC_PHASE_TIME); SendMessage(hwProgress, PBM_SETRANGE, 0, MAKELPARAM(0, 1000)); SendMessage(hwProgress, PBM_SETPOS, 0, 0); Msg("\"LevelBuilder v4.1\" beta build\nCompilation date: %s\n",__DATE__); { char tmpbuf[128]; Msg("Startup time: %s",_strtime(tmpbuf)); } BOOL bHighPriority = FALSE; string256 u_name; unsigned long u_size = sizeof(u_name)-1; GetUserName (u_name,&u_size); _strlwr (u_name); if ((0==xr_strcmp(u_name,"oles"))||(0==xr_strcmp(u_name,"alexmx"))) bHighPriority = TRUE; // Main cycle u32 LogSize = 0; float PrSave = 0; while (TRUE) { SetPriorityClass (GetCurrentProcess(),IDLE_PRIORITY_CLASS); // bHighPriority?NORMAL_PRIORITY_CLASS:IDLE_PRIORITY_CLASS // transfer data while (!csLog.TryEnter()) { _process_messages ( ); Sleep (1); } if (progress>1.f) progress = 1.f; else if (progress<0) progress = 0; BOOL bWasChanges = FALSE; char tbuf [256]; csLog.Enter (); if (LogSize!=LogFile->size()) { bWasChanges = TRUE; for (; LogSize<LogFile->size(); LogSize++) { const char *S = *(*LogFile)[LogSize]; if (0==S) S = ""; SendMessage ( hwLog, LB_ADDSTRING, 0, (LPARAM) S); } SendMessage ( hwLog, LB_SETTOPINDEX, LogSize-1, 0); //FlushLog ( ); } csLog.Leave (); if (_abs(PrSave-progress)>EPS_L) { bWasChanges = TRUE; PrSave = progress; SendMessage ( hwProgress, PBM_SETPOS, u32(progress*1000.f), 0); // timing if (progress>0.005f) { u32 dwCurrentTime = timeGetTime(); u32 dwTimeDiff = dwCurrentTime-phase_start_time; u32 secElapsed = dwTimeDiff/1000; u32 secRemain = u32(float(secElapsed)/progress)-secElapsed; xr_sprintf(tbuf, "Elapsed: %s\n" "Remain: %s", make_time(secElapsed).c_str(), make_time(secRemain).c_str() ); SetWindowText ( hwTime, tbuf ); } else { SetWindowText ( hwTime, "" ); } // percentage text xr_sprintf(tbuf,"%3.2f%%",progress*100.f); SetWindowText ( hwPText, tbuf ); } if (bStatusChange) { bWasChanges = TRUE; bStatusChange = FALSE; SetWindowText ( hwInfo, status); } if (bWasChanges) { UpdateWindow ( logWindow); bWasChanges = FALSE; } csLog.Leave (); _process_messages (); if (bClose) break; Sleep (200); } // Cleanup DestroyWindow(logWindow); }
cglApp::cglApp(int nW, int nH, void* hInst, int nCmdShow) : m_hWnd(NULL) , m_hInstance(hInst) , m_nClearColor(0xFF007F00) , m_pD3D(NULL) , m_nFrameCount(0) , m_rPrevTime(0.0f) { // Register window class WNDCLASS wndClass; wndClass.style = 0; wndClass.lpfnWndProc = D3DBaseAppCallback; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 4; wndClass.hInstance = HINSTANCE(hInst); wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = HBRUSH(GetStockObject(WHITE_BRUSH)); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = s_windowClassName; RegisterClass(&wndClass); // Adjust window in regard to client area nW x nH int nStyle = WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; RECT rRect; SetRect(&rRect, 0, 0, nW, nH); AdjustWindowRect(&rRect, nStyle, TRUE); // Create main window m_hWnd = NULL; m_hWnd = (void*)CreateWindow(s_windowClassName, getWindowText(), nStyle, CW_USEDEFAULT, CW_USEDEFAULT, (rRect.right - rRect.left), (rRect.bottom - rRect.top), NULL, NULL, HINSTANCE(hInst), NULL); if (m_hWnd == NULL) return; // Set pointer SetWindowLong(HWND(m_hWnd), 0, LONG(this)); // Show window ShowWindow(HWND(m_hWnd), nCmdShow); UpdateWindow(HWND(m_hWnd)); // We need to determine the BPP of desktop HDC hDC = GetDC(HWND(m_hWnd)); // Get DC of desktop int nBPP = GetDeviceCaps(hDC, BITSPIXEL); // Retrieve BPP ReleaseDC(HWND(m_hWnd), hDC); // Release DC handle // Create our D3D class cglD3D::CreateParams params; params.hWnd = m_hWnd; params.nBPP = (nBPP == 32) ? cglD3D::BPP_32 : cglD3D::BPP_16; params.nWidth = nW; params.nHeight = nH; m_pD3D = new cglD3D(params); // Check creation result if (m_pD3D == NULL || m_pD3D->isFailed()) return; // Init random generator srand(0); }