# Include <windows. h> lresult callback wndproc (hwnd, uint, wparam, lparam); int winapi winmain (hinstance, hinstance hprevinstance, pstr szcmdline, int icmdshow) {static tchar szappname [] = text ("hexc1c"); MSG; hwnd; wndclass. style = cs_hredraw | cs_vredraw; wndclass. lpfnwndproc = wndproc; wndclass. cbclsextra = 0; // required wndclass when registering your own dialog box. cbwndextra = dlgw.wextra; wndclass. hinstance = hins Tance; wndclass. hicon = loadicon (hinstance, szappname); wndclass. hcursor = loadcursor (null, idc_arrow); wndclass. hbrbackground = (hbrush) (color_btnface + 1); wndclass. lpszmenuname = NULL; wndclass. lpszclassname = szappname; If (! Registerclass (& wndclass) {MessageBox (null, text ("this program requires Windows NT! "), Szappname, mb_iconerror); Return 0;} hwnd = createdialog (hinstance, szappname, 0, null); showwindow (hwnd, icmdshow); While (getmessage (& MSG, null, 0, 0) {translatemessage (& MSG); dispatchmessage (& MSG);} return MSG. wparam;} void shownumber (hwnd, uint inumber) {tchar szbuffer [20]; wsprintf (szbuffer, text ("% x"), inumber ); // What does vk_escape mean by setdlgitemtext (hwnd, vk_escape, szbuffer);} DWORD calcit (uint ifirstnum, int ioperata Tion, uint inum) {Switch (ioperatation) {Case '=': Return inum; Case '+': Return ifirstnum + inum; Case '-': Return ifirstnum-inum; case '*': Return ifirstnum * inum; Case '&': Return ifirstnum & inum; Case '|': Return ifirstnum | inum; Case '^': Return ifirstnum ^ inum; case '<': Return ifirstnum <inum; Case '>': Return ifirstnum> inum; Case '/': Return inum? Ifirstnum/inum: maxdword; Case '%': Return inum? Ifirstnum % inum: maxdword; default: Return 0 ;}} lresult callback wndproc (hwnd, uint message, wparam, lparam) {static bool bnewnumber = true; static int ioperation = '; static uint inumber, ifirstnum; hwnd hbutton; Switch (Message) {// many of the following do not add break, which is executed in sequence, note that the order cannot be changed //////////////////////////////////// //////////// when you press the next button, three messages wm_keydown, wm_char, wm_keyup // The system does not process the wm_keydown message when the pressed message is not left-direction. Wm_char message ///////////////////////////////////// /// // case wm_keydown: // If you press the left arrow key of the keyboard, it is equivalent to vb_back, minus the last if (wparam! = Vk_left) break; wparam = vk_back; // All characters are first converted to uppercase using charupper to write case wm_char: // determine whether to press enter if (wparam = (wparam) charupper (tchar *) wparam) = vk_return) wparam = '; // you can press the keyboard to determine which one is used, to achieve the corresponding animation effect // if there is no corresponding, the warning if (hbutton = getdlgitem (hwnd, wparam) {sendmessage (hbutton, bm_setstate, 1, 0) is issued ); sleep (100); sendmessage (hbutton, bm_setstate,);} else {messagebeep (0); break ;} // The above keyboard buttons will pass hwnd to the following // The following is the implementation of case wm_command: // set focus setfocus (hwn D); // If (loword (wparam) = vk_back) // The hexadecimal value is divided by 16 shownumber (hwnd, inumber/= 16 ); // equals processing else if (loword (wparam) = vk_escape) shownumber (hwnd, inumber = 0 ); // determine whether the number is else if (isxdigit (loword (wparam) {// determine the number of digits if (bnewnumber) {ifirstnum = inumber; inumber = 0 ;} bnewnumber = false; // only perform 4-bit processing? If (inumber <= maxdword> 4) shownumber (hwnd, inumber = 16 * inumber + wparam-(isdigit (wparam )? '0': 'A'-10); elsemessagebeep (0);} else {// if the second number is entered, calcit is called to calculate // If no, the following is the set flag, the read operator if (! Bnewnumber) shownumber (hwnd, inumber = calcit (ifirstnum, ioperation, inumber); bnewnumber = true; ioperation = loword (wparam);} return 0; Case wm_destroy: postquitmessage (0); Return 0;} return defwindowproc (hwnd, message, wparam, lparam );}
The dialog box is called directly in winmain for the first time. This method will be frequently used in the future and will be frequently used in the future.
Now, we have done this. The other thing today is to create a small program to test whether the three cameras we arrived yesterday can work at the same time, image processing ~~~~.
I recently learned about the windows program and used Windows APIs to implement it. I don't need to use the tedious MFC anymore. I still like the code that I can control myself.