32-bit assembler in Windows C code-Chapter 4

Source: Internet
Author: User

The compiling environment is VC ++ 6.0.

 

(1) first Window Function

FirstWindow. c# Include <windows. h> </p> <p> lresult callback ProcWinMain (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) <br/>{< br/> PAINTSTRUCT stPs; <br/> RECTstRect; <br/> HDChDc; </p> <p> switch (uMsg) <br/>{< br/> case WM_PAINT: <br/> hDc = BeginPaint (hWnd, & stPs); <br/> GetClientRect (hWnd, & stRect); <br/> DrawText (hDc, TEXT ("Win32 Programing, simple and Powerful "),-1, & stRect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); <br/> EndPaint (hWnd, & stPs); <br/> return 0; </p> <p> case WM_CLOSE: <br/> DestroyWindow (hWnd); <br/> PostQuitMessage (0); <br/> return 0; <br/>}< br/> return DefWindowProc (hWnd, uMsg, wParam, lParam); <br/>}</p> <p> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) <br/>{< br/> WNDCLASSEXstWndCls; <br/> msstmsg; <br/> HWNDhWnd; </p> <p> RtlZeroMemory (& stWndCls, sizeof (stWndCls); <br/> stWndCls. hCursor = LoadCursor (NULL, IDC_ARROW); <br/> stWndCls. hIcon = LoadIcon (NULL, IDI_APPLICATION); <br/> stWndCls. hIconSm = LoadIcon (NULL, IDI_APPLICATION); <br/> stWndCls. cbWndExtra = 0; <br/> stWndCls. cbClsExtra = 0; <br/> stWndCls. hInstance = hInstance; <br/> stWndCls. cbSize = sizeof (WNDCLASSEX); <br/> stWndCls. style = CS_HREDRAW | CS_VREDRAW; <br/> stWndCls. lpfnWndProc = ProcWinMain; <br/> stWndCls. hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); <br/> stWndCls. lpszClassName = TEXT ("MyClass"); <br/> stWndCls. lpszMenuName = NULL; </p> <p> RegisterClassEx (& stWndCls); </p> <p> hWnd = createjavaswex (WS_EX_CLIENTEDGE, TEXT ("MyClass "), TEXT ("My First Window"), <br/> WS_OVERLAPPEDWINDOW, 100,100,600,400, NULL, NULL, hInstance, NULL); <br/> createmediawex (0, TEXT ("Button"), TEXT ("& OK"), WS_CHILD | WS_VISIBLE, 10, 10, 65, 22, hWnd, (HMENU) 1, hInstance, NULL ); <br/> ShowWindow (hWnd, SW_SHOWNORMAL); <br/> UpdateWindow (hWnd); </p> <p> while (GetMessage (& stMsg, NULL, 0, 0) <br/>{< br/> TranslateMessage (& stMsg); <br/> DispatchMessage (& stMsg); <br/>}< br/> return stMsg. wParam; <br/>}

 

(2) Communication between windows

// The Receive. c code of the message sending and receiving program between Windows adds variable definitions in the FirstWindow. c code ProcWinMain function:

TCHAR buffer [512]; <br/> TCHAR szFmt [] = TEXT ("Received WM_SETTEXT message/nparam: % 08x/ntext: % s ");

 

// Add the following code after processing the WM_PAINT message code segment:

Case WM_SETTEXT: <br/> wsprintf (buffer, szFmt, lParam, lParam); </p> <p> MessageBox (NULL, buffer, TEXT ("Success! "), MB_ OK | MB_ICONINFORMATION); <br/> return 0; </p> <p>

 

// Sending function Send. c code:

# Include <windows. h> </p> <p> HWND hWnd; <br/> TCHAR szBuffer [256]; </p> <p> const TCHAR szCaption [] = TEXT ("SendMessage"); <br/> const TCHAR szStart [] = TEXT ("Press OK start SendMessage, param: % 08x "); <br/> const TCHAR szReturn [] = TEXT (" SendMessage returned! "); <Br/> const TCHAR szDestClass [] = TEXT (" MyClass "); <br/> const TCHAR szText [] = TEXT ("Text send to other windows "); <br/> const TCHAR szNotFound [] = TEXT ("Receive Message Window not found"); </p> <p> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR using line, int iCmdShow) <br/>{< br/> if (hWnd = FindWindow (szDestClass, NULL ))! = NULL) <br/>{< br/> wsprintf (szBuffer, szStart, szText); <br/> MessageBox (NULL, szBuffer, szCaption, MB_ OK ); <br/> SendMessage (hWnd, WM_SETTEXT, 0, (LPARAM) szText); <br/> MessageBox (NULL, szReturn, szCaption, MB_ OK ); <br/>}< br/> else <br/> MessageBox (NULL, szNotFound, szCaption, MB_ OK); <br/> return 0; <br/>}</p> <p>

 

(3) data transmission between windows

// Replace the case: WM_SETTEXT section in the received Code Receive. c In (2):

Case WM_COPYDATA: <br/> wsprintf (buffer, szFmt, (COPYDATASTRUCT *) lParam)-> lpData, (COPYDATASTRUCT *) lParam)-> lpData ); <br/> MessageBox (NULL, buffer, TEXT ("Success! "), MB_ OK | MB_ICONINFORMATION); <br/> return 0; </p> <p>

 

// Change the WinMain in the Send. c file in (2):

Int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR CmdLine, int iCmdShow) <br/>{< br/> COPYDATASTRUCT stCDS; <br/> stCDS. cbData = sizeof (szText); <br/> stCDS. dwData = 0; <br/> stCDS. lpData = szText; <br/> if (hWnd = FindWindow (szDestClass, NULL ))! = NULL) <br/>{< br/> wsprintf (szBuffer, szStart, szText); <br/> MessageBox (NULL, szBuffer, szCaption, MB_ OK ); <br/> // SendMessage (hWnd, WM_SETTEXT, 0, (LPARAM) szText); <br/> SendMessage (hWnd, WM_COPYDATA, 0, (LPARAM) & stCDS ); <br/> MessageBox (NULL, szReturn, szCaption, MB_ OK); <br/>}< br/> else <br/> MessageBox (NULL, szNotFound, szCaption, MB_ OK ); <br/> return 0; <br/>}

 

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.