How to prohibit / enable screen protection and other programming skills
Author: Xu Jing Zhou (cited in part: soundman32, JHawkZZ)
1. How to activate and close IE browser
// activate and open IE
Void Lounchie ()
{
HWND H = FindWindowEx (Null, Null, Null,
"Microsoft Internet Explorer");
Shellexecute (H, "Open", "C: //simple.html",
NULL, NULL, SW_SHOWNORMAL);
}
// Turn off IE and other applications
Void Closeie ()
{
INT app = bsm_applications;
Unsigned long bsm_app = (unsigned long) app;
BroadcastsystemMessage (BSF_POSTMESSAGE, & BSM_APP,
WM_Close, NULL, NULL;
}
2. How to join the tool tips to the tree control
l First, add the TVS_INFOTIP attribute style to the tree control, as shown below:
IF (! m_ctrltree.create (ws_child | ws_visible |
TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_SHOWSELALWAYS | TVS_Infotip, // Join TVS_INFOTIP, JINGZHOU XU (Tree Control Id: 100)
CRECT (0, 0, 0, 0), & M_WndtreeBar, 100)))
{
Trace0 ("Failed to Create Instant Bar Child / N");
Return -1;
}
l Secret to join the mapping message declaration, as shown below:
AFX_MSG VOID ONGETINFOTIP (NMHDR * PNMHDR, LRESULT * PRESULT); / / Tree Control Join the prompt message, Jingzhou Xu
ON_NOTIFY (TVN_GetInfotip, 100, OnGetInfotip) // Tote on the Tree Control Entries JINGZHOU XU
l Add Identification Moderation:
Void ccreatetreedlg :: ONGETINFOTIP (nmhdr * pnmhdr,
LRESULT * PRESULT)
{
* PRESULT = 0;
NMTVGETINFOTIP * PTVTIPINFO = (NMTVGETITIP *) PNMHDR;
LPARAM ITEMDATA = (DWORD) PTVTIPINFO-> LPARAM;
/ / Corresponding to each entry
HtreeItem HITEM = PTVTIPINFO-> HITEM;
CSTRING TIP;
HtreeItem HrootItem = m_chassistree.getrootItem ();
IF (hrootItem! = ptvtipinfo-> HITEM)
{
TIP = "Tips for Tree Node";
}
Else
{
Tip = "Tips on Tree Roots";
}
STRCPY (ptvtipinfo-> psztext, (lpctstr) TIP);
}
3. How to get the path to the system information box
#include
#define ids_reg_key_msinfo_path1_t ("Software // Microsoft // Shared Tools // Msinfo") #define ids_reg_key_msinfo_path2_t ("Software // Microsoft // Shared Tools Location")
#define IDS_REG_VAL_MSINFO_PATH1_T ("Path")
#define IDS_REG_VAL_MSINFO_PATH2_T ("msinfo")
#define IDS_MSINFO_EXE_NAME_T ("msinfo32.exe")
// ...
Bool getSysInfoPath (CString & Strpath)
{
StrPath.empty ();
LPTSTR pszpath = strpath.getBuffer (MAX_PATH);
CregKey REG;
DWORD dwsize = max_path;
Long nret = reg.open (HKEY_LOCAL_MACHINE, IDS_REG_KEY_MSINFO_PATH1, KEY_READ);
// Look for the first "msinfo32.exe" location in the registry
IF (nret == error_success)
{
#if (_MFC_VER> = 0x0700)
NRET = reg.queryStringValue (IDS_REG_VAL_MSINFO_PATH1, PSZPATH, & DWSIZE);
#ELSE
NRET = reg.queryvalue (pszpath, ids_reg_val_msinfo_path1, & dwsize);
#ENDIF
Reg.close ();
}
// If you fail for the first time, I will find a second time.
IF (nret! = error_success)
{
NRET = reg.open (HKEY_LOCAL_MACHINE, IDS_REG_KEY_MSINFO_PATH2, Key_Read);
IF (nret == error_success)
{
#if (_MFC_VER> = 0x0700)
Reg.QueryStringValue (IDS_REG_VAL_MSINFO_PATH2, PSZPATH, & DWSIZE);
#ELSE
REG.QUERYVALUE (pszpath, ids_reg_val_msinfo_path2, & dwsize);
#ENDIF
// The path name does not include the EXE file name
IF (nret == error_success)
Verify (:: pathappend (pszpath, ids_msinfo_exe_name);
Reg.close ();
}
}
StrPath.releaseBuffer ();
StrPath.Freeextra ();
// Check if the file is valid.
Return :: PathfileExists (STRPATH);
}
4. How to run a program directly in a resource
BOOL Run ()
{
CFILE F;
Char * pfilename = "execution.exe";
IF (! f.open (pfileename, cfile :: modecreate | cfile :: Modewrite, Null)
{
AFXMessageBox ("Can Not Create File!"); RETURN 0;
}
CString path = f.getfilepath ();
Hglobal HRES;
HRSRC HRESINFO;
// Get application instances
Hinstance Insapp = AfxGetInstanceHandle ();
// Look for EXE resources name
HRESINFO = FindResource (INSAPP, (LPCSTR) IDR_EXE4, "EXE");
HRES = loading (insapp, hresinfo); // loading it
DWORD DFILENGTH = SizeOfResource (Insapp, HRESINFO); // Calculate EXE file size
F.Writehuge ((lpstr) hres, dfilelength); // Write temporary file
f.close ();
Hinstance hinssd = shellexecute (NULL, "Open", Path, NULL, NULL, SW_SHOWNORMAL);> // Run it.
Return 1;
}
5. How to traverse the entire directory
#include
#include
// Browse the directory.
Void Browsefolder (Void)
{
TCHAR PATH [MAX_PATH];
Browseinfo bi = {0};
bi.lpsztitle = ("Remissive Call All Directory");
LpitemidList PIDL = SHBROWSEFORFOLDER (& BI);
IF (PIDL! = 0)
{
/ / Get the directory path
ShgetPathFromidList (PIDL, PATH);
/ / Set to the current path
SetCurrentDirectory (PATH);
/ / Search all subdiresses
SearchFolder (PATH);
/ / Release memory
IMALLOC * IMALLOC = 0;
IF (Succeeded (ShuTmalloc (& IMALLOC)))
{
Imalloc-> free (PIDL);
IMALLOC-> Release ();
}
}
// Search all subdirectories and files.
Void SearchFolder (Tchar * PATH)
{
Win32_find_data findfiledata;
Handle hfind;
TCHAR FileName [MAX_PATH 256];
TCHAR PATHBAK [MAX_PATH];
// Copy the initial user selection directory
STRCPY (Pathbak, PATH);
/ / Looking for the first file
Hfind = findfirstfile ("*. *", & findfiledata);
/ / Search all files and subdirectories
DO
{
IF (HFIND! = INVALID_HANDLE_VALUE)
{
// If it is the current directory or parent directory, skip
IF (! ") ||! (FindfileData.cfileName,")))
{
CONTINUE;
}
// Restore the initial user selection directory
STRCPY (PATH, PATHBAK);
/ / List all discovered files
Sprintf (path, "% s //% s", path, findfiledata.cfilename); // If setCurrentDirectory is successful, it is a directory, recursive call Continue search subdirectory
IF ((SETCURRENTDIRECTORY (PATH)))
{
SearchFolder (PATH);
}
// Insert the file and path name to the list box m_listbox_hwnd
SendMessage (m_listbox_hwnd, lb_addstring, 0, path); // <- insert what you want done here!
}
}
While (FindNextFile (HFIND, & FINDFILEDATA) && Hfind! = Invalid_Handle_Value);
FindClose (HFIND);
}
6. How to implement the animation effect between the window to the system area icon
// ******************************************************** ***************************************
// * Name: FindtrayWnd
// * Author: Xu Jing Zhou (jingzhou_xu@163.net)
// * Function: Look for system zone before displaying the form animation effect
// ******************************************************** ***************************************
Bool Callback FindtrayWnd (HWND HWND, LPARAM LPARAM)
{
Tchar szclassname [256];
GetclassName (HWND, SZClassName, 255);
// Compare the window class name
IF (_TCSCMP (SzclassName, _T ("TRAYNOTIFYWND")) == 0)
{
CRECT * prect = (create *) lparam;
:: getWindowRect (hwnd, prect);
Return True;
}
// When you find a clock window, you can end.
IF (_TCSCMP (SzclassName, _T ("TRAYCLOCKWCLASS") == 0)
{
CRECT * prect = (create *) lparam;
CRECT RectClock;
:: getWindowRect (HWND, RectClock);
Prect-> Right = RectClock.Left;
Return False;
}
Return True;
}
// ******************************************************** ***************************************
// * Name: Winanimation
// * Author: Xu Jing Zhou (jingzhou_xu@163.net)
// * Function: Display the number of window animation effects
// ******************************************************** ***************************************
Void cscreensnapdlg :: WinaniMation (Bool Showflag)
{
CRECT RECT (0, 0, 0);
/ / Find Tray Window
CWND * PWND = FINDWINDOW ("shell_traywnd", null);
IF (PWND)
{
PWND-> getWindowRect (Rect); EnumChildWindows (PWND-> M_HWND, FindtrayWnd, (LPARAM) & Rect)
// RECT is a rectangle of the tray area
CRECT RCWND;
GetWindowRect (rcwnd);
IF (Showflag) // Form Sliding System Area
DrawanimatedRects (GetSafehWnd (), IDANI_CAPTION, RCWND, RECT)
ELSE // Form slides from the system area
DrawanImatedRects (GetSafehWnd (), IDANI_CAPTION, RECT, RCWND);
}
}
Usage is as follows:
IF (iswindowvisible ()) // Has hidden
{
ShowWindow (sw_hide); // Hide form
WinaniMation (TRUE); // Form Animation Sliding into System Area
}
Else
{
WinaniMation (false); // Form Animation Sliding from the system area
ShowWindow;
}
7. How to determine the version of the current operating system
/ / -------------------------------------------------------------------------------------------- ------------------------------------------------
/ / Judgment Operating System Caution and Variables, Jingzhou XU
Typedef Enum tagwin32systype {
Windows32s,
Windowsnt3,
Windows95,
Windows98,
Windowsme,
WindowsNT4,
Windows2000,
Windowsxp
Win32SYSTYPE;
/ / Judgment Operating System Caution and Variables, Jingzhou XU
Win32Systype isshellsystype ()
{
Win32Systype shellType;
DWORD WINVER;
OsversionInfo * OSVI;
Winver = getversion ();
IF (WinVER <0x80000000) {/ * nt * /
ShellType = WindowsNT3;
Osvi = (OsversionInfo *) Malloc (Sizeof (OsversionInfo);
IF (OSVI! = NULL) {
MEMSET (OSVI, 0, SIZEOF (OsversionInfo);
Osvi-> dwosversioninfosize = sizeof (OsversionInfo);
GetVersionex (OSVI);
IF (OSVI-> dwmajorversion == 4L) shellType = WindowsNT4;
Else IF (OSVI-> dwmajorversion == 5L && OSVI-> dwminorversion == 0L) shellType = Windows2000;
Else if (Osvi-> dwmajorversion == 5L && OSVI-> dwminorversion == 1L) shellType = windowsxp;
Free (OSVI);
}
}
Else IF (LOBYTE (WinVER) <4)
ShellType = Windows32s;
Else {shellType = windows95;
Osvi = (OsversionInfo *) Malloc (Sizeof (OsversionInfo);
IF (OSVI! = NULL) {
MEMSET (OSVI, 0, SIZEOF (OsversionInfo);
Osvi-> dwosversioninfosize = sizeof (OsversionInfo);
GetVersionex (OSVI);
IF (OSVI-> dwmajorversion == 4L && OSVI-> dwminorversion == 10L) shellType = Windows98;
Else IF (OSVI-> dwmajorversion == 4L && OSVI-> dwminorversion == 90L) shellType = Windowsme;
Free (OSVI);
}
}
Return shellType;
}
File: // ---------------------------------------------- --------------------------------------------------