孙鑫MFC视频第一课的例子窗口不显示
#include<windows.h>//#include<iostream>//#include<cstdlib>#include<stdio.h>LRESULTCAL...
#include<windows.h>
//#include<iostream>
//#include<cstdlib>
#include<stdio.h>
LRESULT CALLBACK WinPanProc(
HWND hwnd,
UINT umsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
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=WinPanProc;
wndcls.lpszClassName="PanXin";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("PanXin","YES!!!",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL); //变化CW_DEFAULT
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam; //变化
}
LRESULT CALLBACK WinPanProc(
HWND hwnd,
UINT umsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(umsg)
{
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"PanXin Win",strlen("PanXin Win"));
EndPaint(hwnd,&ps);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"clicked","click",0);
HDC dc;
dc=GetDC(hwnd);
TextOut(dc,0,50,"Again",strlen("Again"));
ReleaseDC(hwnd,dc);
break;
case WM_CHAR:
char szchar[20];
sprintf(szchar,"char is %d",wParam);
MessageBox(hwnd,szchar,"Char",0);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"tui chu ma ?","Exit",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hwnd,umsg,wParam,lParam);
}
return 0;
}
我这个代码在进程里看得到,但是不会弹出窗口。为什么?谢谢大家 展开
//#include<iostream>
//#include<cstdlib>
#include<stdio.h>
LRESULT CALLBACK WinPanProc(
HWND hwnd,
UINT umsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
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=WinPanProc;
wndcls.lpszClassName="PanXin";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("PanXin","YES!!!",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL); //变化CW_DEFAULT
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam; //变化
}
LRESULT CALLBACK WinPanProc(
HWND hwnd,
UINT umsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(umsg)
{
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"PanXin Win",strlen("PanXin Win"));
EndPaint(hwnd,&ps);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"clicked","click",0);
HDC dc;
dc=GetDC(hwnd);
TextOut(dc,0,50,"Again",strlen("Again"));
ReleaseDC(hwnd,dc);
break;
case WM_CHAR:
char szchar[20];
sprintf(szchar,"char is %d",wParam);
MessageBox(hwnd,szchar,"Char",0);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"tui chu ma ?","Exit",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hwnd,umsg,wParam,lParam);
}
return 0;
}
我这个代码在进程里看得到,但是不会弹出窗口。为什么?谢谢大家 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询