鱼C论坛

 找回密码
 立即注册
查看: 1826|回复: 12

[吹水] Virtual Casio 窗口部分大致完成,先发出来看看

[复制链接]
发表于 2023-8-30 15:58:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
rt.
由于windows没有透明按钮的组件,所以我就用判断鼠标点击位置的方法来判断点到的是哪一个按钮。
采集这些按钮的坐标位置真是让人吐血...目前就采集了8个,效果还算可以。
实现效果:点击图片中按钮所在位置时会弹出窗口,表示感应到点击~(上面8个按钮有效)

下一步就是做显示屏的控件了,要求根据按钮的点击作出相应的反馈。这个等我借到了卡西欧再说。
最近需要主打加减乘除乘方等常规按键的响应~可能会用到Python,因为不想手打高精度~

附件:

virtual-casio.zip (472.87 KB, 下载次数: 2)

我的代码:
  1. #include <windows.h>
  2. #include <cstdio>  // sprintf

  3. void test_draw_line(HDC hdc, int x1, int y1, int x2, int y2, COLORREF color) ;
  4. void test_draw_rect(HDC hdc,int x1,int y1,int x2,int y2,COLORREF color);
  5. WINBOOL clicked_in_region(int x1,int y1,int x2,int y2,int Pos_x,int Pos_y);
  6. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  7. void show_click_pt(int Pos_x,int Pos_y);

  8. void test_draw_line(HDC hdc, int x1, int y1, int x2, int y2, COLORREF color)
  9. {
  10.     HPEN hPen = CreatePen(PS_SOLID, 1, color);  // 创建画笔对象
  11.     HPEN hOldPen = static_cast<HPEN>(SelectObject(hdc, hPen));  // 选择画笔对象

  12.     MoveToEx(hdc, x1, y1, NULL);
  13.     LineTo(hdc, x2, y2);

  14.     SelectObject(hdc, hOldPen);  // 恢复原来的画笔对象
  15.     DeleteObject(hPen);  // 删除创建的画笔对象
  16. }

  17. void test_draw_rect(HDC hdc,int x1,int y1,int x2,int y2,COLORREF color)
  18. {
  19.         test_draw_line(hdc,x1,y1,x2,y1,color);
  20.         test_draw_line(hdc,x1,y2,x2,y2,color);
  21.         test_draw_line(hdc,x1,y1,x1,y2,color);
  22.         test_draw_line(hdc,x2,y1,x2,y2,color);
  23. }

  24. void show_click_pt(int Pos_x,int Pos_y)
  25. {
  26.         char str[114]={'\0'};
  27.         sprintf(str,"click_pos:( %d , %d )",Pos_x,Pos_y);
  28.         MessageBoxA(NULL,str,TEXT("notice"),MB_OK);
  29. }

  30. /*Button_names     x1     y1     x2       y2
  31. * Btn_shift        54     249    78       273            
  32. * Btn_alpha       92      250    116      272            
  33. * Btn_menu        237     252    260      271            
  34. * Btn_on           277     249   301      272         
  35. * Btn_up  Btn_down  Btn_left  Btn_right
  36.    Btn_up          162    247    190      269           
  37.    Btn_down      164      289    192      306            
  38.    Btn_left       133     264    153       291            
  39.    Btn_reght     202      265    222       293                                                
  40. * Btn_optn                                   
  41. * Btn_calc                                   
  42. * Btn_integ                                   
  43. * Btn_var_x                                   
  44. * Btn_frac                                   
  45. * Btn_sqrt                                   
  46. * Btn_sqr                                   
  47. * Btn_pow                                   
  48. * Btn_log                                   
  49. * Btn_ln                                   
  50. * Btn_minus                                   
  51. * Btn_dms                                   
  52. * Btn_recip                                   
  53. * Btn_sin                                   
  54. * Btn_cos                                   
  55. * Btn_tan                                   
  56. * Btn_sto                                   
  57. * Btn_eng                                   
  58. * Btn_lbrack                                   
  59. * Btn_rbrack                                   
  60. * Btn_s_d                                   
  61. * Btn_mplus                                   
  62. * Btn_num_0 ... Btn_num_9                                   
  63. * Btn_dot                                   
  64. * Btn_10pow_x                                   
  65. * Btn_plus  Btn_minus  Btn_multi  Btn_div  Btn_equal                                   
  66. * Btn_del                                   
  67. * Btn_ac                                   
  68. */



  69. WINBOOL clicked_in_region(int x1,int y1,int x2,int y2,int Pos_x,int Pos_y)//after message WM_LBUTTONDOWN
  70. {
  71.         return PtInRegion(CreateRectRgn(x1,y1,x2,y2),Pos_x,Pos_y);
  72. }

  73. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  74. {
  75.     WNDCLASSA wc = {0}; // 使用 WNDCLASSA 结构体
  76.     wc.style = CS_HREDRAW | CS_VREDRAW;
  77.     wc.lpfnWndProc = WindowProc;
  78.     wc.hInstance = hInstance;
  79.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  80.     wc.lpszClassName = "MyWindowClass"; // 使用多字节字符串

  81.     RegisterClassA(&wc); // 使用 RegisterClassA 函数

  82.     HWND hwnd = CreateWindowA("MyWindowClass", "Virtual CASIO fx-991CN X", WS_OVERLAPPEDWINDOW,
  83.                               CW_USEDEFAULT, CW_USEDEFAULT, 380, 700, NULL, NULL, hInstance, NULL);
  84.                               
  85.     HWND Btn_num_0=CreateWindow(
  86.                 "BUTTON"," 0 ",
  87.                 WS_CHILD|WS_VISIBLE,
  88.                 100,100,100,30,
  89.                 hwnd,
  90.                 (HMENU)1,
  91.                 hInstance,
  92.                 NULL);
  93.    
  94.    

  95.     ShowWindow(hwnd, nCmdShow);
  96.     UpdateWindow(hwnd);

  97.     MSG msg;
  98.     while (GetMessage(&msg, NULL, 0, 0))
  99.     {
  100.         TranslateMessage(&msg);
  101.         DispatchMessage(&msg);
  102.     }

  103.     return (int)msg.wParam;
  104. }

  105. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  106. {
  107.     switch (uMsg)
  108.     {
  109.             case WM_COMMAND:
  110.                     if(lParam and HIWORD(wParam)==BN_CLICKED)
  111.                     {
  112.                             if(HWND(lParam)==GetDlgItem(hwnd,1))
  113.                             {
  114.                                     MessageBox(hwnd,"button_num_0 pressed","notice",MB_OK);
  115.                                 }
  116.                         }
  117.                         return 0;
  118.         case WM_PAINT:
  119.         {
  120.             PAINTSTRUCT ps;
  121.             HDC hdc = BeginPaint(hwnd, &ps);

  122.                         // 贴图
  123.             HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "casio_image.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  124.             if (hBitmap)
  125.             {
  126.                 BITMAP bitmap;
  127.                 GetObject(hBitmap, sizeof(BITMAP), &bitmap);
  128.                 int bmpWidth = bitmap.bmWidth;
  129.                 int bmpHeight = bitmap.bmHeight;

  130.                 HDC hdcMem = CreateCompatibleDC(hdc);
  131.                 HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBitmap);

  132.                 BitBlt(hdc, 0, 0, bmpWidth, bmpHeight, hdcMem, 0, 0, SRCCOPY);

  133.                 SelectObject(hdcMem, hOldBitmap);
  134.                 DeleteDC(hdcMem);
  135.                 DeleteObject(hBitmap);
  136.             }
  137.             
  138.             //test_draw_line/rect
  139.             test_draw_rect(hdc,40,50,90,100,RGB(255,0,0));
  140.             
  141.             
  142.             test_draw_line(hdc,11,45,14,19,RGB(255,0,0));
  143.             test_draw_line(hdc,234,121,485,321,RGB(0,0,255));

  144.             EndPaint(hwnd, &ps);
  145.             return 0;
  146.         }
  147.         case WM_DESTROY:
  148.         {
  149.             PostQuitMessage(0);
  150.             return 0;
  151.         }
  152.         case WM_LBUTTONDOWN:
  153.         {
  154.                 int xp=LOWORD(lParam),yp=HIWORD(lParam);
  155.                 //show_click_pt(Pos_x,Pos_y);
  156.                 /*if(clicked_in_region(10,10,200,200,Pos_x,Pos_y))
  157.                 {
  158.                         MessageBoxA(hwnd,TEXT("transparent"),TEXT("lalala caution"),MB_OK);
  159.                         }*/
  160.                         if(clicked_in_region(54,249,78,273,xp,yp))
  161.                         {
  162.                                 MessageBoxA(hwnd,TEXT("shift"),TEXT("clicked"),MB_OK);
  163.                         }
  164.                         else if(clicked_in_region(92,250,116,272,xp,yp))
  165.                         {
  166.                                 MessageBoxA(hwnd,TEXT("alpha"),TEXT("clicked"),MB_OK);
  167.                         }
  168.                         else if(clicked_in_region(237,252,260,271,xp,yp))
  169.                         {
  170.                                 MessageBoxA(hwnd,TEXT("menu"),TEXT("clicked"),MB_OK);
  171.                         }
  172.                         else if(clicked_in_region(277,249,301,272,xp,yp))
  173.                         {
  174.                                 MessageBoxA(hwnd,TEXT("on"),TEXT("clicked"),MB_OK);
  175.                         }
  176.                         else if(clicked_in_region(162,247,190,269,xp,yp))
  177.                         {
  178.                                 MessageBoxA(hwnd,TEXT("up"),TEXT("clicked"),MB_OK);
  179.                         }
  180.                         else if(clicked_in_region(164,289,192,306,xp,yp))
  181.                         {
  182.                                 MessageBoxA(hwnd,TEXT("down"),TEXT("clicked"),MB_OK);
  183.                         }
  184.                         else if(clicked_in_region(133,264,153,291,xp,yp))
  185.                         {
  186.                                 MessageBoxA(hwnd,TEXT("left"),TEXT("clicked"),MB_OK);
  187.                         }
  188.                         else if(clicked_in_region(202,265,222,293,xp,yp))
  189.                         {
  190.                                 MessageBoxA(hwnd,TEXT("right"),TEXT("clicked"),MB_OK);
  191.                         }
  192.                         return 0;
  193.                 }
  194.         default:
  195.             return DefWindowProc(hwnd, uMsg, wParam, lParam);
  196.     }
  197. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-8-30 15:59:39 | 显示全部楼层
编译记得加上 -mwindows
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-8-30 21:25:54 From FishC Mobile | 显示全部楼层
有时间看看
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-8-30 22:55:22 | 显示全部楼层
代码改进
对于上半部分黑色按钮均有反馈

  1. #include <windows.h>
  2. #include <cstdio>  // sprintf
  3. //#include "casio_buttons.h"
  4. #define id_Btn_shift 0x00
  5. #define id_Btn_alpha 0x01
  6. #define id_Btn_menu 0x02
  7. #define id_Btn_on 0x03
  8. #define id_Btn_up 0x04
  9. #define id_Btn_down 0x05
  10. #define id_Btn_left 0x06
  11. #define id_Btn_right 0x07
  12. #define id_Btn_optn 0x08
  13. #define id_Btn_calc 0x09
  14. #define id_Btn_integ 0x0a
  15. #define id_Btn_var_x 0x0b
  16. #define id_Btn_frac 0x0c
  17. #define id_Btn_sqrt 0x0d
  18. #define id_Btn_sqr 0x0e
  19. #define id_Btn_pow 0x0f
  20. #define id_Btn_log 0x10
  21. #define id_Btn_ln 0x11
  22. #define id_Btn_minus 0x12
  23. #define id_Btn_dms 0x13
  24. #define id_Btn_recip 0x14
  25. #define id_Btn_sin 0x15
  26. #define id_Btn_cos 0x16
  27. #define id_Btn_tan 0x17
  28. #define id_Btn_sto 0x18
  29. #define id_Btn_eng 0x19
  30. #define id_Btn_lbrack 0x1a
  31. #define id_Btn_rbrack 0x1b
  32. #define id_Btn_s_d 0x1c
  33. #define id_Btn_mplus 0x1d
  34. #define id_Btn_num_0 0x1e
  35. #define id_Btn_num_1 0x1f
  36. #define id_Btn_num_2 0x20
  37. #define id_Btn_num_3 0x21
  38. #define id_Btn_num_4 0x22
  39. #define id_Btn_num_5 0x23
  40. #define id_Btn_num_6 0x24
  41. #define id_Btn_num_7 0x25
  42. #define id_Btn_num_8 0x26
  43. #define id_Btn_num_9 0x27
  44. #define id_Btn_dot 0x28
  45. #define id_Btn_10pow_x 0x29
  46. #define id_Btn_op_plus 0x2a
  47. #define id_Btn_op_minus 0x2b
  48. #define id_Btn_op_multi 0x2c
  49. #define id_Btn_op_div 0x2d
  50. #define id_Btn_op_equal 0x2e
  51. #define id_Btn_del 0x2f
  52. #define id_Btn_ac 0x30


  53. void test_draw_line(HDC hdc, int x1, int y1, int x2, int y2, COLORREF color) ;
  54. void test_draw_rect(HDC hdc,int x1,int y1,int x2,int y2,COLORREF color);
  55. WINBOOL clicked_in_region(int x1,int y1,int x2,int y2,int Pos_x,int Pos_y);
  56. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  57. void show_click_pt(int Pos_x,int Pos_y);
  58. int Btn_clicked_id(int Pos_x,int Pos_y);

  59. int Btn_clicked_id(int xp,int yp,HWND hwnd)
  60. {
  61.         if(clicked_in_region(54,249,78,273,xp,yp))
  62.         {
  63.                 MessageBoxA(hwnd,TEXT("shift"),TEXT("clicked"),MB_OK);
  64.                 return id_Btn_shift;
  65.         }
  66.         else if(clicked_in_region(92,250,116,272,xp,yp))
  67.         {
  68.                 MessageBoxA(hwnd,TEXT("alpha"),TEXT("clicked"),MB_OK);
  69.                 return id_Btn_alpha;
  70.         }
  71.         else if(clicked_in_region(237,252,260,271,xp,yp))
  72.         {
  73.                 MessageBoxA(hwnd,TEXT("menu"),TEXT("clicked"),MB_OK);
  74.                 return id_Btn_menu;
  75.         }
  76.         else if(clicked_in_region(277,249,301,272,xp,yp))
  77.         {
  78.                 MessageBoxA(hwnd,TEXT("on"),TEXT("clicked"),MB_OK);
  79.                 return id_Btn_on;
  80.         }
  81.         else if(clicked_in_region(162,247,190,269,xp,yp))
  82.         {
  83.                 MessageBoxA(hwnd,TEXT("up"),TEXT("clicked"),MB_OK);
  84.                 return id_Btn_up;
  85.         }
  86.         else if(clicked_in_region(164,289,192,306,xp,yp))
  87.         {
  88.                 MessageBoxA(hwnd,TEXT("down"),TEXT("clicked"),MB_OK);
  89.                 return id_Btn_down;
  90.         }
  91.         else if(clicked_in_region(133,264,153,291,xp,yp))
  92.         {
  93.                 MessageBoxA(hwnd,TEXT("left"),TEXT("clicked"),MB_OK);
  94.                 return id_Btn_left;
  95.         }
  96.         else if(clicked_in_region(202,265,222,293,xp,yp))
  97.         {
  98.                 MessageBoxA(hwnd,TEXT("right"),TEXT("clicked"),MB_OK);
  99.                 return id_Btn_right;
  100.         }
  101.         else if(clicked_in_region(49,301,84,320,xp,yp))
  102.         {
  103.                 MessageBoxA(hwnd,TEXT("optn"),TEXT("clicked"),MB_OK);
  104.                 return id_Btn_optn;
  105.         }
  106.         else if(clicked_in_region(92,301,128,321,xp,yp))
  107.         {
  108.                 MessageBoxA(hwnd,TEXT("calc"),TEXT("clicked"),MB_OK);
  109.                 return id_Btn_calc;
  110.         }
  111.         else if(clicked_in_region(227,301,262,319,xp,yp))
  112.         {
  113.                 MessageBoxA(hwnd,TEXT("integ"),TEXT("clicked"),MB_OK);
  114.                 return id_Btn_integ;
  115.         }
  116.         else if(clicked_in_region(271,303,305,320,xp,yp))
  117.         {
  118.                 MessageBoxA(hwnd,TEXT("var_x"),TEXT("clicked"),MB_OK);
  119.                 return id_Btn_var_x;
  120.         }
  121.         else if(clicked_in_region(49,337,84,358,xp,yp))
  122.         {
  123.                 MessageBoxA(hwnd,TEXT("frac"),TEXT("clicked"),MB_OK);
  124.                 return id_Btn_frac;
  125.         }
  126.         else if(clicked_in_region(94,338,172,355,xp,yp))
  127.         {
  128.                 MessageBoxA(hwnd,TEXT("sqrt"),TEXT("clicked"),MB_OK);
  129.                 return id_Btn_sqrt;
  130.         }
  131.         else if(clicked_in_region(136,338,172,355,xp,yp))
  132.         {
  133.                 MessageBoxA(hwnd,TEXT("sqr"),TEXT("clicked"),MB_OK);
  134.                 return id_Btn_sqr;
  135.         }
  136.         else if(clicked_in_region(183,337,218,357,xp,yp))
  137.         {
  138.                 MessageBoxA(hwnd,TEXT("pow"),TEXT("clicked"),MB_OK);
  139.                 return id_Btn_pow;
  140.         }
  141.         else if(clicked_in_region(227,339,261,356,xp,yp))
  142.         {
  143.                 MessageBoxA(hwnd,TEXT("log"),TEXT("clicked"),MB_OK);
  144.                 return id_Btn_log;
  145.         }
  146.         else if(clicked_in_region(270,337,305,356,xp,yp))
  147.         {
  148.                 MessageBoxA(hwnd,TEXT("ln"),TEXT("clicked"),MB_OK);
  149.                 return id_Btn_ln;
  150.         }
  151.         else if(clicked_in_region(49,375,84,391,xp,yp))
  152.         {
  153.                 MessageBoxA(hwnd,TEXT("minus"),TEXT("clicked"),MB_OK);
  154.                 return id_Btn_minus;
  155.         }
  156.         else if(clicked_in_region(94,375,129,391,xp,yp))
  157.         {
  158.                 MessageBoxA(hwnd,TEXT("dms"),TEXT("clicked"),MB_OK);
  159.                 return id_Btn_dms;
  160.         }
  161.         else if(clicked_in_region(138,375,173,391,xp,yp))
  162.         {
  163.                 MessageBoxA(hwnd,TEXT("recip"),TEXT("clicked"),MB_OK);
  164.                 return id_Btn_recip;
  165.         }
  166.         else if(clicked_in_region(182,375,216,391,xp,yp))
  167.         {
  168.                 MessageBoxA(hwnd,TEXT("sin"),TEXT("clicked"),MB_OK);
  169.                 return id_Btn_sin;
  170.         }
  171.         else if(clicked_in_region(228,375,261,391,xp,yp))
  172.         {
  173.                 MessageBoxA(hwnd,TEXT("cos"),TEXT("clicked"),MB_OK);
  174.                 return id_Btn_cos;
  175.         }
  176.         else if(clicked_in_region(271,375,306,391,xp,yp))
  177.         {
  178.                 MessageBoxA(hwnd,TEXT("tan"),TEXT("clicked"),MB_OK);
  179.                 return id_Btn_tan;
  180.         }
  181.         else if(clicked_in_region(48,410,83,429,xp,yp))
  182.         {
  183.                 MessageBoxA(hwnd,TEXT("sto"),TEXT("clicked"),MB_OK);
  184.                 return id_Btn_sto;
  185.         }
  186.         else if(clicked_in_region(94,410,127,429,xp,yp))
  187.         {
  188.                 MessageBoxA(hwnd,TEXT("eng"),TEXT("clicked"),MB_OK);
  189.                 return id_Btn_eng;
  190.         }
  191.         else if(clicked_in_region(137,409,172,429,xp,yp))
  192.         {
  193.                 MessageBoxA(hwnd,TEXT("lbrack"),TEXT("clicked"),MB_OK);
  194.                 return id_Btn_lbrack;
  195.         }
  196.         else if(clicked_in_region(182,409,218,429,xp,yp))
  197.         {
  198.                 MessageBoxA(hwnd,TEXT("rbrack"),TEXT("clicked"),MB_OK);
  199.                 return id_Btn_rbrack;
  200.         }
  201.         else if(clicked_in_region(227,409,261,429,xp,yp))
  202.         {
  203.                 MessageBoxA(hwnd,TEXT("s_d"),TEXT("clicked"),MB_OK);
  204.                 return id_Btn_s_d;
  205.         }
  206.         else if(clicked_in_region(271,409,306,429,xp,yp))
  207.         {
  208.                 MessageBoxA(hwnd,TEXT("mplus"),TEXT("clicked"),MB_OK);
  209.                 return id_Btn_mplus;
  210.         }
  211.         return 0xff;
  212. }

  213. void test_draw_line(HDC hdc, int x1, int y1, int x2, int y2, COLORREF color)
  214. {
  215.     HPEN hPen = CreatePen(PS_SOLID, 1, color);  // 创建画笔对象
  216.     HPEN hOldPen = static_cast<HPEN>(SelectObject(hdc, hPen));  // 选择画笔对象

  217.     MoveToEx(hdc, x1, y1, NULL);
  218.     LineTo(hdc, x2, y2);

  219.     SelectObject(hdc, hOldPen);  // 恢复原来的画笔对象
  220.     DeleteObject(hPen);  // 删除创建的画笔对象
  221. }

  222. void test_draw_rect(HDC hdc,int x1,int y1,int x2,int y2,COLORREF color)
  223. {
  224.         test_draw_line(hdc,x1,y1,x2,y1,color);
  225.         test_draw_line(hdc,x1,y2,x2,y2,color);
  226.         test_draw_line(hdc,x1,y1,x1,y2,color);
  227.         test_draw_line(hdc,x2,y1,x2,y2,color);
  228. }

  229. void show_click_pt(int Pos_x,int Pos_y)
  230. {
  231.         char str[114]={'\0'};
  232.         sprintf(str,"click_pos:( %d , %d )",Pos_x,Pos_y);
  233.         MessageBoxA(NULL,str,TEXT("notice"),MB_OK);
  234. }

  235. WINBOOL clicked_in_region(int x1,int y1,int x2,int y2,int Pos_x,int Pos_y)//after message WM_LBUTTONDOWN
  236. {
  237.         return PtInRegion(CreateRectRgn(x1,y1,x2,y2),Pos_x,Pos_y);
  238. }

  239. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  240. {
  241.     WNDCLASSA wc = {0}; // 使用 WNDCLASSA 结构体
  242.     wc.style = CS_HREDRAW | CS_VREDRAW;
  243.     wc.lpfnWndProc = WindowProc;
  244.     wc.hInstance = hInstance;
  245.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  246.     wc.lpszClassName = "MyWindowClass"; // 使用多字节字符串

  247.     RegisterClassA(&wc); // 使用 RegisterClassA 函数

  248.     HWND hwnd = CreateWindowA("MyWindowClass", "Virtual CASIO fx-991CN X", WS_OVERLAPPEDWINDOW,
  249.                               CW_USEDEFAULT, CW_USEDEFAULT, 380, 700, NULL, NULL, hInstance, NULL);
  250.                               
  251.     HWND Btn_num_0=CreateWindow(
  252.                 "BUTTON"," 0 ",
  253.                 WS_CHILD|WS_VISIBLE,
  254.                 100,100,100,30,
  255.                 hwnd,
  256.                 (HMENU)1,
  257.                 hInstance,
  258.                 NULL);
  259.        
  260.        

  261.         ShowWindow(hwnd, nCmdShow);
  262.         UpdateWindow(hwnd);

  263.         MSG msg;
  264.         while (GetMessage(&msg, NULL, 0, 0))
  265.         {
  266.                 TranslateMessage(&msg);
  267.                 DispatchMessage(&msg);
  268.         }

  269.         return (int)msg.wParam;
  270. }

  271. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  272. {
  273.         switch (uMsg)
  274.         {
  275.                 case WM_COMMAND:
  276.                         if(lParam and HIWORD(wParam)==BN_CLICKED)
  277.                         {
  278.                                 if(HWND(lParam)==GetDlgItem(hwnd,1))
  279.                                 {
  280.                                         MessageBox(hwnd,"button_num_0 pressed","notice",MB_OK);
  281.                                 }
  282.                         }
  283.                         return 0;
  284.                 case WM_PAINT:
  285.                 {
  286.                         PAINTSTRUCT ps;
  287.                         HDC hdc = BeginPaint(hwnd, &ps);

  288.                         // 贴图
  289.                         HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "casio_image.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  290.                         if (hBitmap)
  291.                         {
  292.                                 BITMAP bitmap;
  293.                                 GetObject(hBitmap, sizeof(BITMAP), &bitmap);
  294.                 int bmpWidth = bitmap.bmWidth;
  295.                 int bmpHeight = bitmap.bmHeight;

  296.                 HDC hdcMem = CreateCompatibleDC(hdc);
  297.                 HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBitmap);

  298.                 BitBlt(hdc, 0, 0, bmpWidth, bmpHeight, hdcMem, 0, 0, SRCCOPY);

  299.                 SelectObject(hdcMem, hOldBitmap);
  300.                 DeleteDC(hdcMem);
  301.                 DeleteObject(hBitmap);
  302.             }
  303.             
  304.             //test_draw_line/rect
  305.             test_draw_rect(hdc,40,50,90,100,RGB(255,0,0));
  306.             
  307.             
  308.             test_draw_line(hdc,11,45,14,19,RGB(255,0,0));
  309.             test_draw_line(hdc,234,121,485,321,RGB(0,0,255));

  310.             EndPaint(hwnd, &ps);
  311.             return 0;
  312.         }
  313.         case WM_DESTROY:
  314.         {
  315.             PostQuitMessage(0);
  316.             return 0;
  317.         }
  318.         case WM_LBUTTONDOWN:
  319.         {
  320.                 int xp=LOWORD(lParam),yp=HIWORD(lParam);
  321.                 //show_click_pt(xp,yp);
  322.                 Btn_clicked_id(xp,yp,hwnd);
  323.                 /*if(clicked_in_region(10,10,200,200,Pos_x,Pos_y))
  324.                 {
  325.                         MessageBoxA(hwnd,TEXT("transparent"),TEXT("lalala caution"),MB_OK);
  326.                         }*/
  327.                         /*
  328.                         if(clicked_in_region(54,249,78,273,xp,yp))
  329.                         {
  330.                                 MessageBoxA(hwnd,TEXT("shift"),TEXT("clicked"),MB_OK);
  331.                         }
  332.                         else if(clicked_in_region(92,250,116,272,xp,yp))
  333.                         {
  334.                                 MessageBoxA(hwnd,TEXT("alpha"),TEXT("clicked"),MB_OK);
  335.                         }
  336.                         else if(clicked_in_region(237,252,260,271,xp,yp))
  337.                         {
  338.                                 MessageBoxA(hwnd,TEXT("menu"),TEXT("clicked"),MB_OK);
  339.                         }
  340.                         else if(clicked_in_region(277,249,301,272,xp,yp))
  341.                         {
  342.                                 MessageBoxA(hwnd,TEXT("on"),TEXT("clicked"),MB_OK);
  343.                         }
  344.                         else if(clicked_in_region(162,247,190,269,xp,yp))
  345.                         {
  346.                                 MessageBoxA(hwnd,TEXT("up"),TEXT("clicked"),MB_OK);
  347.                         }
  348.                         else if(clicked_in_region(164,289,192,306,xp,yp))
  349.                         {
  350.                                 MessageBoxA(hwnd,TEXT("down"),TEXT("clicked"),MB_OK);
  351.                         }
  352.                         else if(clicked_in_region(133,264,153,291,xp,yp))
  353.                         {
  354.                                 MessageBoxA(hwnd,TEXT("left"),TEXT("clicked"),MB_OK);
  355.                         }
  356.                         else if(clicked_in_region(202,265,222,293,xp,yp))
  357.                         {
  358.                                 MessageBoxA(hwnd,TEXT("right"),TEXT("clicked"),MB_OK);
  359.                         }
  360.                         */
  361.                         return 0;
  362.                 }
  363.         default:
  364.             return DefWindowProc(hwnd, uMsg, wParam, lParam);
  365.     }
  366. }
复制代码

评分

参与人数 1荣誉 +1 收起 理由
cjjJasonchen + 1

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-8-31 15:52:32 | 显示全部楼层
最新版窗口代码,窗口设计部分告一段落。
下一步就是做每个按钮对应的功能啦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-8-31 15:53:12 | 显示全部楼层
  1. #include <windows.h>
  2. #include <cstdio>  // sprintf
  3. #define id_Btn_shift 0x00
  4. #define id_Btn_alpha 0x01
  5. #define id_Btn_menu 0x02
  6. #define id_Btn_on 0x03
  7. #define id_Btn_up 0x04
  8. #define id_Btn_down 0x05
  9. #define id_Btn_left 0x06
  10. #define id_Btn_right 0x07
  11. #define id_Btn_optn 0x08
  12. #define id_Btn_calc 0x09
  13. #define id_Btn_integ 0x0a
  14. #define id_Btn_var_x 0x0b
  15. #define id_Btn_frac 0x0c
  16. #define id_Btn_sqrt 0x0d
  17. #define id_Btn_sqr 0x0e
  18. #define id_Btn_pow 0x0f
  19. #define id_Btn_log 0x10
  20. #define id_Btn_ln 0x11
  21. #define id_Btn_minus 0x12
  22. #define id_Btn_dms 0x13
  23. #define id_Btn_recip 0x14
  24. #define id_Btn_sin 0x15
  25. #define id_Btn_cos 0x16
  26. #define id_Btn_tan 0x17
  27. #define id_Btn_sto 0x18
  28. #define id_Btn_eng 0x19
  29. #define id_Btn_lbrack 0x1a
  30. #define id_Btn_rbrack 0x1b
  31. #define id_Btn_s_d 0x1c
  32. #define id_Btn_mplus 0x1d
  33. #define id_Btn_num_0 0x1e
  34. #define id_Btn_num_1 0x1f
  35. #define id_Btn_num_2 0x20
  36. #define id_Btn_num_3 0x21
  37. #define id_Btn_num_4 0x22
  38. #define id_Btn_num_5 0x23
  39. #define id_Btn_num_6 0x24
  40. #define id_Btn_num_7 0x25
  41. #define id_Btn_num_8 0x26
  42. #define id_Btn_num_9 0x27
  43. #define id_Btn_dot 0x28
  44. #define id_Btn_10pow_x 0x29
  45. #define id_Btn_op_plus 0x2a
  46. #define id_Btn_op_minus 0x2b
  47. #define id_Btn_op_multi 0x2c
  48. #define id_Btn_op_div 0x2d
  49. #define id_Btn_op_equal 0x2e
  50. #define id_Btn_del 0x2f
  51. #define id_Btn_ac 0x30
  52. #define id_Btn_ans 0x31


  53. void test_draw_line(HDC hdc, int x1, int y1, int x2, int y2, COLORREF color) ;
  54. void test_draw_rect(HDC hdc,int x1,int y1,int x2,int y2,COLORREF color);
  55. WINBOOL clicked_in_region(int x1,int y1,int x2,int y2,int Pos_x,int Pos_y);
  56. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  57. void show_click_pt(int Pos_x,int Pos_y);
  58. int Btn_clicked_id(int Pos_x,int Pos_y);

  59. int Btn_clicked_id(int xp,int yp,HWND hwnd)
  60. {
  61.         if(clicked_in_region(54,249,78,273,xp,yp))
  62.         {
  63.                 MessageBoxA(hwnd,TEXT("shift"),TEXT("clicked"),MB_OK);
  64.                 return id_Btn_shift;
  65.         }
  66.         else if(clicked_in_region(92,250,116,272,xp,yp))
  67.         {
  68.                 MessageBoxA(hwnd,TEXT("alpha"),TEXT("clicked"),MB_OK);
  69.                 return id_Btn_alpha;
  70.         }
  71.         else if(clicked_in_region(237,252,260,271,xp,yp))
  72.         {
  73.                 MessageBoxA(hwnd,TEXT("menu"),TEXT("clicked"),MB_OK);
  74.                 return id_Btn_menu;
  75.         }
  76.         else if(clicked_in_region(277,249,301,272,xp,yp))
  77.         {
  78.                 MessageBoxA(hwnd,TEXT("on"),TEXT("clicked"),MB_OK);
  79.                 return id_Btn_on;
  80.         }
  81.         else if(clicked_in_region(162,247,190,269,xp,yp))
  82.         {
  83.                 MessageBoxA(hwnd,TEXT("up"),TEXT("clicked"),MB_OK);
  84.                 return id_Btn_up;
  85.         }
  86.         else if(clicked_in_region(164,289,192,306,xp,yp))
  87.         {
  88.                 MessageBoxA(hwnd,TEXT("down"),TEXT("clicked"),MB_OK);
  89.                 return id_Btn_down;
  90.         }
  91.         else if(clicked_in_region(133,264,153,291,xp,yp))
  92.         {
  93.                 MessageBoxA(hwnd,TEXT("left"),TEXT("clicked"),MB_OK);
  94.                 return id_Btn_left;
  95.         }
  96.         else if(clicked_in_region(202,265,222,293,xp,yp))
  97.         {
  98.                 MessageBoxA(hwnd,TEXT("right"),TEXT("clicked"),MB_OK);
  99.                 return id_Btn_right;
  100.         }
  101.         else if(clicked_in_region(49,301,84,320,xp,yp))
  102.         {
  103.                 MessageBoxA(hwnd,TEXT("optn"),TEXT("clicked"),MB_OK);
  104.                 return id_Btn_optn;
  105.         }
  106.         else if(clicked_in_region(92,301,128,321,xp,yp))
  107.         {
  108.                 MessageBoxA(hwnd,TEXT("calc"),TEXT("clicked"),MB_OK);
  109.                 return id_Btn_calc;
  110.         }
  111.         else if(clicked_in_region(227,301,262,319,xp,yp))
  112.         {
  113.                 MessageBoxA(hwnd,TEXT("integ"),TEXT("clicked"),MB_OK);
  114.                 return id_Btn_integ;
  115.         }
  116.         else if(clicked_in_region(271,303,305,320,xp,yp))
  117.         {
  118.                 MessageBoxA(hwnd,TEXT("var_x"),TEXT("clicked"),MB_OK);
  119.                 return id_Btn_var_x;
  120.         }
  121.         else if(clicked_in_region(49,337,84,358,xp,yp))
  122.         {
  123.                 MessageBoxA(hwnd,TEXT("frac"),TEXT("clicked"),MB_OK);
  124.                 return id_Btn_frac;
  125.         }
  126.         else if(clicked_in_region(94,338,172,355,xp,yp))
  127.         {
  128.                 MessageBoxA(hwnd,TEXT("sqrt"),TEXT("clicked"),MB_OK);
  129.                 return id_Btn_sqrt;
  130.         }
  131.         else if(clicked_in_region(136,338,172,355,xp,yp))
  132.         {
  133.                 MessageBoxA(hwnd,TEXT("sqr"),TEXT("clicked"),MB_OK);
  134.                 return id_Btn_sqr;
  135.         }
  136.         else if(clicked_in_region(183,337,218,357,xp,yp))
  137.         {
  138.                 MessageBoxA(hwnd,TEXT("pow"),TEXT("clicked"),MB_OK);
  139.                 return id_Btn_pow;
  140.         }
  141.         else if(clicked_in_region(227,339,261,356,xp,yp))
  142.         {
  143.                 MessageBoxA(hwnd,TEXT("log"),TEXT("clicked"),MB_OK);
  144.                 return id_Btn_log;
  145.         }
  146.         else if(clicked_in_region(270,337,305,356,xp,yp))
  147.         {
  148.                 MessageBoxA(hwnd,TEXT("ln"),TEXT("clicked"),MB_OK);
  149.                 return id_Btn_ln;
  150.         }
  151.         else if(clicked_in_region(49,375,84,391,xp,yp))
  152.         {
  153.                 MessageBoxA(hwnd,TEXT("minus"),TEXT("clicked"),MB_OK);
  154.                 return id_Btn_minus;
  155.         }
  156.         else if(clicked_in_region(94,375,129,391,xp,yp))
  157.         {
  158.                 MessageBoxA(hwnd,TEXT("dms"),TEXT("clicked"),MB_OK);
  159.                 return id_Btn_dms;
  160.         }
  161.         else if(clicked_in_region(138,375,173,391,xp,yp))
  162.         {
  163.                 MessageBoxA(hwnd,TEXT("recip"),TEXT("clicked"),MB_OK);
  164.                 return id_Btn_recip;
  165.         }
  166.         else if(clicked_in_region(182,375,216,391,xp,yp))
  167.         {
  168.                 MessageBoxA(hwnd,TEXT("sin"),TEXT("clicked"),MB_OK);
  169.                 return id_Btn_sin;
  170.         }
  171.         else if(clicked_in_region(228,375,261,391,xp,yp))
  172.         {
  173.                 MessageBoxA(hwnd,TEXT("cos"),TEXT("clicked"),MB_OK);
  174.                 return id_Btn_cos;
  175.         }
  176.         else if(clicked_in_region(271,375,306,391,xp,yp))
  177.         {
  178.                 MessageBoxA(hwnd,TEXT("tan"),TEXT("clicked"),MB_OK);
  179.                 return id_Btn_tan;
  180.         }
  181.         else if(clicked_in_region(48,410,83,429,xp,yp))
  182.         {
  183.                 MessageBoxA(hwnd,TEXT("sto"),TEXT("clicked"),MB_OK);
  184.                 return id_Btn_sto;
  185.         }
  186.         else if(clicked_in_region(94,410,127,429,xp,yp))
  187.         {
  188.                 MessageBoxA(hwnd,TEXT("eng"),TEXT("clicked"),MB_OK);
  189.                 return id_Btn_eng;
  190.         }
  191.         else if(clicked_in_region(137,409,172,429,xp,yp))
  192.         {
  193.                 MessageBoxA(hwnd,TEXT("lbrack"),TEXT("clicked"),MB_OK);
  194.                 return id_Btn_lbrack;
  195.         }
  196.         else if(clicked_in_region(182,409,218,429,xp,yp))
  197.         {
  198.                 MessageBoxA(hwnd,TEXT("rbrack"),TEXT("clicked"),MB_OK);
  199.                 return id_Btn_rbrack;
  200.         }
  201.         else if(clicked_in_region(227,409,261,429,xp,yp))
  202.         {
  203.                 MessageBoxA(hwnd,TEXT("s_d"),TEXT("clicked"),MB_OK);
  204.                 return id_Btn_s_d;
  205.         }
  206.         else if(clicked_in_region(271,409,306,429,xp,yp))
  207.         {
  208.                 MessageBoxA(hwnd,TEXT("mplus"),TEXT("clicked"),MB_OK);
  209.                 return id_Btn_mplus;
  210.         }
  211.         else if(clicked_in_region(48,580,92,611,xp,yp))
  212.         {
  213.                 MessageBoxA(hwnd,TEXT("num_0"),TEXT("clicked"),MB_OK);
  214.                 return id_Btn_num_0;
  215.         }
  216.         else if(clicked_in_region(48,535,91,567,xp,yp))
  217.         {
  218.                 MessageBoxA(hwnd,TEXT("num_1"),TEXT("clicked"),MB_OK);
  219.                 return id_Btn_num_1;
  220.         }
  221.         else if(clicked_in_region(102,536,145,566,xp,yp))
  222.         {
  223.                 MessageBoxA(hwnd,TEXT("num_2"),TEXT("clicked"),MB_OK);
  224.                 return id_Btn_num_2;
  225.         }
  226.         else if(clicked_in_region(157,537,200,566,xp,yp))
  227.         {
  228.                 MessageBoxA(hwnd,TEXT("num_3"),TEXT("clicked"),MB_OK);
  229.                 return id_Btn_num_3;
  230.         }
  231.         else if(clicked_in_region(48,492,91,524,xp,yp))
  232.         {
  233.                 MessageBoxA(hwnd,TEXT("num_4"),TEXT("clicked"),MB_OK);
  234.                 return id_Btn_num_4;
  235.         }
  236.         else if(clicked_in_region(101,492,146,522,xp,yp))
  237.         {
  238.                 MessageBoxA(hwnd,TEXT("num_5"),TEXT("clicked"),MB_OK);
  239.                 return id_Btn_num_5;
  240.         }
  241.         else if(clicked_in_region(155,493,198,521,xp,yp))
  242.         {
  243.                 MessageBoxA(hwnd,TEXT("num_6"),TEXT("clicked"),MB_OK);
  244.                 return id_Btn_num_6;
  245.         }
  246.         else if(clicked_in_region(47,447,91,476,xp,yp))
  247.         {
  248.                 MessageBoxA(hwnd,TEXT("num_7"),TEXT("clicked"),MB_OK);
  249.                 return id_Btn_num_7;
  250.         }
  251.         else if(clicked_in_region(101,448,145,476,xp,yp))
  252.         {
  253.                 MessageBoxA(hwnd,TEXT("num_8"),TEXT("clicked"),MB_OK);
  254.                 return id_Btn_num_8;
  255.         }
  256.         else if(clicked_in_region(156,447,198,477,xp,yp))
  257.         {
  258.                 MessageBoxA(hwnd,TEXT("num_9"),TEXT("clicked"),MB_OK);
  259.                 return id_Btn_num_9;
  260.         }
  261.         else if(clicked_in_region(101,580,146,611,xp,yp))
  262.         {
  263.                 MessageBoxA(hwnd,TEXT("dot"),TEXT("clicked"),MB_OK);
  264.                 return id_Btn_dot;
  265.         }
  266.         else if(clicked_in_region(157,580,199,611,xp,yp))
  267.         {
  268.                 MessageBoxA(hwnd,TEXT("10pow_x"),TEXT("clicked"),MB_OK);
  269.                 return id_Btn_10pow_x;
  270.         }
  271.         else if(clicked_in_region(210,537,253,567,xp,yp))
  272.         {
  273.                 MessageBoxA(hwnd,TEXT("op_plus"),TEXT("clicked"),MB_OK);
  274.                 return id_Btn_op_plus;
  275.         }
  276.         else if(clicked_in_region(263,537,307,567,xp,yp))
  277.         {
  278.                 MessageBoxA(hwnd,TEXT("op_minus"),TEXT("clicked"),MB_OK);
  279.                 return id_Btn_op_minus;
  280.         }
  281.         else if(clicked_in_region(210,492,253,521,xp,yp))
  282.         {
  283.                 MessageBoxA(hwnd,TEXT("op_multi"),TEXT("clicked"),MB_OK);
  284.                 return id_Btn_op_multi;
  285.         }
  286.         else if(clicked_in_region(264,493,307,521,xp,yp))
  287.         {
  288.                 MessageBoxA(hwnd,TEXT("op_div"),TEXT("clicked"),MB_OK);
  289.                 return id_Btn_op_div;
  290.         }
  291.         else if(clicked_in_region(264,493,307,612,xp,yp))
  292.         {
  293.                 MessageBoxA(hwnd,TEXT("op_equal"),TEXT("clicked"),MB_OK);
  294.                 return id_Btn_op_equal;
  295.         }
  296.         else if(clicked_in_region(210,447,254,477,xp,yp))
  297.         {
  298.                 MessageBoxA(hwnd,TEXT("del"),TEXT("clicked"),MB_OK);
  299.                 return id_Btn_del;
  300.         }
  301.         else if(clicked_in_region(263,447,306,475,xp,yp))
  302.         {
  303.                 MessageBoxA(hwnd,TEXT("ac"),TEXT("clicked"),MB_OK);
  304.                 return id_Btn_ac;
  305.         }
  306.         else if(clicked_in_region(209,581,252,610,xp,yp))
  307.         {
  308.                 MessageBoxA(hwnd,TEXT("ans"),TEXT("clicked"),MB_OK);
  309.                 return id_Btn_ans;
  310.         }
  311.        
  312.         return 0xff;
  313. }

  314. void test_draw_line(HDC hdc, int x1, int y1, int x2, int y2, COLORREF color)
  315. {
  316.     HPEN hPen = CreatePen(PS_SOLID, 1, color);  // 创建画笔对象
  317.     HPEN hOldPen = static_cast<HPEN>(SelectObject(hdc, hPen));  // 选择画笔对象

  318.     MoveToEx(hdc, x1, y1, NULL);
  319.     LineTo(hdc, x2, y2);

  320.     SelectObject(hdc, hOldPen);  // 恢复原来的画笔对象
  321.     DeleteObject(hPen);  // 删除创建的画笔对象
  322. }

  323. void test_draw_rect(HDC hdc,int x1,int y1,int x2,int y2,COLORREF color)
  324. {
  325.         test_draw_line(hdc,x1,y1,x2,y1,color);
  326.         test_draw_line(hdc,x1,y2,x2,y2,color);
  327.         test_draw_line(hdc,x1,y1,x1,y2,color);
  328.         test_draw_line(hdc,x2,y1,x2,y2,color);
  329. }

  330. void show_click_pt(int Pos_x,int Pos_y)
  331. {
  332.         char str[114]={'\0'};
  333.         sprintf(str,"click_pos:( %d , %d )",Pos_x,Pos_y);
  334.         MessageBoxA(NULL,str,TEXT("notice"),MB_OK);
  335. }

  336. WINBOOL clicked_in_region(int x1,int y1,int x2,int y2,int Pos_x,int Pos_y)//after message WM_LBUTTONDOWN
  337. {
  338.         return PtInRegion(CreateRectRgn(x1,y1,x2,y2),Pos_x,Pos_y);
  339. }

  340. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  341. {
  342.     WNDCLASSA wc = {0}; // 使用 WNDCLASSA 结构体
  343.     wc.style = CS_HREDRAW | CS_VREDRAW;
  344.     wc.lpfnWndProc = WindowProc;
  345.     wc.hInstance = hInstance;
  346.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  347.     wc.lpszClassName = "MyWindowClass"; // 使用多字节字符串

  348.     RegisterClassA(&wc); // 使用 RegisterClassA 函数

  349.     HWND hwnd = CreateWindowA("MyWindowClass", "Virtual CASIO fx-991CN X", WS_OVERLAPPEDWINDOW,
  350.                               CW_USEDEFAULT, CW_USEDEFAULT, 380, 700, NULL, NULL, hInstance, NULL);
  351.                               
  352.     HWND Btn_num_0=CreateWindow(
  353.                 "BUTTON"," 0 ",
  354.                 WS_CHILD|WS_VISIBLE,
  355.                 100,100,100,30,
  356.                 hwnd,
  357.                 (HMENU)1,
  358.                 hInstance,
  359.                 NULL);
  360.        
  361.        

  362.         ShowWindow(hwnd, nCmdShow);
  363.         UpdateWindow(hwnd);

  364.         MSG msg;
  365.         while (GetMessage(&msg, NULL, 0, 0))
  366.         {
  367.                 TranslateMessage(&msg);
  368.                 DispatchMessage(&msg);
  369.         }

  370.         return (int)msg.wParam;
  371. }

  372. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  373. {
  374.         switch (uMsg)
  375.         {
  376.                 case WM_COMMAND:
  377.                         if(lParam and HIWORD(wParam)==BN_CLICKED)
  378.                         {
  379.                                 if(HWND(lParam)==GetDlgItem(hwnd,1))
  380.                                 {
  381.                                         MessageBox(hwnd,"button_num_0 pressed","notice",MB_OK);
  382.                                 }
  383.                         }
  384.                         return 0;
  385.                 case WM_PAINT:
  386.                 {
  387.                         PAINTSTRUCT ps;
  388.                         HDC hdc = BeginPaint(hwnd, &ps);

  389.                         // 贴图
  390.                         HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "casio_image.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  391.                         if (hBitmap)
  392.                         {
  393.                                 BITMAP bitmap;
  394.                                 GetObject(hBitmap, sizeof(BITMAP), &bitmap);
  395.                 int bmpWidth = bitmap.bmWidth;
  396.                 int bmpHeight = bitmap.bmHeight;

  397.                 HDC hdcMem = CreateCompatibleDC(hdc);
  398.                 HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBitmap);

  399.                 BitBlt(hdc, 0, 0, bmpWidth, bmpHeight, hdcMem, 0, 0, SRCCOPY);

  400.                 SelectObject(hdcMem, hOldBitmap);
  401.                 DeleteDC(hdcMem);
  402.                 DeleteObject(hBitmap);
  403.             }
  404.             
  405.             //test_draw_line/rect
  406.             test_draw_rect(hdc,40,50,90,100,RGB(255,0,0));
  407.             
  408.             
  409.             test_draw_line(hdc,11,45,14,19,RGB(255,0,0));
  410.             test_draw_line(hdc,234,121,485,321,RGB(0,0,255));

  411.             EndPaint(hwnd, &ps);
  412.             return 0;
  413.         }
  414.         case WM_DESTROY:
  415.         {
  416.             PostQuitMessage(0);
  417.             return 0;
  418.         }
  419.         case WM_LBUTTONDOWN:
  420.         {
  421.                 int xp=LOWORD(lParam),yp=HIWORD(lParam);
  422.                 //show_click_pt(xp,yp);
  423.                 Btn_clicked_id(xp,yp,hwnd);
  424.                         return 0;
  425.                 }
  426.         default:
  427.             return DefWindowProc(hwnd, uMsg, wParam, lParam);
  428.     }
  429. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-8-31 15:54:09 | 显示全部楼层
由于我采取的是位图,按钮做的是用像素点位置来判断,所以应该可移植性很强
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-8-31 17:04:16 | 显示全部楼层
这啥啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-8-31 17:05:01 | 显示全部楼层

一个窗口程序。是我的计划的一部分
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-8-31 17:26:48 | 显示全部楼层
我趣汇编?厉害啊!这么叼的怎么发在吹水
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-8-31 18:12:22 | 显示全部楼层
cjjJasonchen 发表于 2023-8-31 17:26
我趣汇编?厉害啊!这么叼的怎么发在吹水

?不是啊,是c++
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-8-31 20:06:55 | 显示全部楼层



除了scratch,其他在python玩家眼里全是汇编

笑死
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-8-31 21:27:38 | 显示全部楼层
cjjJasonchen 发表于 2023-8-31 20:06
除了scratch,其他在python玩家眼里全是汇编

笑死

6
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-30 21:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表