當前位置:編程學習大全網 - 源碼下載 - 計算機應用源代碼

計算機應用源代碼

# include & ltWindows.h & gt

# include & lttchar.h & gt

# include & ltassert.h & gttchar * SZ question = text(" 1000 * 10是什麽?");

TCHAR * SZ answer = TEXT(" 10000 ");

WNDPROC oldEditProc = NULL

WNDPROC oldButtonProc = NULL

HFONT hFont = NULL

HWND hTestDlgWnd=NULL,hEditWnd=NULL,hButtonWnd = NULL

LRESULT回調TestDlgProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM LPARAM);

LRESULT回調MyEditProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM LPARAM);

LRESULT回調MyButtonProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM LPARAM);

BOOL system reboot();int WINAPI WinMain(h instance h instance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)

{

wnd class wnd class = { 0 };

TCHAR * SZ class name = TEXT(" TestDlg ");

MSG MSG = { 0 };COLORREF COLOR = GetSysColor(COLOR _ active border);

HBRUSH HBRUSH = CreateSolidBrush(color);

assert(hBrush);hFont =(hFont)GetStockObject(DEFAULT _ GUI _ FONT);

log font log font = { 0 };

GetObject(hFont,sizeof(LOGFONT),& amplog font);

delete object(hFont);

hFont = NULL

log font . lf height = 12;

_ tcscpy (logfont。lffacename,text("我的世界"));

hFont = createfont indirect(& amp;log font);

斷言(hFont);wnd class . style = CS _ no close;

wnd class . h instance = h instance;

wnd class . HBR background = HB rush;

wnd class . hcursor = load cursor(NULL,MAKEINTRESOURCE(IDC _ ARROW));

wndclass.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(IDI _應用));

wnd class . cbwndextra = 0;

wnd class . cbclsextra = 0;

wnd class . lpfnwndproc = TestDlgProc;

wndclass.lpszMenuName = NULL

wnd class . lpsz class name = SZ class name;

如果(!register class(& amp;wndclass))

{

MessageBox(NULL,TEXT("窗口註冊失敗!") )、TEXT ("warning ")、MB _ OK);

返回S _ FALSE

} DWORD style = WS _ overlapped window & amp;~(WS _ maximize box | WS _ minimize box | WS _ thick frame);

int CX = getsystem metrics(SM _ CX full screen);

int cy = GetSystemMetrics(SM _ cy full screen);

int iTestDlgWidth = 500

int iTestDlgHeight = 230

hTestDlgWnd = CreateWindowEx(WS _ EX _ tool window,

szClassName,

正文("請回答問題:"),

風格,

cx/2-iTestDlgWidth/2,

cy/2-iTestDlgHeight/2,

iTestDlgWidth,

iTestDlgHeight,

空,

空,

hInstance,

NULL);

assert(hTestDlgWnd);

* SendMessage(hTestDlgWnd,WM_SETFONT,(WPARAM)hFont,1);style = WS _ CHILD | ES _ MULTILINE | ES _ LEFT | ES _ AUTOHSCROLL | ES _ AUTOVSCROLL;

hEditWnd=CreateWindow(

文本(“編輯”),

文本(""),

風格,

10,

40,

iTestDlgWidth-20,

100,

hTestDlgWnd,

空,

hInstance,

);

assert(hEditWnd);

oldEditProc =(WNDPROC)SetWindowLong(hEditWnd,GWL_WNDPROC,(LONG)MyEditProc);

assert(oldEditProc);

* SendMessage(hedit wnd,WM_SETFONT,(WPARAM)hFont,1);style = WS _ CHILD

hButtonWnd = create window(TEXT(" Button "),

文本(“確定”),

風格,

10,

150,

60,

20,

hTestDlgWnd,

空,

hInstance,

);

assert(hButtonWnd);

oldButtonProc =(WNDPROC)SetWindowLong(hButtonWnd,GWL_WNDPROC,(LONG)MyButtonProc);

assert(oldButtonProc);

* SendMessage(hButtonWnd,WM_SETFONT,(WPARAM)hFont,1);ShowWindow(hTestDlgWnd,SW _ SHOW);

ShowWindow(hEditWnd,SW _ SHOW);

ShowWindow(hButtonWnd,SW _ SHOW);

update window(hTestDlgWnd);* SetFocus(hEditWnd);

while(GetMessage(& amp;msg,NULL,0,0))

{

翻譯消息(& amp味精);

dispatch message(amp;味精);

}

中頻(hBrush)

delete object(HB rush);

中頻(高頻)

delete object(hFont);

返回msg.wParam

}LRESULT回調TestDlgProc(HWND hWnd,UINT消息,WPARAM wParam,LPARAM lParam)

{

開關(消息)

{

案例WM_CLOSE:

{

銷毀窗口(hWnd);

}

打破;

案例WM_DESTROY:

{

PostQuitMessage(0);

}

打破;

案例WM_PAINT:

{

paint struct PS = { 0 };

HDC hDC = NULL

hDC = begin paint(hWnd & amp;PS);

HFONT hold font =(HFONT)select object(hDC,HFONT);

int oldMode=SetBkMode(hDC,TRANSPARENT);

TextOut(hDC,10,5,szQuestion,_ TCS len(SZ question));

SelectObject(hDC,hold font);

SetBkMode(hDC,old mode);

面漆(hWnd & amp;PS);

}

打破;

}

返回DefWindowProc(hWnd,message,wParam,lParam);

}LRESULT回調MyEditProc(HWND hWnd,UINT消息,WPARAM wParam,LPARAM lParam)

{

return (*oldEditProc)(hWnd,message,wParam,lParam);

}LRESULT回調MyButtonProc(HWND hWnd,UINT消息,WPARAM wParam,LPARAM lParam)

{

開關(消息)

{

案例WM_LBUTTONDOWN:

{

TCHAR buf[512]= { 0 };

GetWindowText(hEditWnd,buf,512);如果(!_tcscmp(buf,szAnswer))

{

MessageBox(hWnd,TEXT("妳回答正確!"),TEXT ("prompt "),MB _ OK);

* SendMessage(hTestDlgWnd,WM_CLOSE,0,0);

}

其他

{

MessageBox(hWnd,TEXT)(“妳答錯了!請做好接受懲罰的準備!!"),TEXT ("prompt "),MB _ OK);

system reboot();

}

}

打破;

}

return (*oldButtonProc)(hWnd,message,wParam,lParam);

}BOOL系統重新啟動()

{

處理hToken

TOKEN _ PRIVILEGES tkp

如果(!OpenProcessToken(GetCurrentProcess(),TOKEN _ ADJUST _ PRIVILEGES | TOKEN _ QUERY,& amphToken))

{

返回(假);

}

LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,& amptkp。權限[0]。luid);

tkp。PrivilegeCount = 1;

tkp。權限[0]。屬性= SE _ PRIVILEGE _ ENABLED

AdjustTokenPrivileges(hToken,FALSE,& amptkp,0,(PTOKEN_PRIVILEGES)NULL,0);if (GetLastError()!=錯誤_成功)

{

返回FALSE

}如果(!ExitWindowsEx(EWX_REBOOT,0))

{

返回FALSE

}

返回TRUE

}在回答關機欺騙程序之前,需要先構建壹個WIN32程序,粘貼進去。

  • 上一篇:股票公式,三天前的K線收大陽線怎麽編
  • 下一篇:借錢可以不用還?2021年新規出爐,這7種情況可以不用還錢
  • copyright 2024編程學習大全網