调试闪退了。。。
本帖最后由 freeparty 于 2015-5-18 13:08 编辑#include <Windows.h>
#include <tchar.h>
#include <string>
#include <strsafe.h>
using namespace std;
LRESULT CALLBACK WndProc(HWND Hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
const TCHAR szWindowClass[] = L"窗口";
const TCHAR szWindowTite[] = L"标题";
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPTSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wcex.lpszClassName = szWindowClass;
RegisterClassEx(&wcex);
HWND hWnd = CreateWindow(
szWindowClass,
szWindowTite,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
int i;
PAINTSTRUCT ps;
size_t iT;
TCHAR szBuffer;
TEXTMETRIC tm;
static int cxChar, cyChar;
switch (msg)
{
case WM_CREATE:
hdc = GetDC(hWnd);
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC(hWnd, hdc);
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
case WM_PAINT:
{
HDC hdc = BeginPaint(hWnd, &ps);
for (i = 0; i < 10; i++)
{
StringCchPrintf(szBuffer, 12, TEXT("%d:%s"), i + 1, TEXT("heheda"));
StringCchLength(szBuffer, 12, &iT);
TextOut(hdc, cxChar, i* cyChar, szBuffer, iT);
}
EndPaint(hWnd, &ps);
return 0;
}
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
}
这个调试怎么闪退了呢,看着个甲鱼老师视频上面代码一样的啊。。郁闷了
case WM_CREATE:
少了return 0 零度C 发表于 2015-5-16 16:30
case WM_CREATE:
少了return 0
哈,还真是这样,谢谢啦 abc75727 发表于 2015-5-16 19:28
哈,还真是这样,谢谢啦
加油哦。。坚持到最后就不难了 零度C 发表于 2015-5-16 21:00
加油哦。。坚持到最后就不难了
哈哈,谢谢鼓励 没有返回值
页:
[1]