学习,接分。
小妹,哥哥看你骨骼清奇,绝非凡人,将来必成大业,不如这样,你先把裤裤脱了,待哥哥为你开启灵窍,然后我们一起努力钻研如何
/** 例题需要实现的方面是: 总分=0,数A=0,数B=0,点击加分按钮,变量总分=点击按钮的次数*10,总分的 值用小图片显示出来,点击按钮A一次,数A+1,数A下面显示数A的值,总分-1, 代表总分的图片变成-1后的值,点击按钮B一次,数B+1,数B下面显示数B的值, 总分-1,代表总分的图片变成-1后的值; */ #include <windows.h> #include <stdio.h> ////////////////////////////////////////////////////////// #define jiafen 1 #define shuA 2 #define shuB 3 const LPSTR szClassName = "sunxin2006"; HINSTANCE hHandle = 0; HBITMAP hBack = 0; HDC hdc_buffer = 0; BITMAP bitmap, d_bitmap; HBITMAP hDigital[10]; int total = 0; int digit_a = 0; int digit_b = 0; ////////////////////////////////////////////////////////// LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void on_create(HWND); void on_paint(HDC); void on_close(HWND); void on_mousemove(HWND, DWORD, DWORD); void create_button(HWND parent, LPSTR text, int x, int y, int width, int height, int ctl_id); void load_digital_bitmap(void); void unload_digital_bitmap(void); void go_jiafen(HWND); HBITMAP get_digital(char digital); ////////////////////////////////////////////////////////// //程序入口 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdLine, int nShow) { HWND hwnd; MSG msg; WNDCLASS wnd; HDC hdc_main; hHandle = hInst; memset(&wnd, 0, sizeof(wnd) ); wnd.hCursor = LoadCursor(NULL, IDC_ARROW); wnd.hInstance = hInst; wnd.lpfnWndProc = WndProc; wnd.lpszClassName = szClassName; wnd.style = CS_HREDRAW | CS_VREDRAW; wnd.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); if(! RegisterClass(&wnd) ) { MessageBox(NULL, "Error RegisterClass", "Error", MB_OK); return -1; } hBack = (HBITMAP) LoadImage(NULL, "background.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); GetObject(hBack, sizeof(BITMAP), &bitmap); hwnd = CreateWindow(szClassName, "小窗口", WS_OVERLAPPEDWINDOW, 10, 20, bitmap.bmWidth, bitmap.bmHeight, 0, 0, hInst, 0); if( !hwnd ) { MessageBox(NULL, "Error Create Windows", "Error", MB_OK); return -1; } hdc_main = GetDC(hwnd); hdc_buffer = CreateCompatibleDC(hdc_main); SelectObject(hdc_buffer, hBack); ReleaseDC(hwnd, hdc_main); ShowWindow(hwnd, nShow); UpdateWindow(hwnd); while( GetMessage(&msg , NULL, 0, 0) >0 ) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } //消息回调过程 LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_CREATE: on_create(hwnd); break; case WM_PAINT: HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hwnd, &ps); on_paint(hdc); EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_CLOSE: on_close(hwnd); break; case WM_COMMAND: switch(LOWORD(wParam)) { case jiafen: go_jiafen(hwnd); break; case shuA: break; case shuB: break; } break; case WM_MOUSEMOVE: on_mousemove(hwnd, LOWORD(lParam), HIWORD(lParam)); break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } //////////////////////////////////////////////////////////////////////////////////////// // 处理窗口消息 void on_create(HWND hwnd) { create_button(hwnd, "加分", 556, 271, 49, 48, jiafen); create_button(hwnd, "钮A", 138, 269, 34, 40, shuA); create_button(hwnd, "钮B", 303, 269, 34, 40, shuB); load_digital_bitmap(); } void on_close(HWND hwnd) { if(IDYES == MessageBox(hwnd,"真的要退出吗?","小窗口标题", MB_YESNO) ) { unload_digital_bitmap(); DeleteDC(hdc_buffer); DeleteObject(hBack); DestroyWindow(hwnd); } } void on_paint(HDC hdc) { if(hdc_buffer) { BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdc_buffer, 0, 0, SRCCOPY); } } void on_mousemove(HWND hwnd, DWORD x, DWORD y) { char buf[50]; sprintf(buf, "小窗口 x = %d, y = %d", x, y); SetWindowText(hwnd, buf); } //////////////////////////////////////////////////////////////////////////////////////////////// // 处理command中的按钮消息 void go_jiafen(HWND hwnd) { int i, slen, base_x = 491, base_y = 181; char ibuf[20]; HDC temp; total += 10; sprintf(ibuf, "%06d", total); slen = strlen(ibuf); //SelectObject(hdc_buffer, hBack); temp = CreateCompatibleDC(NULL); for(i = 0; i < slen; i++) { SelectObject(temp, get_digital(ibuf[i]) ); BitBlt(hdc_buffer, base_x + i * d_bitmap.bmWidth, base_y, d_bitmap.bmWidth, d_bitmap.bmHeight, temp, 0, 0, SRCCOPY); } DeleteDC(temp); InvalidateRect(hwnd, NULL, FALSE); } HBITMAP get_digital(char digital) { switch(digital) { case '0': return hDigital[0]; break; case '1': return hDigital[1]; break; case '2': return hDigital[2]; break; case '3': return hDigital[3]; break; case '4': return hDigital[4]; break; case '5': return hDigital[5]; break; case '6': return hDigital[6]; break; case '7': return hDigital[7]; break; case '8': return hDigital[8]; break; case '9': return hDigital[9]; break; } return 0; } //////////////////////////////////////////////////////////////////////////////////////////////// // 辅助函数 void create_button(HWND parent, LPSTR text, int x, int y, int width, int height, int ctl_id) { CreateWindow("button", text, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, x, y, width, height, parent, (HMENU) ctl_id, hHandle, 0); } void load_digital_bitmap() { char buf[20]; int i; for(i = 0; i < 10; i++) { sprintf(buf, "%d.bmp", i); hDigital[i] = (HBITMAP) LoadImage(NULL, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if( hDigital[i] == 0) MessageBox(NULL, "load digital bmpfile error!", "error", MB_OK); else GetObject(hDigital[i], sizeof(BITMAP), &d_bitmap); } } void unload_digital_bitmap() { int i; for(i = 0; i < 10; i++) { DeleteObject( hDigital[i] ); } }