Windows API 9-9 multiplication table [To be continued]

Source: Internet
Author: User

Degree of understanding: so far, I have found some places where I can add logic code, but I am not very familiar with some statements, such as wprintf and TextOut functions, therefore, only the result of the multiplication table can be output to the display screen. I also found a lot of instructions on the Internet, but it did not solve my problem. Let's share the code first. Whatever the case, the first thing I made with Windows APIs has been listed. Haha ...... Solve this problem in the future ...... The Windows API code is as follows: [cpp]/* HELLOWIN. C -- Displays (Display) * 9-9 multiplication table * in client area Display 9-9 multiplication table */# include <windows. h> // # pragma comment (lib, "WINMM. LIB ") lresult callback WndProc (HWND, UINT, WPARAM, LPARAM); // UINT indicates unsigned int. this is the declaration of the window process int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR sz1_line, int iCmdShow) // PSTR is a pointer to a non-wide string {static TCHAR szAppname [] = TEXT ("HELLOWIN"); HWND hwnd; MSG msg; // message structure WNDCLASS wndclass; // window class structure wndclass. style = CS_HREDRAW | CS_VREDRAW; wndclass. lpfnWndProc = WndProc; // is this a reference of WndProc? Wndclass. cbClsExtra = 0; wndclass. cbWndExtra = 0; wndclass. hInstance = hInstance; // instance handle wndclass. hIcon = LoadIcon (NULL, IDI_APPLICATION); // set the target wndclass. hCursor = LoadCursor (NULL, IDC_ARROW); // predefined wndclass pointer. hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); // specify the system color wndclass with a white paint brush. lpszMenuName = NULL; // name of the menu window class wndclass. lpszClassName = szAppname; // if (! RegisterClass (& wndclass) {MessageBox (NULL, TEXT ("what is this"), szAppname, MB_ICONERROR); return 0;} hwnd = CreateWindow (szAppname, // hwnd is the handle, szappname is the name of the window class TEXT ("jiujiu multiplication table"), // The window title WS_OVERLAPPEDWINDOW, // The window style (window format) CW_USEDEFAULT, // The initial x coordinate CW_USEDEFAULT, // initial y coordinate CW_USEDEFAULT, // initial x direction dimension CW_USEDEFAULT, // initial y direction dimension NULL, // parent window handle NULL, // Window menu handle hInstance, // program instance handle NULL); // create the ShowWindow (hwnd, iCmdSh) parameter Ow); UpdateWindow (hwnd); while (GetMessage (& msg, NULL, 0, 0) // message loop {TranslateMessage (& msg); DispatchMessage (& msg );} return msg. wParam;} lresult callback WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {HDC hdc; PAINTSTRUCT ps; // draw structure RECT rect; // static int cxChar, cxCaps, cyChar; int iLength; TCHAR szBuffer [50]; TEXTMETRIC tm; int I, j, a [10] [10]; for (j = 1; J <10; j ++) {for (I = 1; I <= j; I ++) {a [I] [j] = I * j ;}} switch (message) {case WM_CREATE: hdc = GetDC (hwnd); GetTextMetrics (hdc, & tm); cxChar = tm. tmAveCharWidth; cyChar = tm. tmHeight + tm. tmExternalLeading; cxCaps = (tm. tmPitchAndFamily & 1? 3: 2) * cxChar/2; ReleaseDC (hwnd, hdc); return 0; case WM_PAINT: hdc = BeginPaint (hwnd, & ps); for (j = 1; j <10; j ++) {for (I = 1; I <= j; I ++) {iLength = wsprintf (szBuffer, TEXT ("% I "), a [I] [j]); TextOut (hdc, cxCaps * 4 * I, cyChar * j * 3, szBuffer, iLength) ;}} EndPaint (hwnd, & ps ); return 0; case WM_DESTROY: PostQuitMessage (0); return 0;} return DefWindowProc (hwnd, message, wParam, lParam);} running result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.