c語(yǔ)言如何檢測(cè)點(diǎn)擊的按鈕?
main.c:#include <windows.h>#include "resource.h"/* Declare Windows procedure */LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);/* Current app instance */HINSTANCE hInst;/* Make the class name into a global variable */TCHAR szClassName[] = TEXT("WindowsApp");int WINAPIWinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil){ HWND hwnd;/* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass *//* Save this instance */hInst = hThisInstance; /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS;/* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = MAKEINTRESOURCE (IDC_12345); wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx (0,/* Extended possibilites for variation */szClassName,/* Classname */TEXT("12345"), /* Title Text */WS_OVERLAPPEDWINDOW, /* default window */CW_USEDEFAULT,/* Windows decides the position */0,/* where the window ends up on the screen */CW_USEDEFAULT,/* The programs width */0,/* and height in pixels */HWND_DESKTOP, /* The window is a child-window to desktop */NULL, /* No menu */hThisInstance,/* Program Instance handler */NULL/* No Window Creation data */); /* Make the window visible on the screen */ ShowWindow (hwnd, nFunsterStil); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam;}/* This function is called by the Windows function DispatchMessage() */LRESULT CALLBACKWindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){PAINTSTRUCT ps;HDC hdc;RECT rt;TCHAR szHello[] = TEXT("今天你打卡了嗎?"); switch (message) /* handle the messages */ {case WM_COMMAND: switch (LOword(wParam)) { case IDM_ABOUT:MessageBox (hwnd, TEXT ("賈智淵制作"), TEXT ("About"), MB_OK | MB_ICONINFORMATION);break;case IDM_EXIT:DestroyWindow(hwnd);break;case IDM_QU:MessageBox (hwnd, TEXT ("今天你打卡了嗎,?"), TEXT ("問(wèn)"), MB_OK | MB_ICONINFORMATION | MB_OKCANCEL | MB_ICONINFORMATION);MessageBox (hwnd, TEXT ("去打卡!"),TEXT ("溫馨提示"), MB_OK | MB_ICONINFORMATION | MB_OKCANCEL | MB_ICONINFORMATION);default:return DefWindowProc(hwnd, message, wParam, lParam); } break; case WM_PAINT:hdc = BeginPaint(hwnd, &ps);/* TODO: Add any drawing code here... */GetClientRect(hwnd, &rt);DrawText(hdc, szHello, lstrlen(szHello), &rt, DT_CENTER);EndPaint(hwnd, &ps);break; case WM_DESTROY: PostQuitMessage (0);/* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0;}12345.rc:#include "resource.h"#include <windows.h>///////////////////////////////////////////////////////////////////////////////// Menu//IDC_12345 MENUBEGIN POPUP "&File" BEGIN MENUITEM "E&xit", IDM_EXIT END POPUP "&Help" BEGIN MENUITEM "&About ...",IDM_ABOUT END POPUP "&Q" BEGIN MENUITEM "&QU",IDM_QU ENDENDresource.h:#define IDM_EXIT10001#define IDM_ABOUT10002#defineIDM_QU 10003#define IDC_1234510101#define IDD_ABOUTBOX10102怎樣修改case IDM_QU:MessageBox (hwnd, TEXT ("今天你打卡了嗎,?"), TEXT ("問(wèn)"), MB_OK | MB_ICONINFORMATION | MB_OKCANCEL | MB_ICONINFORMATION);MessageBox (hwnd, TEXT ("去打卡!"),TEXT ("溫馨提示"), MB_OK | MB_ICONINFORMATION | MB_OKCANCEL | MB_ICONINFORMATION);部分來(lái)確認(rèn)點(diǎn)的是哪個(gè)按鈕(確認(rèn)/取消)
你是用MessageBox上的按鈕,所以可直接用它返回值來(lái)判斷
你的程序可以這樣改
case IDM_QU:if (MessageBox(hwnd, TEXT("今天你打卡了嗎?"), TEXT("問(wèn)"),MB_OK | MB_ICONINFORMATION | MB_OKCANCEL | MB_ICONINFORMATION)==IDCANCEL) //按下取消鍵,,未打卡{if (MessageBox(hwnd, TEXT("去打卡,!"), TEXT("溫馨提示"),MB_OK | MB_ICONINFORMATION | MB_OKCANCEL | MB_ICONINFORMATION)==IDOK){ //按下了確定}else{ //按下了取消}}else{///確定已打卡}default:
另外,,c語(yǔ)言win32的開(kāi)發(fā)模式目前只適合于學(xué)習(xí)了,實(shí)際開(kāi)發(fā)肯定要用C++和構(gòu)件了(不然開(kāi)發(fā)效率太低了)
相關(guān)推薦
- 中國(guó)籃球雛鷹計(jì)劃如何報(bào)名
- 約戰(zhàn)狂三主線約會(huì)第一章怎么打出‘狂三槍口下的真實(shí)’
- 車(chē)圣好:A6發(fā)動(dòng)顯示自動(dòng)啟停系統(tǒng)故障,抖動(dòng)厲害,,1分左右自動(dòng)熄火,,好大一股汽油味,反復(fù)啟動(dòng)幾次又正常了
- cctv1中國(guó)詩(shī)詞大會(huì)哪一期胡夏郁可唯到達(dá)現(xiàn)場(chǎng)唱知否知否
- 按鍵精靈計(jì)數(shù)語(yǔ)句
- 丙戌,、乙未,、辛酉、癸巳出生的男孩五行缺什么,?
- 是否不是收錢(qián)的陪聊,一般人不喜歡和別人說(shuō)一些難回答的問(wèn)題和自己不了解的事,?,??
- 為什么現(xiàn)在有些人不玩荒野行動(dòng)
- 奧迪A6顯示自動(dòng)啟停系統(tǒng)故障,,抖動(dòng)厲害,后面慢慢熄火,,一股汽油味,,反復(fù)幾次有正常了是什么原因
- 飄香一劍霍同基