c++ 一个简单的windows程序 显示不出窗口
代码如下:#include<windows.h>#include<stdio.h>LRESULTCALLBACKWinSunProc(HWNDhwnd,UINTuMsg,...
代码如下:
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wndcls;
wndcls.cbClsExtra = 0; // 类额外附件数
wndcls.cbWndExtra = 0; // 窗口额外附加数
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // 背静
wndcls.hCursor = LoadCursor(NULL,IDC_CROSS); // 光标
wndcls.hIcon = LoadIcon(NULL,IDI_ERROR); // 图标
wndcls.hInstance = hInstance; // 应用程序实例号
wndcls.lpfnWndProc = WinSunProc; // 窗口过程函数
wndcls.lpszClassName = (LPCWSTR)"WEIXIN"; // 类名
wndcls.lpszMenuName = NULL; // 菜单名
wndcls.style = CS_HREDRAW | CS_VREDRAW; // 类型
RegisterClass(&wndcls); // 注册窗口类
HWND hwnd; // 定义句柄
hwnd = CreateWindow((LPCWSTR)"sdfatet",(LPCWSTR)"xintetwet",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);//创建窗口
ShowWindow(hwnd,SW_SHOWDEFAULT); // 显示窗口
UpdateWindow(hwnd); // 更新窗口
MSG msg;
while (GetMessage(&msg,NULL,0,0)) // 消息循环
{
TranslateMessage(&msg); //
DispatchMessage(&msg); //
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_CHAR:
{
char szChar[20];
sprintf_s(szChar,"123%d",wParam);
MessageBox(hwnd,(LPCWSTR)szChar,(LPCWSTR)"weixin",0);
}
break;
case WM_LBUTTONDOWN:
{
MessageBox(hwnd,(LPCWSTR)"321",(LPCWSTR)"weixin",0);
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc,0,50,(LPCWSTR)"125215",strlen("2323236"));
ReleaseDC(hwnd,hdc);
}
break;
case WM_PAINT: //窗口重绘
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd,&ps);
TextOut(hdc,0,50,(LPCWSTR)"125215",strlen("2323236"));
EndPaint(hwnd,&ps);
}
break;
case WM_CLOSE:
{
if (IDYES==MessageBox(hwnd,(LPCWSTR)"是否真的结束?",(LPCWSTR)"xieaf",MB_YESNO))
{
DestroyWindow(hwnd);//销毁窗口
}
}
break;
case WM_DESTROY:
{
PostQuitMessage(0); // 程序退出
}
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
代码到 消息循环这一行 断点就无效了 按f10或f11 都会释放断点
程序在进程中可以查看到
但是刷新不出程序的界面 不知道为什么 求解~ 展开
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wndcls;
wndcls.cbClsExtra = 0; // 类额外附件数
wndcls.cbWndExtra = 0; // 窗口额外附加数
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // 背静
wndcls.hCursor = LoadCursor(NULL,IDC_CROSS); // 光标
wndcls.hIcon = LoadIcon(NULL,IDI_ERROR); // 图标
wndcls.hInstance = hInstance; // 应用程序实例号
wndcls.lpfnWndProc = WinSunProc; // 窗口过程函数
wndcls.lpszClassName = (LPCWSTR)"WEIXIN"; // 类名
wndcls.lpszMenuName = NULL; // 菜单名
wndcls.style = CS_HREDRAW | CS_VREDRAW; // 类型
RegisterClass(&wndcls); // 注册窗口类
HWND hwnd; // 定义句柄
hwnd = CreateWindow((LPCWSTR)"sdfatet",(LPCWSTR)"xintetwet",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);//创建窗口
ShowWindow(hwnd,SW_SHOWDEFAULT); // 显示窗口
UpdateWindow(hwnd); // 更新窗口
MSG msg;
while (GetMessage(&msg,NULL,0,0)) // 消息循环
{
TranslateMessage(&msg); //
DispatchMessage(&msg); //
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_CHAR:
{
char szChar[20];
sprintf_s(szChar,"123%d",wParam);
MessageBox(hwnd,(LPCWSTR)szChar,(LPCWSTR)"weixin",0);
}
break;
case WM_LBUTTONDOWN:
{
MessageBox(hwnd,(LPCWSTR)"321",(LPCWSTR)"weixin",0);
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc,0,50,(LPCWSTR)"125215",strlen("2323236"));
ReleaseDC(hwnd,hdc);
}
break;
case WM_PAINT: //窗口重绘
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd,&ps);
TextOut(hdc,0,50,(LPCWSTR)"125215",strlen("2323236"));
EndPaint(hwnd,&ps);
}
break;
case WM_CLOSE:
{
if (IDYES==MessageBox(hwnd,(LPCWSTR)"是否真的结束?",(LPCWSTR)"xieaf",MB_YESNO))
{
DestroyWindow(hwnd);//销毁窗口
}
}
break;
case WM_DESTROY:
{
PostQuitMessage(0); // 程序退出
}
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
代码到 消息循环这一行 断点就无效了 按f10或f11 都会释放断点
程序在进程中可以查看到
但是刷新不出程序的界面 不知道为什么 求解~ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询