24,853
社区成员
发帖
与我相关
我的任务
分享#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define _WIN32_IE 0x0501
#define _RICHEDIT_VER 0x0200
#include <Windows.h>
#include <tchar.h>
#include <CommCtrl.h>
#pragma comment(lib,"comctl32.lib")
#define DEF_AppName _T("Hello World!")
#define DEF_ClassName _T("Hello World! - QPSOFT.COM")
LRESULT CALLBACK WndProc(HWND wndHandle, UINT msg, WPARAM wpa, LPARAM lpa);
int WINAPI _tWinMain(HINSTANCE inst, HINSTANCE /*prevInst*/, PTSTR /*cmdLine*/, int cmdShow)
{
INITCOMMONCONTROLSEX icc = {sizeof(INITCOMMONCONTROLSEX), ICC_WIN95_CLASSES};
::InitCommonControlsEx(&icc);
WNDCLASSEX wcex;
::ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = inst;
wcex.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
wcex.hIconSm = wcex.hIcon;
wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
wcex.lpszMenuName = NULL;
wcex.lpszClassName = DEF_ClassName;
if (!::RegisterClassEx(&wcex))
{
::MessageBox(NULL, _T("This program requires Windows NT!"), DEF_AppName, MB_ICONERROR);
return 0;
}
HWND wndHandle = ::CreateWindowEx(0, DEF_ClassName, DEF_AppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, inst, NULL);
::ShowWindow(wndHandle, cmdShow);
::UpdateWindow(wndHandle);
MSG msg;
while (int ret = ::GetMessage(&msg, NULL, 0, 0) != 0)
{
if (ret == -1) break; // handle the error and possibly exit
else
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
return static_cast<int>(msg.wParam);
}
LRESULT CALLBACK WndProc(HWND wndHandle, UINT msg, WPARAM wpa, LPARAM lpa)
{
PAINTSTRUCT ps;
HDC hdc;
switch (msg)
{
case WM_CREATE:
{
::MessageBox(wndHandle, _T("Welcome to QPSOFT.COM ...^_^"), DEF_AppName, MB_OK);
}
return 0;
case WM_PAINT:
{
hdc = ::BeginPaint(wndHandle, &ps);
RECT rc;
::GetClientRect(wndHandle, &rc);
::DrawText(hdc, DEF_AppName, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
::EndPaint(wndHandle, &ps);
}
return 0;
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
}
return ::DefWindowProc(wndHandle, msg, wpa, lpa);
} default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}