自己独立完成的,一运行CPU就100%, 不知道是为什么......
#include
<
windows.h
>
TCHAR szAppName[ 10 ] = " MyApiWin " ;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitalInstance(HINSTANCE hInstance,HWND hwnd, int nShowCmd);
BOOL MyRegisterClass(HINSTANCE hInstance);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
HWND hwnd = NULL;
MSG msg;
MyRegisterClass(hInstance);
InitalInstance(hInstance,hwnd,nShowCmd);
while (GetMessage( & msg,NULL, 0 , 0 ))
{
DispatchMessageW( & msg);
TranslateMessage( & msg);
}
return msg.wParam;
}
BOOL MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS cla;
cla.cbClsExtra = 0 ;
cla.cbWndExtra = 0 ;
cla.hbrBackground = HBRUSH(GetStockObject(WHITE_BRUSH));
cla.hCursor = LoadCursor(NULL,IDC_ARROW);
cla.hIcon = LoadIcon(NULL,IDI_APPLICATION);
cla.hInstance = hInstance;
cla.lpfnWndProc = WndProc;
cla.lpszClassName = szAppName;
cla.lpszMenuName = NULL;
cla.lpszMenuName = NULL;
cla.style = CS_HREDRAW | CS_VREDRAW;
if ( ! RegisterClass( & cla)){
MessageBox(NULL,TEXT( " Register Window Failed " ),szAppName,MB_ICONERROR);
return false ;}
else {
return true ;}
}
BOOL InitalInstance(HINSTANCE hInstance,HWND hwnd, int nShowCmd)
{
hwnd = CreateWindow(szAppName,
TEXT( " Hook API Demo " ),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
if ( ! hwnd)
return false ;
else
return true ;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
return 0 ;
case WM_PAINT:
return 0 ;
case WM_DESTROY:
PostQuitMessage( 0 );
return 0 ;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
TCHAR szAppName[ 10 ] = " MyApiWin " ;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitalInstance(HINSTANCE hInstance,HWND hwnd, int nShowCmd);
BOOL MyRegisterClass(HINSTANCE hInstance);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
HWND hwnd = NULL;
MSG msg;
MyRegisterClass(hInstance);
InitalInstance(hInstance,hwnd,nShowCmd);
while (GetMessage( & msg,NULL, 0 , 0 ))
{
DispatchMessageW( & msg);
TranslateMessage( & msg);
}
return msg.wParam;
}
BOOL MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS cla;
cla.cbClsExtra = 0 ;
cla.cbWndExtra = 0 ;
cla.hbrBackground = HBRUSH(GetStockObject(WHITE_BRUSH));
cla.hCursor = LoadCursor(NULL,IDC_ARROW);
cla.hIcon = LoadIcon(NULL,IDI_APPLICATION);
cla.hInstance = hInstance;
cla.lpfnWndProc = WndProc;
cla.lpszClassName = szAppName;
cla.lpszMenuName = NULL;
cla.lpszMenuName = NULL;
cla.style = CS_HREDRAW | CS_VREDRAW;
if ( ! RegisterClass( & cla)){
MessageBox(NULL,TEXT( " Register Window Failed " ),szAppName,MB_ICONERROR);
return false ;}
else {
return true ;}
}
BOOL InitalInstance(HINSTANCE hInstance,HWND hwnd, int nShowCmd)
{
hwnd = CreateWindow(szAppName,
TEXT( " Hook API Demo " ),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
if ( ! hwnd)
return false ;
else
return true ;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
return 0 ;
case WM_PAINT:
return 0 ;
case WM_DESTROY:
PostQuitMessage( 0 );
return 0 ;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}