コンソールの下にウィンドウとWinMainエントリを作成ウィンドウ簡易プログラムを作成
3306 ワード
コンソール作成ウィンドウ(コンソールウィンドウと新しく作成したウィンドウが同時にある)(プロジェクトタイプ:コンソールアプリケーション)
WinMain入口下作成ウィンドウ(新しく作成したウィンドウのみ)(プロジェクトタイプ:windowsアプリケーション)
#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);
}
WinMain入口下作成ウィンドウ(新しく作成したウィンドウのみ)(プロジェクトタイプ:windowsアプリケーション)
#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);
}