#2
by Math » 5年前
Windowsのメッセージをコンソールに出力するプログラムです。
コード:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
static FILE *fp;
LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI _tWinMain
(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wc;
wc.style =0;
wc.lpfnWndProc =WindowProc;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
wc.hInstance =hInstance;
wc.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName =NULL;
wc.lpszClassName=TEXT("Form1Class");
if(RegisterClass(&wc)==0)
return 0;
hwnd=CreateWindow( TEXT("Form1Class"),
TEXT("Form1"),
WS_OVERLAPPEDWINDOW,
10,
50,
300,
200,
NULL,
(HMENU)NULL,
hInstance,
0);
if(hwnd==NULL)
return 0;
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
///////////////////////////////////////////
//コンソールを作成し,標準出力に割り当てる
AllocConsole();
freopen_s(&fp,"CON", "w", stdout);
////////////////////////////////////////////
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
/////////////////////////////////////////////////
//コンソールを作成し,標準入出力に割り当てている
printf(" message = %d",message);
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wparam,lparam);
}
///////////////////////////////////////////////////////////////////////////////
VisualStudio2019Community で
実行してみました。
http://www2.koyoen.birdview.co.jp/~abcx ... -20-a-.PNG
Windows10のにはDirectXが採用されています。
この質問箱の管理人さんのページに
https://dixq.net/g/02_09.html
説明があります。
なを 詳しいことはここに問い合わせてください。
https://dxlib.xsrv.jp/cgi/patiobbs/patio.cgi?
Windowsのメッセージをコンソールに出力するプログラムです。
[code]
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
static FILE *fp;
LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI _tWinMain
(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wc;
wc.style =0;
wc.lpfnWndProc =WindowProc;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
wc.hInstance =hInstance;
wc.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName =NULL;
wc.lpszClassName=TEXT("Form1Class");
if(RegisterClass(&wc)==0)
return 0;
hwnd=CreateWindow( TEXT("Form1Class"),
TEXT("Form1"),
WS_OVERLAPPEDWINDOW,
10,
50,
300,
200,
NULL,
(HMENU)NULL,
hInstance,
0);
if(hwnd==NULL)
return 0;
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
///////////////////////////////////////////
//コンソールを作成し,標準出力に割り当てる
AllocConsole();
freopen_s(&fp,"CON", "w", stdout);
////////////////////////////////////////////
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
/////////////////////////////////////////////////
//コンソールを作成し,標準入出力に割り当てている
printf(" message = %d",message);
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wparam,lparam);
}
///////////////////////////////////////////////////////////////////////////////
[/code]
VisualStudio2019Community で
実行してみました。
[url]http://www2.koyoen.birdview.co.jp/~abcxyz/19-04-20-a-.PNG[/url]
Windows10のにはDirectXが採用されています。
この質問箱の管理人さんのページに[url]https://dixq.net/g/02_09.html[/url]
説明があります。
なを 詳しいことはここに問い合わせてください。
[url]https://dxlib.xsrv.jp/cgi/patiobbs/patio.cgi?[/url]