双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

VC内存栈溢出_求解

cqclark cqclark 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <Windows.h>
#include <stdio.h>
HWND g_hWnd;

HRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

bool initWin(HINSTANCE hInstance, LPCTSTR pClassName, LPCTSTR pAppName)
{
WNDCLASS wc;
wc.cbClsExtra = 4;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = 0;
wc.hIcon = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.lpszClassName = pClassName;
wc.lpszMenuName = 0;
wc.style = CS_HREDRAW|CS_VREDRAW;

if (!RegisterClass(&wc))
{
return false;
}

g_hWnd = CreateWindow(pClassName, pAppName, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);

if (!g_hWnd)
{
return false;
}

ShowWindow(g_hWnd, SW_SHOW);
UpdateWindow(g_hWnd);
return true;
}


HRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0);
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}


int CALLBACK WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
LPCTSTR pClassName = TEXT("WinMsgClass");
LPCTSTR pAppName = TEXT("WinMsgApp");
initWin(hInstance, pClassName, pAppName);

int a = 100;
SetClassLong(g_hWnd, 0L, a);

int b = GetClassLong(g_hWnd, 0);

TCHAR buf[9] = {0};
int size = sizeof("CLS: %d"); //运行后,当点击了对话按钮后,点击窗口关闭按钮时出错。程序回弹出中断程序对话框
swprintf_s(buf, sizeof(buf), TEXT("CLS: %d"), b);

::MessageBox(0, buf, 0, 0);

MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
cqclark
VC/MFC 16,550 成员 421,605 内容