控制台下创建窗口和WinMain入口创建窗口简单程序
标签:
控制台创建窗口(同时有控制台窗口和新创建的窗口)(项目类型:控制台应用程序)#include "windows.h"
#include "TCHAR.h"
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE hInstance;
hInstance = GetModuleHandle(NULL);
WNDCLASS Draw;
Draw.cbClsExtra = 0;
Draw.cbWndExtra = 0;
Draw.hCursor = LoadCursor(hInstance, IDC_ARROW);;
Draw.hIcon = LoadIcon(hInstance, IDI_APPLICATION);;
Draw.lpszMenuName = NULL;
Draw.style = CS_HREDRAW | CS_VREDRAW;
Draw.hbrBackground = (HBRUSH)COLOR_WINDOW;
Draw.lpfnWndProc = WindowProc;
Draw.lpszClassName = _T("DDraw");
Draw.hInstance = hInstance;
RegisterClass(&Draw);
HWND hwnd = CreateWindow(
_T("DDraw"),
//上面注册的类名,要完全一致
L"绘制", //窗口标题文字
WS_OVERLAPPEDWINDOW, //窗口外观样式
38,
//窗口相对于父级的X坐标
20,
//窗口相对于父级的Y坐标
640,
//窗口的宽度
480,
//窗口的高度
NULL,
//没有父窗口,为NULL
NULL,
//没有菜单,,为NULL
hInstance,
//当前应用程序的实例句柄
NULL);
//没有附加数据,为NULL
// 显示窗口
ShowWindow(hwnd, SW_SHOW);
// 更新窗口
UpdateWindow(hwnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// 消息处理函数的实现
LRESULT CALLBACK WindowProc(
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
switch (uMsg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
#include <windows.h>
#include "TCHAR.h"
#include <stdio.h>
LRESULT CALLBACK WindowProc(
HWND hwnd,
// handle to window
UINT uMsg,
// message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance,
// handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine,
// command line
int nCmdShow
// show state
)
{
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 = WindowProc;
wndcls.lpszClassName = _T("Hello");
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd = CreateWindow(_T("Hello"), L"World", WS_OVERLAPPEDWINDOW,
0, 0, 600, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
// 消息处理函数的实现
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70072.html