c++ vs release没有exe_[LOG]C&C++语法笔记

  • 三种【Messagebox】:
//第一种
MessageBox(NULL, TEXT("申请空间失败。"), NULL, MB_ICONINFORMATION | MB_YESNO);
MessageBox(NULL, dm.Ver(), TEXT("提示:"), NULL);
//第二种
MessageBox(_T("你好,世界!!!"), _T("提示:"), MB_OK);
//第三种 --来自MFC
AfxMessageBox(L"登陆成功!!!", 0, 0);
AfxMessageBox(L"登陆成功!!!");
  • 两种输出信息到【调试窗口】:
//第一种
TRACE("F:%dn", 1);
//第二种
OutputDebugString(L"1n");

521400b9b3ad495055bef11b2e7ff99d.png
  • 两种【禁用按钮】:
//第一种
m_btnQuit.EnableWindow(FALSE);//禁用按钮
//第二种
((CButton*)GetDlgItem(按钮ID))->EnableWindow(FALSE) //禁用按钮

060412e1f62f99431e9627c7454841aa.png
  • C++11不阻塞MFC的【守护线程】:
#include <thread>

//例
std::thread ThreadGodShoot(&ClassName::FunName, this);
ThreadGodShoot.detach();

//如
void FunName(int i,int j);

//则
std::thread ThreadGodShoot(&ClassName::FunName, this,1,2);
ThreadGodShoot.detach();

//或
std::thread ThreadGodShoot(FunName);
ThreadGodShoot.detach();
  • VS中提升【UAC】:
右键【工程名称】选择【属性】->【配置属性】->【链接器】->【清单文件】->【UAC执行级别】
  • 遍历【进程】返回【PID】:
#include <tlhelp32.h>
//
DWORD findPidByName(wchar_t * pname)
{
	HANDLE h;
	PROCESSENTRY32 procSnapshot;
	h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	procSnapshot.dwSize = sizeof(PROCESSENTRY32);

	do
	{
		if (!_wcsicmp(procSnapshot.szExeFile, pname))
		{
			//
			DWORD pid = procSnapshot.th32ProcessID;
			//
			CloseHandle(h);
			//
			return pid;
		}
	} while (Process32Next(h, &procSnapshot));

	CloseHandle(h);
	return 0;
}
//
dwProcessId = findPidByName(L"XXX.exe");
//
if (dwProcessId == 0)
{

}
  • 【鼠标右键】是否按下:
if ((GetKeyState(VK_RBUTTON) & 0x100) != 0)
{

}
  • 【LPCSTR】 to【 LPCWSTR】:
//
LPCSTR filename="jojo";
//
CA2W(filename);
  • 截取屏幕指定区域【位图】存储至【运行目录】:
//例
screenCapturePart(900, 490, 120, 110, "this.bmp");

//
bool screenCapturePart(int x, int y, int w, int h, LPCSTR fname) 
{
	HDC hdcSource = GetDC(NULL);
	HDC hdcMemory = CreateCompatibleDC(hdcSource);

	int capX = GetDeviceCaps(hdcSource, HORZRES);
	int capY = GetDeviceCaps(hdcSource, VERTRES);

	HBITMAP hBitmap = CreateCompatibleBitmap(hdcSource, w, h);
	HBITMAP hBitmapOld = (HBITMAP)SelectObject(hdcMemory, hBitmap);

	BitBlt(hdcMemory, 0, 0, w, h, hdcSource, x, y, SRCCOPY);
	hBitmap = (HBITMAP)SelectObject(hdcMemory, hBitmapOld);

	DeleteDC(hdcSource);
	DeleteDC(hdcMemory);

	HPALETTE hpal = NULL;
	if (saveBitmap(fname, hBitmap, hpal)) return true;
	return false;
}
//
bool saveBitmap(LPCSTR filename, HBITMAP bmp, HPALETTE pal)
{
	bool result = false;
	PICTDESC pd;

	pd.cbSizeofstruct = sizeof(PICTDESC);
	pd.picType = PICTYPE_BITMAP;
	pd.bmp.hbitmap = bmp;
	pd.bmp.hpal = pal;

	LPPICTURE picture;
	HRESULT res = OleCreatePictureIndirect(&pd, IID_IPicture, false,
		reinterpret_cast<void**>(&picture));

	if (!SUCCEEDED(res))
		return false;

	LPSTREAM stream;
	res = CreateStreamOnHGlobal(0, true, &stream);

	if (!SUCCEEDED(res))
	{
		picture->Release();
		return false;
	}

	LONG bytes_streamed;
	res = picture->SaveAsFile(stream, true, &bytes_streamed);

	HANDLE file = CreateFile(CA2W(filename), GENERIC_WRITE, FILE_SHARE_READ, 0,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

	if (!SUCCEEDED(res) || !file)
	{
		stream->Release();
		picture->Release();
		return false;
	}

	HGLOBAL mem = 0;
	GetHGlobalFromStream(stream, &mem);
	LPVOID data = GlobalLock(mem);

	DWORD bytes_written;

	result = !!WriteFile(file, data, bytes_streamed, &bytes_written, 0);
	result &= (bytes_written == static_cast<DWORD>(bytes_streamed));

	GlobalUnlock(mem);
	CloseHandle(file);

	stream->Release();
	picture->Release();

	return result;
}
  • 【int】 to 【lpcwstr】:
//
int i = 1;
//
wchar_t buffer[256];
wsprintfW(buffer, L"%dn", i);
//
OutputDebugString(buffer);
  • GUI控件调用:
//无成员变量
((CButton*)GetDlgItem(IDC_GodPower))->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_GodPower))->SetWindowText(L"XXX");

//成员变量
m_btnQuit.EnableWindow(FALSE);
  • 定时器:
//启动
SetTimer(1,1000,NULL);//定时器ID,定时间隔,略

//关闭
KillTimer(1);

void Cxxx::OnTimer(UINT_PTR nIDEvent)
{
	//
        ...
	//
	CDialogEx::OnTimer(nIDEvent);
}
  • VS中【win32】和【x86项目】的区别和坑:
1.win32指所有的32bit的平台,而x86仅仅是指Intel和AMD的32bit平台。
2.比如32bit的ARM平台,就包含在win32中,不在x86的范围中。
3.偶然调试一个win32项目的大漠插件vc++demo,移植到x86项目中报错,用了一天调试没有成功,后将该x86项目改为win32项目,移植成功。
  • 【大漠插件】中的【FindColor】等函数在【VC++】中的坑:
//正确
VARIANT intX;
VARIANT intY;

int dm_ret = dm.FindColor(0, 0, 1920, 1080, _T("00ff00-505050"), 1.0, 0, &intX, &intY);

//错误
VARIANT* intX = 0;
VARIANT* intY = 0;

int dm_ret = dm.FindColor(0, 0, 1920, 1080, _T("00ff00-505050"), 1.0, 0, intX, intY);

//取值
intX.intVal;
intY.intVal;
  • 获取屏幕【水平】和【垂直】分辨率:
//
int horizontal = 0;
int vertical = 0;
//
GetDesktopResolution(horizontal, vertical);
//
wchar_t buffer[256];
wsprintfW(buffer, L"%d %dn", horizontal, vertical);
//
OutputDebugString(buffer);

void GetDesktopResolution(int& horizontal, int& vertical)
{
   RECT desktop;
   // Get a handle to the desktop window
   const HWND hDesktop = GetDesktopWindow();
   // Get the size of screen to the variable desktop
   GetWindowRect(hDesktop, &desktop);
   // The top left corner will have coordinates (0,0)
   // and the bottom right corner will have coordinates
   // (horizontal, vertical)
   horizontal = desktop.right;
   vertical = desktop.bottom;
}

82ccf2c0e0859a0dc5187d812ea13bef.png
  • 检查按钮是否启用:
m_btnGodPower.IsWindowEnabled() == TRUE

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值