appleyuchi
所念皆山海
2015-09-20 15:39
采纳率: 100%
浏览 1.6k
已采纳

无warning无error,但不知为何没有输出的代码,求指点~

#include
HINSTANCE hInst;
HINSTANCE hInstance;
MSG msg;
char lpszClassName[]="window_class";
char* ShowText;
//TCHAR *ShowText;

//声明函数原型
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//窗口函数
void OnLButtonDown(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
void OnPaint (HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
void OnDestroy (HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);

//声明窗口类
class CFrameWnd
{
public:
HWND hWnd;
public:
int RegisterWindow();
void Create(LPCTSTR lpClassName,LPCTSTR lpWindowName);
void ShowWindow(int nCmdShow);
void UpdateWindow();
};

//窗口类成员函数的实现
int CFrameWnd::RegisterWindow()
{
WNDCLASS wc;
wc.style=0;
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=lpszClassName;
return RegisterClass(&wc);
}

void CFrameWnd::Create(LPCTSTR lpszClassName,LPCTSTR lpWindowName)
{
RegisterWindow();
hInst=hInstance;
hWnd=CreateWindow(lpszClassName,lpWindowName,WS_OVERLAPPEDWINDOW,200,200,200,200,NULL,NULL,hInstance,NULL);
}

void CFrameWnd::ShowWindow(int nCmdShow)
{
::ShowWindow(hWnd,nCmdShow);
}

void CFrameWnd::UpdateWindow()
{
::UpdateWindow(hWnd);
}

//声明应用程序类

class CWinApp
{
public:
CFrameWnd *m_pMainWnd;
public:
BOOL InitInstance(int nCmdShow);
int Run();
~CWinApp();
};

//应用程序类成员函数的实现
BOOL CWinApp::InitInstance(int nCmdShow)
{
m_pMainWnd=new CFrameWnd;
m_pMainWnd->Create(NULL,"封装的Windows程序");
m_pMainWnd->ShowWindow(nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}

int CWinApp::Run()
{
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

CWinApp::~CWinApp(){delete m_pMainWnd;}

//程序员定义的WinApp对象theApp-------------------------------------------------------------------
CWinApp theApp;

//主函数-----------------------------------------------------------------------
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hprevInstance,LPSTR lpCmdLine,int nCmdShow)
{
int ResultCode=-1;
theApp.InitInstance(nCmdShow);
return ResultCode=theApp.Run();

}

//窗口函数的实现
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
case WM_LBUTTONDOWN:
OnLButtonDown(hWnd,message,wParam,lParam);
break;

case WM_PAINT:
    OnPaint(hWnd,message,wParam,lParam);
    break;

case WM_DESTROY:
    OnDestroy(hWnd,message,wParam,lParam);
    break;

default:
    return DefWindowProc(hWnd,message,wParam,lParam);

}
return 0;

}

void OnLButtonDown(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
ShowText="Hello!";
InvalidateRect(hWnd,NULL,1);
}

void OnPaint(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,50,50,ShowText,6);
EndPaint(hWnd,&ps);
}

void OnDestroy(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PostQuitMessage(0);
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • lm_whales
    lm_whales 2015-09-20 15:53
    已采纳

    ShowText 没有初始化,它是外部变量,被初始化为0
    也就是NULL指针
    所以没显示任何东西
    改成 TCHAR ShowText[]="123456";
    显示 123456

    点赞 评论
  • devmiao
    devmiao 2015-09-20 15:40

    编译下,打开输出窗口,看看有没有报错。

    点赞 评论

相关推荐