在网上找的程度例子代码,是关于钩子的应用的。下面的是主程序,主要工作是创建一个对话框,对话框类型是(DLGPROC)ProcMain。
我的疑问是int WINAPI WinMain()是个什么类型的程序?我用VC6创建的MFC AppWizard(exe)和Win32 Console Application程序生成的入口函数都不是这个类型。
第二个问题是int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)的参数是怎么来的?不用初始化就直接创建的时候声明吗?
请高手赐教。 例子如下:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, (DLGPROC)ProcMain, 0);
return 0;
}
我的疑问是int WINAPI WinMain()是个什么类型的程序?我用VC6创建的MFC AppWizard(exe)和Win32 Console Application程序生成的入口函数都不是这个类型。
第二个问题是int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)的参数是怎么来的?不用初始化就直接创建的时候声明吗?
请高手赐教。 例子如下:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, (DLGPROC)ProcMain, 0);
return 0;
}
建议lz看下 windows程序设计的前面几章
Win32 Console Application的入口函数应该是WinMain阿
例如
#pragma comment(linker, "/ENTRY:EntryPoint")
将入口函数改为了EntryPoint
void EntryPoint()
{
.......
}使用WinMain之类的函数会做一些初始化和一些扫尾的工作
#include<windows.h>
#include<stdio.h>LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wnd;
wnd.cbClsExtra=0;
wnd.cbWndExtra=0;
wnd.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wnd.hCursor=LoadCursor(NULL,IDC_ARROW);
wnd.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wnd.hInstance=hInstance;
wnd.lpfnWndProc=WindowProc;
wnd.lpszClassName="wang";
wnd.lpszMenuName=NULL;
wnd.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wnd); HWND hwnd;
hwnd=CreateWindow("wang","第一个win32程序",WS_OVERLAPPEDWINDOW
,20,20,600,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG Msg;
while(GetMessage(&Msg,NULL,0,0))//必须为空,代表主线程
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hdc;
switch(uMsg)
{
case WM_CHAR:
char c[20];
sprintf(c,"char is %d",wParam);
MessageBox(hwnd,c,"WM_CHAR",0);
break;
case WM_PAINT:
PAINTSTRUCT paint;
hdc=BeginPaint(hwnd,&paint);
TextOut(hdc,100,100,"第一个win32程序",strlen("第一个win32程序"));
EndPaint(hwnd,&paint);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click","WM_LBUTTONDOWN",0);
hdc=GetDC(hwnd);
TextOut(hdc,0,10,"第一个win32程序",strlen("第一个win32程序"));
ReleaseDC(hwnd,hdc);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否退出应用程序?","WM_CLOSE",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}