📄 helloworld.c
字号:
/*-----------------------------------------------------------------------------------------------------------
HelloWorld.c
------------------------------------------------------------------------------------------------------------*/
#include <windows.h>
#include <winbase.h>
#include"resource.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
HANDLE hThread;
DWORD ProcessID;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWorld") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
HMENU hMenu;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hMenu=LoadMenu(hInstance,szAppName );
hwnd = CreateWindow (
szAppName,
TEXT ("Hello World!"),
WS_OVERLAPPEDWINDOW
|WS_HSCROLL|WS_VSCROLL,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
hMenu,
hInstance,
NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
//回调函数1
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
DWORD ThreadID;
DWORD id;
HDC hDCT;
DWORD pid;
switch (message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_BEGIN:
PROCESS_INFORMATION pi;
STARTUPINFO si;
si.cb=sizeof(si);
si.lpReserved=NULL;
si.lpDesktop=NULL;
si.lpTitle=NULL;
si.cbReserved2=0;
si.lpReserved2=NULL;
si.dwFlags=STARTF_USEPOSITION|STARTF_USESIZE;
si.dwX=100;
si.dwY=100;
si.dwXSize=320;
si.dwYSize=240;
CreateProcess("c:\\marktam\\examples\\hello.exe",NULL,NULL,NULL,FALSE,0,NULL,"C:\\WINNT",&si,&pi);
ProcessID=pi.dwProcessId;
return 0;
break;
}
case WM_CHAR:
DEBUG_EVENT debug_event;
int ret;
ret=DebugActiveProcess(ProcessID);
while(WaitForDebugEvent(&debug_event,INFINITE)&&
ContinueDebugEvent(debug_event,dwProcessId,debug_event.dwThreadId,
DBG_CONTINUE)&&
debug_event.dwDebugEventCode!=EXCEPTION_DEBUG_EVENT);
while(WaitForDebugEvent(&debug_event,INFINITE)&&
ContinueDebugEvent(debug_event,dwProcessId,debug_event.dwThreadId,
DBG_CONTINUE)&&
debug_event.dwDebugEventCode!=EXCEPTION_DEBUG_EVENT);
if(debug_event.dwDebugEventCode==EXCEPTION_DEBUG_EVENT){
char strAddress[64];
if(debug_event.u.Exception.ExceptionRecord.ExceptionCode==EXCEPTION_INT_DIVIDE_BY_ZERO){
sprintf(strAddress,"在地址0x%08x处发生了零做除数的异常!",debug_event.u.Exception.ExceptionRecord.ExceptionAddress);
MessageBox(NULL,strAddress,"Exception!",MB_OK);
}
}
pid=debug_event.dwProcessId;
if(pid==ProcessID)
{
HANDLE hProcess;
hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,pid);
TerminateProcess(hProcess,0);
}
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
break;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -