#include <windows.h>
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL,"メッセージ","タイトル",0);
return 0;
}
char line[256];
AllocConsole();
freopen("CONOUT$", "w", stdout);
freopen("CONIN$", "r", stdin);
printf("これでprintfが使える\n");
gets(line); // Returnキー入力待ち
::GetConsoleTitle( title, 1023 ) ;
g.hConsole = FindWindow(NULL,title);
ShowWindow(g.hConsole, SW_HIDE);
g.hConsele = ::GetConsoleWindow();
HMENU hMenu = ::GetSystemMenu(g.hConsole, 0);
::RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
#include <windows.h>
#include <tchar.h>
TCHAR szTitle[100] = _T("My Program");
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wp, lp);
}
return 0;
}
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HWND hWnd;
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(NULL)); // ICON
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(NULL); // MENU
wcex.lpszClassName = szTitle;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(NULL)); // small ICON
if (!RegisterClassEx(&wcex)) return 0;
hWnd = CreateWindow(szTitle, szTitle, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd) {
return 0;
}
ShowWindow(hWnd, nCmdShow);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
#include "resource.h";
HKEY hKey;
TCHAR szName[256],dataBuff[256];
DWORD dwIndex,dwType,dwSize,dwNameSize;
long result;
char cbuff[] = "HARDWARE\\DEVICEMAP\\SERIALCOMM";
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, cbuff, 0, KEY_READ, &hKey);
if (result == ERROR_SUCCESS){
for (dwIndex = 0;;dwIndex++) {
dwNameSize = 256;
result = RegEnumValue(hKey,dwIndex,szName,&dwNameSize,NULL,&dwType,NULL,NULL);
if(result == ERROR_NO_MORE_ITEMS) break;
else if (result != ERROR_SUCCESS) break;
switch (dwType){
case REG_SZ:
result = RegQueryValueEx(hKey, szName, NULL, &dwType, NULL, &dwSize);
result = RegQueryValueEx(hKey, szName, NULL, &dwType, (LPBYTE)dataBuff, &dwSize);
MessageBox(NULL,dataBuff,"COM Port",0);
break;
default:
break;
}
}
RegCloseKey(hKey);
}
long rs_init(char *portName, unsigned long speed,
unsigned short length, unsigned short parities, unsigned short stops)
{
char c[10];
sprintf(c,"\\\\.\\%s",portName);
hComm=CreateFile(c, /*COM1〜*/
:
if (!rs_init(comName,9600,8,0,0)) {
rs_write(strlen(command),(unsigned char *)command);
wait_ms(50);
datalen = rs_check();
if (datalen>0) {
rs_read(datalen,(unsigned char *)res);
res[datalen] = '\0';
printf("%s > %s\n",command,res);
}
rs_end();
}
::CreateMutex(NULL, TRUE, APPLICATION_NAME);
if(GetLastError() == ERROR_ALREADY_EXISTS) {
SetForegroundWindow(FindWindow(NULL, APPLICATION_NAME));
return FALSE;
}
void wait_ms(int delay)
{
clock_t sclock;
sclock = clock();
while(clock()-sclock<delay);
}
int wait_ms(int wait)
{
register LONGLONG goal, freq, cnt;
if (!QueryPerformanceFrequency((LARGE_INTEGER*)&freq))
return 1;
else {
QueryPerformanceCounter((LARGE_INTEGER*)&goal);
goal += freq * (LONGLONG)wait/1000;
do {
QueryPerformanceCounter((LARGE_INTEGER*)&cnt);
} while (goal>cnt);
}
return 0;
}
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&begin);
Sleep(1000);
QueryPerformanceCounter( &end );
printf("%f\n",(double)(end.QuadPart-begin.QuadPart)/freq.QuadPart);
#include <stdio.h>
void DebugMsgBox(LPCSTR pszFormat, ...)
{
wchar_t wbuf[256] = { 0x00 };
va_list argp;
char pszBuf[256];
va_start(argp, pszFormat);
vsprintf_s(pszBuf, pszFormat, argp);
va_end(argp);
MultiByteToWideChar(CP_ACP, 0, pszBuf, -1, wbuf, (int)strlen(pszBuf)+1);
MessageBox(NULL, wbuf, _T("debug"), MB_OK);
}
#include <windows.h>
#include <stdio.h>
#if defined(_DEBUG) || defined(DEBUG)
// Debugのとき
#define TRACE(x) OutputDebugString(x)
#define TRACE0(x) OutputDebugString(x)
#define TRACE1(x, a) MyOutputDebugString(x, a)
#define TRACE2(x, a, b) MyOutputDebugString(x, a, b)
#define TRACE3(x, a, b, c) MyOutputDebugString(x, a, b, c)
#define TRACE4(x, a, b, c, d) MyOutputDebugString(x, a, b, c, d)
#else
// Releaseのとき
#define TRACE(x)
#define TRACE0(x)
#define TRACE1(x, a)
#define TRACE2(x, a, b)
#define TRACE3(x, a, b, c)
#define TRACE4(x, a, b, c, d)
#endif
void MyOutputDebugString( LPCSTR pszFormat, ...)
{
va_list argp;
char pszBuf[ 256];
va_start(argp, pszFormat);
vsprintf( pszBuf, pszFormat, argp);
va_end(argp);
OutputDebugString( pszBuf);
}
system("xcommand test.csv");
ShellExecute(NULL,"open","xcommand","test.csv",NULL,SW_SHOWNORMAL);
include <iostream>
#include <cstdio>
using namespace std;
:
FILE *fout;
fout = _popen("xcommand.exe", "w");
fputs("xxx yyy zzz\n", fout); //コマンドにパラメータを送る
fflush(fout);
cin.get();
_pclose(fout);
: