windows程序中WinMain和响应函数myproc哪部分形成进程?
windows程序中WinMain和响应函数myproc,都是回调函数,就我们看来似乎是脱节的两部分。是我想知道编译装载后,哪一部分形成进程?还是WinMain和响应函数myproc各自生成1个进程,一共2个进程?
#include <windows.h>
#include "resource.h"
#include <stdio.h>
int x,y;
LRESULT CALLBACK myproc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CLOSE:
if(IDOK==MessageBox(hwnd,"你是真的要退出吗?","系统提示",MB_OKCANCEL|MB_ICONINFORMATION))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
case WM_CHAR:
{
char buf[100];
sprintf(buf,"%d",wParam);
MessageBox(hwnd,buf,"show",MB_OK);
break;
}
case WM_MOUSEMOVE:
{//这里和上面的情况用大括号一是为了防止buf的重复定义,二是为解决类似int x=LOWORD(lParam);的定义编译器糊涂报错。
HDC hdc=GetDC(hwnd);
char buf[100];
sprintf(buf,"x=%d,y=%d",x,y);
SetTextColor(hdc,RGB(255,255,255));
TextOut(hdc,0,0,buf,strlen(buf));
//InvalidateRect(hwnd,NULL,true);
//PostMessage(hwnd,WM_PAINT,0,0);
//SendMessage(hwnd,WM_PAINT,0,0);
x=LOWORD(lParam);
y=HIWORD(lParam);
memset(buf,0,100);
sprintf(buf,"x=%d,y=%d",x,y);
SetTextColor(hdc,RGB(0,0,0));
TextOut(hdc,0,0,buf,strlen(buf));
ReleaseDC(hwnd,hdc);
break;
}
}
return 1;
}
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=NULL;
wndclass.cbWndExtra=NULL;
wndclass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wndclass.hCursor=LoadCursor(hInstance,MAKEINTRESOURCE(IDC_POINTER));
wndclass.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=myproc;
wndclass.lpszClassName="mywnd";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW;
RegisterClass(&wndclass);
HWND hwnd=CreateWindow("mywnd","window test",WS_OVERLAPPEDWINDOW,100,100,400,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOW);
MSG msg;
while(GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 1;
}
[解决办法]
就‘进程’而言 应该是 一个 进程,否则 就会 跨进程,麻烦大了。
[解决办法]
进程的话肯定就一个,进程是一个当前状态和一组相关的系统资源所描述的活动单元,即使是线程的话按照楼主的代码也是一个,只有winmain形成线程,回调的那一部分可以看成一个普通函数而已。
[解决办法]
那个应该是WinDBG~