c的:- #include <windows.h>
- int APIENTRY WinMain(HINSTANCE hinstExe, HINSTANCE, PSTR pszCmdLine, int nCmdShow)
- {
- char cmdLine[] = "calc.exe";
- STARTUPINFO si = {sizeof(STARTUPINFO)};
- PROCESS_INFORMATION pi = {0};
- if(!CreateProcess(NULL, cmdLine, NULL, NULL, false, 0, NULL, NULL, &si, &pi))
- return -1;
- Sleep(300);
- RECT rc = {sizeof(RECT)};
- HWND hwnd = FindWindow(NULL, "计算器");
- if(NULL == hwnd)
- return -1;
-
- if(!GetWindowRect(hwnd, &rc))
- return -1;
-
- int cx = GetSystemMetrics(SM_CXSCREEN);
- int cy = GetSystemMetrics(SM_CYSCREEN);
- cx = (cx - rc.right + rc.left) / 2;
- cy = (cy - rc.bottom + rc.top) / 2;
- si.dwX = cx;
- si.dwY = cy;
- si.dwXSize = rc.right - rc.left;
- si.dwYSize = rc.bottom - rc.top;
- SetWindowPos(hwnd, HWND_TOPMOST, si.dwX, si.dwY, si.dwXSize, si.dwYSize, SWP_SHOWWINDOW);
- return 0;
- }
复制代码- .386
- .model flat, stdcall
- option casemap:none
- include windows.inc
- include user32.inc
- include kernel32.inc
- includelib user32.lib
- includelib kernel32.lib
- .data?
- rect RECT <>
- hwnd HWND ?
- showx dword ?
- showy dword ?
- xsize dword ?
- ysize dword ?
- .data
- szName byte ';calc';, 0
- szApp byte ';计算器';, 0
- .code
- start:
- invoke WinExec, offset szName, 0
- invoke FindWindow, NULL, offset szApp
- MOV [hwnd], EAX
- invoke GetWindowRect, EAX, offset rect
- invoke GetSystemMetrics, SM_CXSCREEN
- SUB EAX, rect.right
- ADD EAX, rect.left
- SAR EAX, 1
- MOV [showx], EAX
- invoke GetSystemMetrics, SM_CYSCREEN
- SUB EAX, rect.bottom
- ADD EAX, rect.top
- SAR EAX, 1
- MOV [showy], EAX
- MOV EAX, rect.right
- SUB EAX, rect.left
- MOV [xsize], EAX
- MOV EAX, rect.bottom
- SUB EAX, rect.top
- MOV [ysize], EAX
- invoke SetWindowPos, hwnd, HWND_TOPMOST, showx, showy, xsize, ysize, SWP_SHOWWINDOW
- ret
- end start
复制代码 |