如果才能隐藏控制台程序的右键菜单?
这是我用控制台写的贪食蛇程序
有个问题一直困惑着我?
怎样取消控制台右键菜单
如果点击控制台右键菜单的标记的话。虽然程序还在运行,但是控制台显示就会暂停。
我想解决这个问题,就要取消这个程序的控制台右键菜单的显示。
请问:如果才能隐藏控制台程序的右键菜单?
PS:我见过这种程序,cmd里能显示右键菜单,但是这种程序就显示不出来!(同一台电脑运行)
------解决方案--------------------
vs2010测试通过
#include
//BOOL ReadConsoleInput(
// HANDLE hConsoleInput, //输入句柄
// PINPUT_RECORD lpBuffer, //指向INPUT_RECORD结构体(数组)的指针
// DWORD nLength, //上面那个结构体的大小
// LPDWORD lpNumberOfEventsRead //实际读入输入内容的个数
//);
VOID MouseEventProc(MOUSE_EVENT_RECORD mer)
{
switch(mer.dwEventFlags)
{
case 0:
if(mer.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
{
printf("left button press \n");
}
else if(mer.dwButtonState == RIGHTMOST_BUTTON_PRESSED)
{
printf("right button press \n");
}
break;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE _hIn = GetStdHandle(STD_INPUT_HANDLE);
HANDLE _hOut = GetStdHandle(STD_OUTPUT_HANDLE);
INPUT_RECORD _InRec[255];
DWORD _NumRead;
BOOL bRet = true;
while(true)
{
bRet = ReadConsoleInput(_hIn,_InRec,1,&_NumRead);
if(!bRet)
{
break;
}
for(unsigned int i = 0; i
{
switch(_InRec[i].EventType)
{
case MOUSE_EVENT:
MouseEventProc(_InRec[i].Event.MouseEvent);
break;
}
}
}
return 0;
}
------解决方案--------------------
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
HFONT hfont,ohfont;
RECT r;
COLORREF oc;
switch(message) {
case WM_CLOSE://按Alt+F4退出
PostQuitMessage(0);
break;
case WM_PAINT:
BeginPaint(hWnd, &ps);
hdc = ps.hdc; // the device context to draw in
GetClientRect(hWnd, &r); // Obtain the window's client rectangle
hfont = CreateFont(240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "华文楷体");
ohfont=(HFONT)SelectObject(hdc,hfont);
oc=SetTextColor(hdc,0x00C080FF);
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc,r.left+r.right/2-720, r.top+r.bottom/2-120,"最短画图程序",12);
SelectObject(hdc,ohfont);
SetTextColor(hdc,oc);
DeleteObject(hfont);
EndPaint(hWnd, &ps);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MSG msg = {0};
WNDCLASS wc = {0};
HBRUSH hbrh;
hbrh=CreateSolidBrush(0x00000000);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;