下面的程序不出窗口,在进程里有WinMain进程解决方案
下面的程序不出窗口,在进程里有WinMain进程
下面的程序不出窗口,在进程里有WinMain进程,怎么回事,哪位帮帮忙
#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WinSunProc(
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, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbClsExtra=0;
wndcls.lpfnWndProc=WinSunProc;
wndcls.hInstance=hInstance;
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.lpszMenuName=NULL;
wndcls.lpszClassName="zhangxiang";
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("zhangxiang","tuying",WS_OVERLAPPEDWINDOW,0,0,600,500,
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 WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"cao",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","hai cao",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,50,50,"你爷爷的",strlen("你爷爷的"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDc;
PAINTSTRUCT ps;
hDc=BeginPaint(hwnd,&ps);
TextOut(hDc,0,0,"计算机",strlen("计算机"));
EndPaint(hwnd,&ps);
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的退出?","草",MB_YESNO))
{
DestroyWindow(hwnd);
};
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
------解决方案--------------------
if (!RegisterClass (&wndcls))
{
MessageBox (NULL, TEXT ("ERROR!"),
"test", MB_ICONERROR) ;
return 0 ;
}
下次检查一下注册窗口。
下面的程序不出窗口,在进程里有WinMain进程,怎么回事,哪位帮帮忙
#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WinSunProc(
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, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbClsExtra=0;
wndcls.lpfnWndProc=WinSunProc;
wndcls.hInstance=hInstance;
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.lpszMenuName=NULL;
wndcls.lpszClassName="zhangxiang";
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("zhangxiang","tuying",WS_OVERLAPPEDWINDOW,0,0,600,500,
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 WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"cao",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","hai cao",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,50,50,"你爷爷的",strlen("你爷爷的"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDc;
PAINTSTRUCT ps;
hDc=BeginPaint(hwnd,&ps);
TextOut(hDc,0,0,"计算机",strlen("计算机"));
EndPaint(hwnd,&ps);
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的退出?","草",MB_YESNO))
{
DestroyWindow(hwnd);
};
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
------解决方案--------------------
if (!RegisterClass (&wndcls))
{
MessageBox (NULL, TEXT ("ERROR!"),
"test", MB_ICONERROR) ;
return 0 ;
}
下次检查一下注册窗口。