孙鑫VC++视频问题
#include<windows.h>#include<stdio.h>LRESULTCALLBACKWinSunProc(HWNDhwnd,//handletowind...
# 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
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[10];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"金",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"Mouse Clicked","金",0);
HDC hDC;
hDC=GetDC(hwnd);
TextOut(hDC,0,50,"I love you!",strlen("I love you!"));
ReleaseDC(hwnd,hDC);
break;
case WM_PAINT:
PAINTSTRUCT ps;
HDC Hdc;
Hdc=BeginPaint(hwnd,&ps);
TextOut(Hdc,0,0,"Fuck the world!",strlen("Fuck the world!"));
EndPaint(hwnd,&ps);
break;
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;
}
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.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="jinyang";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("jinyang","阿里巴巴",WS_OVERLAPPEDWINDOW ,
0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_NORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
问题1:为什么程序中使用了strlen函数 却没有引入 <string.h>头文件?
问题2:我运行这段代码在退出程序的时候窗口销毁了,但是进程中程序还运行着,不清楚是什么原因,望高手指点。 展开
# 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
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[10];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"金",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"Mouse Clicked","金",0);
HDC hDC;
hDC=GetDC(hwnd);
TextOut(hDC,0,50,"I love you!",strlen("I love you!"));
ReleaseDC(hwnd,hDC);
break;
case WM_PAINT:
PAINTSTRUCT ps;
HDC Hdc;
Hdc=BeginPaint(hwnd,&ps);
TextOut(Hdc,0,0,"Fuck the world!",strlen("Fuck the world!"));
EndPaint(hwnd,&ps);
break;
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;
}
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.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="jinyang";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("jinyang","阿里巴巴",WS_OVERLAPPEDWINDOW ,
0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_NORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
问题1:为什么程序中使用了strlen函数 却没有引入 <string.h>头文件?
问题2:我运行这段代码在退出程序的时候窗口销毁了,但是进程中程序还运行着,不清楚是什么原因,望高手指点。 展开
3个回答
展开全部
因为你先用了DestroyWindow(hwnd);销毁窗口,然后才用PostQuitMessage(0); 退出程序,所以窗口销毁了,进程还存在,改变一下顺序就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
窗口只是一个显示在屏幕上的,与进程的运行没有必然的联系,他是先销毁窗口,进程再退出。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询