2024-01-01から1年間の記事一覧

完璧!

#include <windows.h>#include <vector>#include <sstream> const int WINDOW_WIDTH = 200;const int WINDOW_HEIGHT = 400;const int LINE_HEIGHT = 20;const int TOTAL_LINES = 20;const int VISIBLE_LINES = 10; HWND g_hWnd;int g_scrollPosition = 0;int g_selectedIndex = 0; void S</sstream></vector></windows.h>…

ウィンドウで操作中、main関数のwhile文で処理

#include <windows.h>#include <iostream> // グローバル変数HWND g_hWnd;bool g_running = true; LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefW</iostream></windows.h>…

10行分スクロール

#include <iostream>#include <windows.h>#include <conio.h> const int WINDOW_HEIGHT = 10;const int TOTAL_LINES = 20; void setConsoleWindowSize(int width, int height) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SMALL_RECT rect = { 0, 0, static_cast<SHORT>(width - 1), st</short></conio.h></windows.h></iostream>…

WORD

#include <iostream>#include <cstdio>#include <windows.h>#include <stdio.h> void main(){ SYSTEMTIME st, lt; GetSystemTime(&st); GetLocalTime(&lt); printf("The system time is: %02d:%02d\n", st.wHour, st.wMinute); printf(" The local time is: %02d:%02d\n", lt.wHour, lt.wMinute); W</stdio.h></windows.h></cstdio></iostream>…

メール作成

【Mail_Setting.xlsm】 Sub SendEmail() Dim OutlookApp As Object Dim MailItem As Object Dim mail_list As Variant Dim i As Integer Dim LastRow As Long ' C列の最終行を取得 LastRow = Cells(Rows.Count, "C").End(xlUp).Row ReDim mail_list(0 To Las…

スペイン

日程 観光エリア 移動等 宿エリア 宿 04/26 金 日本発 04/27 土 マドリード マドリード市内 マドリード SLEEP'N Atocha - B Corp Certified 04/28 日 トレド 午後トレド マドリード SLEEP'N Atocha - B Corp Certified 04/29 月 セゴビア 午前セゴビア マド…

文字選択による結果(簡易化)

#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <Windows.h>#include <vector> // 選択された文字列のインデックスint selectedIndex = 0; // 選択肢の文字列std::vector<std::string> options = { "おはよう", "こんにちは", "こんばんは", "おやすみ" }; int key_mode;void key_sel_pai</std::string></vector></windows.h></iostream>…

文字選択による結果表示

#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <Windows.h>#include <vector> // 選択された文字列のインデックスint selectedIndex = 0; // 選択肢の文字列std::vector<std::string> options = { "おはよう", "こんにちは", "こんばんは", "おやすみ" }; // ウィンドウプロシージャLRES</std::string></vector></windows.h></iostream>…

ウィンドウ背景青、水色枠

#define _CRT_SECURE_NO_WARNINGS#include <Windows.h>#include <chrono>#include <ctime>#include <thread> constexpr int WINDOW_X = 10;constexpr int WINDOW_Y = 10; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);void DisplayCurrentDateTime(HWND hwnd,</thread></ctime></chrono></windows.h>…

C++ウィンドウ表示など

#define _CRT_SECURE_NO_WARNINGS#include <Windows.h>#include <chrono>#include <ctime>#include <thread> constexpr int WINDOW_X = 10;constexpr int WINDOW_Y = 10; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);void DisplayCurrentDateTime(HWND hwnd,</thread></ctime></chrono></windows.h>…

引数LPCWSTR型によるビルドエラー対策

そのエラーはconst wchar_t*型を渡すべきところに、const char*を渡しているというエラーです。Windows APIはワイド文字モードでビルドすると、多くの文字列はconst wchar_t*で受け取ります。マルチ・バイト文字モードでビルドするか、文字列をL"xxx"のよう…

_dos_finefirst()の代替関数(確定)

#include <io.h>#include <cstring> int main() { struct _finddata_t fileinfo; intptr_t handle; const char* filespec = "C:\\Users\\sannp\\Desktop\\SAMC1\\DAT\\data\\data?.dat"; // 検索するファイル名のパターンを指定 // 検索を開始 handle = _findfirst(filespec</cstring></io.h>…

_dos_findfirst 関数について

_dos_findfirst 関数は、DOS ファイルシステム上のファイルやディレクトリを検索するための関数です。dos.h ヘッダーファイルで提供され、DOS プログラミング環境で使用されましたが、現代の Windows プログラミングには推奨されません。 以下は _dos_findfi…

C++ RS-232C通信制御プログラム(パート2)

<RS232C.cpp> #include <iostream>#include "SerialPort.h" // シリアルポートクラスのヘッダーファイルをインクルード int main() { // シリアルポート設定(ポート、データビット長、パリティチェック、ストップビッチ長) SerialPort serial(TEXT("COM1"), CBR_9600, 8, EVENPAR</iostream></rs232c.cpp>…

C++ dos_getftime(),fread()に関して

#include <iostream>#include <Windows.h>#include <ctime> //fopen関数を使用できるためのおまじない#pragma warning(disable: 4996) #define NUM_ALPHA 256 int main() { FILE *fp; char buffer[NUM_ALPHA + 1]; int num; const int BUFFER_SIZE = 100; // File path const char* fileP</ctime></windows.h></iostream>…

C++

古い_dos_getftime()関数は、DOS時代のファイルの最終更新日時を取得する関数でしたが、Windowsでその代替となる関数は標準的なC++やWindows APIには存在しません。代わりに、Windowsでファイルの属性を取得するには、Windows APIの GetFileAttributes() 関…

C++API

12個のボタンを描画して、1個目のボタンを押すと「Hallo!」のメッセージが表示される #include <Windows.h>#include <vector> // グローバル変数std::vector<HWND> g_buttons; // ボタンウィンドウのハンドルを格納するベクター // ボタンクリック時の処理void OnButtonClick(int </hwnd></vector></windows.h>…

C++ signal関数

#include <iostream>#include <csignal> // signal関数を含むヘッダ // シグナルハンドラ関数void signalHandler(int signal) { std::cout << "Interrupt signal (" << signal << ") received." << std::endl; // プログラムの終了 exit(signal);} int main() { // SIGINTシグナ</csignal></iostream>…

C++ RS-232C通信制御プログラム

指定されたシリアルポート(COM1)を開き、指定されたボーレート(9600bps)で通信を行います。指定されたデータを送信し、受信したデータを取得して表示します。必要に応じてポート名やボーレートを変更してください。 #include <iostream>#include <Windows.h> // シリアルポー</windows.h></iostream>…

日時、日時取得

Visual C++ (VC++) で日付と日時を取得するためには、Windows API の GetSystemTime() 関数を使用します。以下は、この関数を使用して現在の日付と日時を取得するプログラムの例です。 #include <iostream>#include <Windows.h> int main() { SYSTEMTIME systemTime; // 現在のシ</windows.h></iostream>…

#ifdefと#if #defineの違い

#include <stdio.h>#define DEBUG#ifdef DEBUG printf("DEBUGモードです。\n");#endif#define VERSION 2#if VERSION >= 3 printf("最新バージョンです。\n");#else printf("古いバージョンです。\n");#endif *************************************** #include <stdio.h>#defin</stdio.h></stdio.h>…

C++iniファイル読み書き

#include <iostream>#include <Windows.h> int main() { // INIファイルのパスとセクション、キーを指定 LPCWSTR iniFilePath = L"C:\\Users\\sannp\\Desktop\\SAMC1\\INI\\COM.ini"; LPCWSTR section = L"FTE"; // キーを指定 //LPCWSTR key1 = L"section1"; //LPCWSTR key2 = L"</windows.h></iostream>…

C++ visa通信

#include <visa.h> // Keysight IOライブラリ・スイートのヘッダーファイル #include <iostream>#include <string> int main() { ViSession defaultRM, instr; ViStatus status; ViChar buffer[256]; // VISAデバイスの初期化 status = viOpenDefaultRM(&defaultRM); if (status < VI_S</string></iostream></visa.h>…

C++関連その3

コンソールサイズ設定 consol_size_set(800, 600); int consol_size_set(short int x, short int y) { // コンソールウィンドウのハンドルを取得 HWND console = GetConsoleWindow(); if (console == NULL) { return 1; // エラー処理 } // ウィンドウのサイ…

グラフィック関係

putimage() 関数は、古いBGI(Borland Graphics Interface)などのグラフィックスライブラリで使用されており、イメージを画面上の指定された位置に描画します。標準C++には含まれていないため、直接的な代替関数はありません。 しかし、グラフィックス描画…

データファイルをプリンターに出力するプログラム

#include <iostream>#include <Windows.h> void PrintFile(const std::string& filename) { // デフォルトのプリンターを取得 DWORD bufsize = 256; char printerName[256]; GetDefaultPrinter(printerName, &bufsize); // プリンターデバイスコンテキストを取得 HDC hdc = Create</windows.h></iostream>…

C++キー入力関連

std::cout << "キーを入力してください: "; switch (_getch()) { case 0xe0: switch (_getch()) { case 0x48: printf("↑"); break; case 0x50: printf("↓"); break; case 0x4b: printf("←"); break; case 0x4d: printf("→"); break; } break; case 0x0d: pri…

C++解説2

#define On 1 は、C++のプリプロセッサディレクティブを使用して、On という識別子を 1 に置き換えるという意味です。 ------------------------- C++における struct find_t file_buffer という記述は、構造体(struct)の定義とその変数宣言を組み合わせて…

C++関連その3

void message_outX(const char* message) { gotoXY1(3, 22); printf("%-76s", message); textcolor(BLUE);} ------------------------------------------------------- // char* message[10] の宣言 const char* message[10]; // message[0] に "異常検出" …

C++関連 解説

C++言語そのものに _interrupt というキーワードや機能はありません。_interrupt は、古いDOSプログラミング環境において、割り込みベクターに関連する関数や関連機能を宣言するために使用されていました。 古いMS-DOSやWindowsのプログラムでは、割り込みハ…