├── .gitattributes ├── .gitignore ├── LICENSE.TXT ├── README.md ├── Source.cpp ├── camera.png ├── json.hpp ├── resource.h ├── tweet2.rc ├── tweet2.sln ├── tweet2.vcxproj └── tweet2.vcxproj.filters /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | MIT License (MIT) 2 | 3 | Copyright (c) 2023 kenjinote (hack.jp) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tweet2 2 | Twitter API 2.0を使ってツイート(ポスト)する 3 | 4 | ![image](https://github.com/kenjinote/tweet2/assets/2605401/7f319c58-ca12-4f42-937f-ea3ced68f6af) 5 | 6 | 下記のキーをTwitterの[開発者ページ](https://developer.twitter.com/)から取得する必要があります。 7 | 8 | - API Key(Consumer Key) 9 | - API Key Secret(Consumer Secret) 10 | - Access Token 11 | - Access Token Secret 12 | -------------------------------------------------------------------------------- /Source.cpp: -------------------------------------------------------------------------------- 1 | #pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 2 | 3 | #pragma comment(lib, "shlwapi") 4 | #pragma comment(lib, "crypt32") 5 | #pragma comment(lib, "gdiplus") 6 | #pragma comment(lib, "dwmapi") 7 | #pragma comment(lib, "winhttp.lib") 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "json.hpp" 20 | #include "resource.h" 21 | 22 | using namespace Gdiplus; 23 | 24 | WCHAR szClassName[] = L"Window"; 25 | 26 | INT64 GetUnixTime() 27 | { 28 | SYSTEMTIME systemtime; 29 | GetSystemTime(&systemtime); 30 | FILETIME filetime; 31 | SystemTimeToFileTime(&systemtime, &filetime); 32 | INT64 unixtime = filetime.dwHighDateTime; 33 | unixtime <<= 32; 34 | unixtime += filetime.dwLowDateTime; 35 | unixtime -= 116444736000000000L; 36 | unixtime /= 10000000L; 37 | return unixtime; 38 | } 39 | 40 | LPSTR CreateRandomString() 41 | { 42 | HCRYPTPROV prov; 43 | if (CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, 0)) { 44 | BYTE data[32] = {}; 45 | CryptGenRandom(prov, sizeof(data), data); 46 | DWORD dwSize = 0; 47 | CryptBinaryToStringA(data, sizeof(data), CRYPT_STRING_BASE64, NULL, &dwSize); 48 | LPSTR random = (LPSTR)GlobalAlloc(GPTR, dwSize); 49 | if (random) { 50 | CryptBinaryToStringA(data, sizeof(data), CRYPT_STRING_BASE64, random, &dwSize); 51 | CryptReleaseContext(prov, 0); 52 | LPSTR p, q; 53 | for (p = random, q = random; *p; p++) { 54 | if (*p != '+' && *p != '/' && *p != '=' && *p != '\r' && *p != '\n') { 55 | *q++ = *p; 56 | } 57 | } 58 | *q = 0; 59 | return random; 60 | } 61 | } 62 | return 0; 63 | } 64 | 65 | int UrlEncode(LPCSTR src, LPSTR dst) 66 | { 67 | DWORD idst = 0; 68 | for (DWORD isrc = 0; src[isrc] != '\0'; ++isrc) { 69 | LPCSTR lpszUnreservedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"; 70 | if (StrChrA(lpszUnreservedCharacters, src[isrc])) { 71 | if (dst) dst[idst] = (WCHAR)src[isrc]; 72 | ++idst; 73 | } 74 | else if (src[isrc] == ' ') { 75 | if (dst) dst[idst] = L'+'; 76 | ++idst; 77 | } 78 | else { 79 | if (dst) wsprintfA(&dst[idst], "%%%02X", src[isrc] & 0xFF); 80 | idst += 3; 81 | } 82 | } 83 | if (dst) dst[idst] = L'\0'; 84 | ++idst; 85 | return idst; 86 | } 87 | 88 | LPSTR CreateURLEncodeStrng(LPCSTR src) 89 | { 90 | const int nSize = UrlEncode(src, 0); 91 | if (nSize) { 92 | LPSTR encoded = (LPSTR)GlobalAlloc(0, nSize); 93 | if (encoded) { 94 | UrlEncode(src, encoded); 95 | return encoded; 96 | } 97 | } 98 | return 0; 99 | } 100 | 101 | BOOL GetHMAC_SHA1(LPCSTR src, LPCSTR key, LPSTR output, DWORD size) 102 | { 103 | BOOL ret = FALSE; 104 | 105 | DWORD keylen = lstrlenA(key); 106 | if (keylen >= 1024) { 107 | return FALSE; 108 | } 109 | 110 | struct { 111 | BLOBHEADER hdr; 112 | DWORD len; 113 | BYTE key[1024]; 114 | } key_blob; 115 | 116 | HCRYPTPROV hProv = NULL; 117 | HCRYPTHASH hHash = NULL; 118 | HCRYPTKEY hKey = NULL; 119 | HCRYPTHASH hHmacHash = NULL; 120 | PBYTE pbHash = NULL; 121 | DWORD dwDataLen = 0; 122 | HMAC_INFO HmacInfo; 123 | 124 | ZeroMemory(&HmacInfo, sizeof(HmacInfo)); 125 | HmacInfo.HashAlgid = CALG_SHA1; 126 | 127 | if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)) { 128 | goto ErrorExit; 129 | } 130 | 131 | ZeroMemory(&key_blob, sizeof(key_blob)); 132 | 133 | key_blob.hdr.bType = PLAINTEXTKEYBLOB; 134 | key_blob.hdr.bVersion = CUR_BLOB_VERSION; 135 | key_blob.hdr.reserved = 0; 136 | key_blob.hdr.aiKeyAlg = CALG_RC2; 137 | key_blob.len = keylen; 138 | memcpy(key_blob.key, key, keylen); 139 | 140 | if (!CryptImportKey(hProv, (BYTE*)&key_blob, sizeof(key_blob), 0, CRYPT_IPSEC_HMAC_KEY, &hKey)) { 141 | goto ErrorExit; 142 | } 143 | 144 | if (!CryptCreateHash(hProv, CALG_HMAC, hKey, 0, &hHmacHash)) { 145 | goto ErrorExit; 146 | } 147 | 148 | if (!CryptSetHashParam(hHmacHash, HP_HMAC_INFO, (BYTE*)&HmacInfo, 0)) { 149 | goto ErrorExit; 150 | } 151 | 152 | if (!CryptHashData(hHmacHash, (LPCBYTE)src, lstrlenA(src), 0)) { 153 | goto ErrorExit; 154 | } 155 | 156 | if (!CryptGetHashParam(hHmacHash, HP_HASHVAL, NULL, &dwDataLen, 0)) { 157 | goto ErrorExit; 158 | } 159 | 160 | pbHash = (LPBYTE)GlobalAlloc(0, dwDataLen); 161 | if (NULL == pbHash) { 162 | goto ErrorExit; 163 | } 164 | 165 | if (!CryptGetHashParam(hHmacHash, HP_HASHVAL, pbHash, &dwDataLen, 0)) { 166 | goto ErrorExit; 167 | } 168 | 169 | CryptBinaryToStringA(pbHash, dwDataLen, CRYPT_STRING_BASE64, output, &size); 170 | LPSTR p = 0, q = 0; 171 | for (p = output, q = output; *p; p++) { 172 | if (*p != '\r' && *p != '\n') { 173 | *q++ = *p; 174 | } 175 | } 176 | *q = 0; 177 | ret = TRUE; 178 | 179 | ErrorExit: 180 | if (hHmacHash) 181 | CryptDestroyHash(hHmacHash); 182 | if (hKey) 183 | CryptDestroyKey(hKey); 184 | if (hHash) 185 | CryptDestroyHash(hHash); 186 | if (hProv) 187 | CryptReleaseContext(hProv, 0); 188 | if (pbHash) 189 | GlobalFree(pbHash); 190 | 191 | return ret; 192 | } 193 | 194 | LPSTR CreateOAuthPram(const std::map& m, LPCSTR url, LPCSTR consumer_secret, LPCSTR access_token_secret, BOOL bIncludeQueryParameter = TRUE) 195 | { 196 | std::string base; 197 | std::map parameter; 198 | 199 | for (auto it = m.begin(); it != m.end(); it++) { 200 | if (it != m.begin()) { 201 | base += "&"; 202 | } 203 | base += it->first; 204 | base += "="; 205 | base += it->second; 206 | LPSTR encoded = CreateURLEncodeStrng(it->second.c_str()); 207 | if (encoded) { 208 | parameter[it->first] = encoded; 209 | GlobalFree(encoded); 210 | } 211 | } 212 | 213 | std::string src; 214 | if (bIncludeQueryParameter) { 215 | src += "POST&"; 216 | LPSTR encoded = CreateURLEncodeStrng(url); 217 | if (encoded) { 218 | src += encoded; 219 | src += "&"; 220 | GlobalFree(encoded); 221 | } 222 | } 223 | 224 | { 225 | LPSTR encoded = CreateURLEncodeStrng(base.c_str()); 226 | if (encoded) { 227 | src += encoded; 228 | GlobalFree(encoded); 229 | } 230 | } 231 | 232 | std::string key = ""; 233 | key += consumer_secret; 234 | key += "&"; 235 | key += access_token_secret; 236 | 237 | LPSTR lpszOAuthParam = 0; 238 | { 239 | CHAR output[1024] = {}; 240 | if (GetHMAC_SHA1(src.c_str(), key.c_str(), output, _countof(output)) == TRUE) { 241 | LPSTR encoded = CreateURLEncodeStrng(output); 242 | if (encoded) { 243 | std::string strOAuthParam = "OAuth "; 244 | for (auto it = parameter.begin(); it != parameter.end(); it++) { 245 | if (it != parameter.begin()) { 246 | strOAuthParam += ","; 247 | } 248 | strOAuthParam += it->first; 249 | strOAuthParam += "="; 250 | strOAuthParam += it->second; 251 | } 252 | strOAuthParam += ",oauth_signature="; 253 | strOAuthParam += encoded; 254 | GlobalFree(encoded); 255 | lpszOAuthParam = (LPSTR)GlobalAlloc(0, strOAuthParam.size() + 1); 256 | if (lpszOAuthParam) { 257 | strcpy_s(lpszOAuthParam, strOAuthParam.size() + 1, strOAuthParam.c_str()); 258 | } 259 | } 260 | } 261 | } 262 | 263 | return lpszOAuthParam; 264 | } 265 | 266 | std::string send(HWND hWnd, LPCWSTR lpszServerName, LPCWSTR lpszObjectName, LPCSTR lpszOAuthParam, LPCSTR lpszHeader, LPCBYTE lpBody, DWORD dwBodySize) 267 | { 268 | std::string ret; 269 | 270 | HINTERNET hSession = WinHttpOpen(L"WinHTTP_Client", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); 271 | if (!hSession) return ret; 272 | 273 | HINTERNET hConnect = WinHttpConnect(hSession, lpszServerName, INTERNET_DEFAULT_HTTPS_PORT, 0); 274 | if (!hConnect) { 275 | WinHttpCloseHandle(hSession); 276 | return ret; 277 | } 278 | 279 | HINTERNET hRequest = WinHttpOpenRequest(hConnect, L"POST", lpszObjectName, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE); 280 | if (!hRequest) { 281 | WinHttpCloseHandle(hConnect); 282 | WinHttpCloseHandle(hSession); 283 | return ret; 284 | } 285 | 286 | std::string headers = "Authorization: "; 287 | headers += lpszOAuthParam; 288 | headers += "\r\n"; 289 | headers += lpszHeader; 290 | 291 | BOOL bResults = WinHttpSendRequest(hRequest, 292 | std::wstring(headers.begin(), headers.end()).c_str(), 293 | -1, 294 | (LPVOID)lpBody, 295 | dwBodySize, 296 | dwBodySize, 297 | 0); 298 | 299 | if (bResults && WinHttpReceiveResponse(hRequest, NULL)) { 300 | DWORD dwStatusCode = 0; 301 | DWORD dwSize = sizeof(dwStatusCode); 302 | WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &dwStatusCode, &dwSize, NULL); 303 | 304 | DWORD dwContentLength = 0; 305 | dwSize = sizeof(dwContentLength); 306 | WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_CONTENT_LENGTH | WINHTTP_QUERY_FLAG_NUMBER, NULL, &dwContentLength, &dwSize, NULL); 307 | 308 | std::string response; 309 | DWORD dwDownloaded = 0; 310 | do { 311 | DWORD dwSize = 0; 312 | WinHttpQueryDataAvailable(hRequest, &dwSize); 313 | if (dwSize == 0) break; 314 | 315 | BYTE* buffer = new BYTE[dwSize + 1]; 316 | ZeroMemory(buffer, dwSize + 1); 317 | WinHttpReadData(hRequest, buffer, dwSize, &dwDownloaded); 318 | response.append((char*)buffer, dwDownloaded); 319 | delete[] buffer; 320 | } while (dwDownloaded > 0); 321 | 322 | try { 323 | auto j = nlohmann::json::parse(response); 324 | 325 | if (dwStatusCode != HTTP_STATUS_OK && 326 | dwStatusCode != HTTP_STATUS_CREATED && 327 | dwStatusCode != HTTP_STATUS_ACCEPTED && 328 | dwStatusCode != HTTP_STATUS_PARTIAL && 329 | dwStatusCode != HTTP_STATUS_NO_CONTENT && 330 | dwStatusCode != HTTP_STATUS_RESET_CONTENT && 331 | dwStatusCode != HTTP_STATUS_PARTIAL_CONTENT) { 332 | 333 | std::string error = "ポストできませんでした(ステータスコード:" + std::to_string(dwStatusCode); 334 | if (j.contains("detail")) { 335 | error += ", エラー詳細:" + j["detail"].get(); 336 | } 337 | else if (j.contains("error")) { 338 | error += ", エラー詳細:" + j["error"].get(); 339 | } 340 | else if (j.contains("errors")) { 341 | for (auto& e : j["errors"]) { 342 | error += e["message"].get() + "\n"; 343 | } 344 | } 345 | error += ")"; 346 | MessageBoxA(hWnd, error.c_str(), 0, MB_OK); 347 | } 348 | else { 349 | if (j.contains("media_id_string")) { 350 | ret = j["media_id_string"]; 351 | } 352 | else if (j.contains("data") && j["data"].contains("id")) { 353 | ret = j["data"]["id"]; 354 | } 355 | } 356 | } 357 | catch (...) { 358 | std::string error = "レスポンスの解析に失敗しました(ステータスコード:" + std::to_string(dwStatusCode) + ")"; 359 | MessageBoxA(hWnd, error.c_str(), 0, MB_OK); 360 | } 361 | } 362 | 363 | WinHttpCloseHandle(hRequest); 364 | WinHttpCloseHandle(hConnect); 365 | WinHttpCloseHandle(hSession); 366 | 367 | return ret; 368 | } 369 | 370 | 371 | std::string image_upload(HWND hWnd, LPCSTR lpszOAuthParam, LPCBYTE lpByte) 372 | { 373 | LPCSTR boundary = "AaB03x"; 374 | DWORD dwBoundarySize = (DWORD)lstrlenA(boundary); 375 | DWORD dwOrgSize = (DWORD)GlobalSize((HGLOBAL)lpByte); 376 | LPCSTR lpszContentDisposition = "Content-Disposition: form-data; name=\"media\"; filename=\"media\""; 377 | DWORD dwContentDispositionSize = (DWORD)lstrlenA(lpszContentDisposition); 378 | LPCSTR lpszContentType = "Content-Type: image/png;"; 379 | DWORD dwContentTypeSize = (DWORD)lstrlenA(lpszContentType); 380 | 381 | DWORD dwBodySize = 2/* ハイフン*2 */ + dwBoundarySize + 2/* 改行 */ 382 | + dwContentDispositionSize + 2/* 改行 */ 383 | + dwContentTypeSize + 2/* 改行 */ 384 | + 2/* 改行 */ 385 | + dwOrgSize 386 | + 2/* 改行 */ 387 | + 2/* ハイフン*2 */ + dwBoundarySize + 2/* ハイフン*2 */ + 2/* 改行 */; 388 | 389 | LPBYTE lpszBody = (LPBYTE)GlobalAlloc(0, dwBodySize + 1); 390 | if (lpszBody == NULL) { 391 | return std::string(); 392 | } 393 | 394 | DWORD pos = 0; 395 | CopyMemory(lpszBody + pos, "--", 2); 396 | pos += 2; 397 | CopyMemory(lpszBody + pos, boundary, dwBoundarySize); 398 | pos += dwBoundarySize; 399 | CopyMemory(lpszBody + pos, "\r\n", 2); 400 | pos += 2; 401 | CopyMemory(lpszBody + pos, lpszContentDisposition, dwContentDispositionSize); 402 | pos += dwContentDispositionSize; 403 | CopyMemory(lpszBody + pos, "\r\n", 2); 404 | pos += 2; 405 | CopyMemory(lpszBody + pos, lpszContentType, dwContentTypeSize); 406 | pos += dwContentTypeSize; 407 | CopyMemory(lpszBody + pos, "\r\n", 2); 408 | pos += 2; 409 | CopyMemory(lpszBody + pos, "\r\n", 2); 410 | pos += 2; 411 | CopyMemory(lpszBody + pos, lpByte, dwOrgSize); 412 | pos += dwOrgSize; 413 | CopyMemory(lpszBody + pos, "\r\n", 2); 414 | pos += 2; 415 | CopyMemory(lpszBody + pos, "--", 2); 416 | pos += 2; 417 | CopyMemory(lpszBody + pos, boundary, dwBoundarySize); 418 | pos += dwBoundarySize; 419 | CopyMemory(lpszBody + pos, "--", 2); 420 | pos += 2; 421 | CopyMemory(lpszBody + pos, "\r\n", 2); 422 | pos += 2; 423 | 424 | std::string ret = send(hWnd, L"upload.twitter.com", L"/1.1/media/upload.json", lpszOAuthParam, "Content-Type: multipart/form-data; boundary=AaB03x", lpszBody, dwBodySize); 425 | 426 | GlobalFree(lpszBody); 427 | 428 | return ret; 429 | } 430 | 431 | std::string tweet(HWND hWnd, LPCSTR lpszOAuthParam, LPCSTR lpszMessage, const std::vector &media_ids) 432 | { 433 | nlohmann::json payload; 434 | payload["text"] = lpszMessage; 435 | if (media_ids.size() > 0) { 436 | payload["media"]["media_ids"] = media_ids; 437 | } 438 | std::string strPayload = payload.dump(); 439 | return send(hWnd, L"api.x.com", L"/2/tweets", lpszOAuthParam, "Content-Type: application/json", (LPCBYTE)strPayload.c_str(), (DWORD)strPayload.size()); 440 | } 441 | 442 | class BitmapEx : public Gdiplus::Bitmap { 443 | public: 444 | LPBYTE m_lpByte; 445 | DWORD m_nSize; 446 | BitmapEx(IN HBITMAP hbm) 447 | : Gdiplus::Bitmap::Bitmap(hbm, 0) 448 | , m_lpByte(0), m_nSize(0) { 449 | Gdiplus::Status OldlastResult = GetLastStatus(); 450 | if (OldlastResult == Gdiplus::Ok) { 451 | GUID guid; 452 | if (GetRawFormat(&guid) == Gdiplus::Ok) { 453 | } 454 | } 455 | else { 456 | lastResult = OldlastResult; 457 | } 458 | } 459 | BitmapEx(const WCHAR* filename) 460 | : Gdiplus::Bitmap::Bitmap(filename) 461 | , m_lpByte(0), m_nSize(0) { 462 | if (GetLastStatus() == Gdiplus::Ok) { 463 | GUID guid; 464 | if (GetRawFormat(&guid) == Gdiplus::Ok) { 465 | if (guid == Gdiplus::ImageFormatGIF) { 466 | UINT count = GetFrameDimensionsCount(); 467 | GUID* pDimensionIDs = new GUID[count]; 468 | GetFrameDimensionsList(pDimensionIDs, count); 469 | int nFrameCount = GetFrameCount(&pDimensionIDs[0]); 470 | delete[]pDimensionIDs; 471 | if (nFrameCount > 1) { 472 | HANDLE hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 473 | if (hFile != INVALID_HANDLE_VALUE) { 474 | DWORD dwReadSize; 475 | m_nSize = GetFileSize(hFile, 0); 476 | m_lpByte = (LPBYTE)GlobalAlloc(0, m_nSize); 477 | ReadFile(hFile, m_lpByte, m_nSize, &dwReadSize, 0); 478 | CloseHandle(hFile); 479 | } 480 | } 481 | } 482 | } 483 | } 484 | else { 485 | lastResult = Gdiplus::UnknownImageFormat; 486 | } 487 | } 488 | virtual ~BitmapEx() { 489 | GlobalFree(m_lpByte); 490 | m_lpByte = 0; 491 | } 492 | }; 493 | 494 | Gdiplus::Bitmap* LoadBitmapFromResource(int nID, LPCWSTR lpszType) 495 | { 496 | Gdiplus::Bitmap* pBitmap = 0; 497 | const HINSTANCE hInstance = GetModuleHandle(0); 498 | const HRSRC hResource = FindResourceW(hInstance, MAKEINTRESOURCE(nID), lpszType); 499 | if (!hResource) 500 | return 0; 501 | const DWORD dwImageSize = SizeofResource(hInstance, hResource); 502 | if (!dwImageSize) 503 | return 0; 504 | const void* pResourceData = LockResource(LoadResource(hInstance, hResource)); 505 | if (!pResourceData) 506 | return 0; 507 | const HGLOBAL hBuffer = GlobalAlloc(GMEM_MOVEABLE, dwImageSize); 508 | if (hBuffer) { 509 | void* pBuffer = GlobalLock(hBuffer); 510 | if (pBuffer) { 511 | CopyMemory(pBuffer, pResourceData, dwImageSize); 512 | IStream* pStream = NULL; 513 | if (CreateStreamOnHGlobal(hBuffer, TRUE, &pStream) == S_OK) { 514 | pBitmap = Gdiplus::Bitmap::FromStream(pStream); 515 | if (pBitmap) { 516 | if (pBitmap->GetLastStatus() != Gdiplus::Ok) { 517 | delete pBitmap; 518 | pBitmap = NULL; 519 | } 520 | } 521 | pStream->Release(); 522 | } 523 | GlobalUnlock(hBuffer); 524 | } 525 | } 526 | return pBitmap; 527 | } 528 | 529 | BitmapEx* WindowCapture(HWND hWnd) 530 | { 531 | BitmapEx* pBitmap = 0; 532 | RECT rect1; 533 | GetWindowRect(hWnd, &rect1); 534 | RECT rect2; 535 | if (DwmGetWindowAttribute(hWnd, DWMWA_EXTENDED_FRAME_BOUNDS, &rect2, sizeof(rect2)) != S_OK) rect2 = rect1; 536 | HDC hdc = GetDC(0); 537 | HDC hMem = CreateCompatibleDC(hdc); 538 | HBITMAP hBitmap = CreateCompatibleBitmap(hdc, rect2.right - rect2.left, rect2.bottom - rect2.top); 539 | if (hBitmap) { 540 | HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMem, hBitmap); 541 | SetForegroundWindow(hWnd); 542 | InvalidateRect(hWnd, 0, 1); 543 | UpdateWindow(hWnd); 544 | BitBlt(hMem, 0, 0, rect2.right - rect2.left, rect2.bottom - rect2.top, hdc, rect2.left, rect2.top, SRCCOPY); 545 | pBitmap = new BitmapEx(hBitmap); 546 | SelectObject(hMem, hOldBitmap); 547 | DeleteObject(hBitmap); 548 | } 549 | DeleteDC(hMem); 550 | ReleaseDC(0, hdc); 551 | return pBitmap; 552 | } 553 | 554 | BitmapEx* ScreenCapture(LPRECT lpRect) 555 | { 556 | BitmapEx* pBitmap = 0; 557 | HDC hdc = GetDC(0); 558 | HDC hMem = CreateCompatibleDC(hdc); 559 | HBITMAP hBitmap = CreateCompatibleBitmap(hdc, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top); 560 | if (hBitmap) { 561 | HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMem, hBitmap); 562 | BitBlt(hMem, 0, 0, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, hdc, lpRect->left, lpRect->top, SRCCOPY); 563 | pBitmap = new BitmapEx(hBitmap); 564 | SelectObject(hMem, hOldBitmap); 565 | DeleteObject(hBitmap); 566 | } 567 | DeleteDC(hMem); 568 | ReleaseDC(0, hdc); 569 | return pBitmap; 570 | } 571 | 572 | LRESULT CALLBACK LayerWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 573 | { 574 | static HWND hParentWnd; 575 | static BOOL bDrag; 576 | static BOOL bDown; 577 | static POINT posStart; 578 | static RECT OldRect; 579 | switch (msg) { 580 | case WM_CREATE: 581 | hParentWnd = (HWND)((LPCREATESTRUCT)lParam)->lpCreateParams; 582 | break; 583 | case WM_KEYDOWN: 584 | case WM_RBUTTONDOWN: 585 | SendMessage(hWnd, WM_CLOSE, 0, 0); 586 | break; 587 | case WM_LBUTTONDOWN: 588 | { 589 | int xPos = GET_X_LPARAM(lParam); 590 | int yPos = GET_Y_LPARAM(lParam); 591 | POINT point = { xPos, yPos }; 592 | ClientToScreen(hWnd, &point); 593 | posStart = point; 594 | SetCapture(hWnd); 595 | } 596 | break; 597 | case WM_MOUSEMOVE: 598 | if (GetCapture() == hWnd) 599 | { 600 | int xPos = GET_X_LPARAM(lParam); 601 | int yPos = GET_Y_LPARAM(lParam); 602 | POINT point = { xPos, yPos }; 603 | ClientToScreen(hWnd, &point); 604 | if (!bDrag) { 605 | if (abs(xPos - posStart.x) > GetSystemMetrics(SM_CXDRAG) && abs(yPos - posStart.y) > GetSystemMetrics(SM_CYDRAG)) { 606 | bDrag = TRUE; 607 | } 608 | } 609 | else { 610 | HDC hdc = GetDC(hWnd); 611 | RECT rect = { min(point.x, posStart.x), min(point.y, posStart.y), max(point.x, posStart.x), max(point.y, posStart.y) }; 612 | OffsetRect(&rect, -GetSystemMetrics(SM_XVIRTUALSCREEN), -GetSystemMetrics(SM_YVIRTUALSCREEN)); 613 | HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 0)); 614 | HRGN hRgn1 = CreateRectRgn(OldRect.left, OldRect.top, OldRect.right, OldRect.bottom); 615 | HRGN hRgn2 = CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom); 616 | CombineRgn(hRgn1, hRgn1, hRgn2, RGN_DIFF); 617 | FillRgn(hdc, hRgn1, (HBRUSH)GetStockObject(BLACK_BRUSH)); 618 | FillRect(hdc, &rect, hBrush); 619 | OldRect = rect; 620 | DeleteObject(hBrush); 621 | DeleteObject(hRgn1); 622 | DeleteObject(hRgn2); 623 | ReleaseDC(hWnd, hdc); 624 | } 625 | } 626 | break; 627 | case WM_LBUTTONUP: 628 | if (GetCapture() == hWnd) { 629 | ReleaseCapture(); 630 | Gdiplus::Bitmap* pBitmap = 0; 631 | if (bDrag) { 632 | bDrag = FALSE; 633 | int xPos = GET_X_LPARAM(lParam); 634 | int yPos = GET_Y_LPARAM(lParam); 635 | POINT point = { xPos, yPos }; 636 | ClientToScreen(hWnd, &point); 637 | RECT rect = { min(point.x, posStart.x), min(point.y, posStart.y), max(point.x, posStart.x), max(point.y, posStart.y) }; 638 | ShowWindow(hWnd, SW_HIDE); 639 | pBitmap = ScreenCapture(&rect); 640 | } 641 | else { 642 | ShowWindow(hWnd, SW_HIDE); 643 | HWND hTargetWnd = WindowFromPoint(posStart); 644 | hTargetWnd = GetAncestor(hTargetWnd, GA_ROOT); 645 | if (hTargetWnd) { 646 | pBitmap = WindowCapture(hTargetWnd); 647 | } 648 | } 649 | SendMessage(hParentWnd, WM_APP, 0, (LPARAM)pBitmap); 650 | } 651 | break; 652 | default: 653 | return DefWindowProc(hWnd, msg, wParam, lParam); 654 | } 655 | return 0; 656 | } 657 | 658 | class ImageListPanel { 659 | BOOL m_bDrag; 660 | int m_nDragIndex; 661 | int m_nSplitPrevIndex; 662 | int m_nSplitPrevPosX; 663 | int m_nMargin; 664 | int m_nImageMaxCount; 665 | HFONT m_hFont; 666 | std::list m_listBitmap; 667 | WNDPROC fnWndProc; 668 | Gdiplus::Bitmap* m_pCameraIcon; 669 | BOOL MoveImage(int nIndexFrom, int nIndexTo) { 670 | if (nIndexFrom < 0) nIndexFrom = 0; 671 | if (nIndexTo < 0) nIndexTo = 0; 672 | if (nIndexFrom == nIndexTo) return FALSE; 673 | std::list::iterator itFrom = m_listBitmap.begin(); 674 | std::list::iterator itTo = m_listBitmap.begin(); 675 | std::advance(itFrom, nIndexFrom); 676 | std::advance(itTo, nIndexTo); 677 | m_listBitmap.splice(itTo, m_listBitmap, itFrom); 678 | return TRUE; 679 | } 680 | static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { 681 | if (msg == WM_NCCREATE) { 682 | SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)((LPCREATESTRUCT)lParam)->lpCreateParams); 683 | return TRUE; 684 | } 685 | ImageListPanel* _this = (ImageListPanel*)GetWindowLongPtr(hWnd, GWLP_USERDATA); 686 | if (_this) { 687 | switch (msg) { 688 | case WM_DROPFILES: 689 | { 690 | HDROP hDrop = (HDROP)wParam; 691 | WCHAR szFileName[MAX_PATH]; 692 | UINT iFile, nFiles; 693 | nFiles = DragQueryFile((HDROP)hDrop, 0xFFFFFFFF, NULL, 0); 694 | BOOL bUpdate = FALSE; 695 | for (iFile = 0; iFile < nFiles; ++iFile) { 696 | if ((int)_this->m_listBitmap.size() >= _this->m_nImageMaxCount) break; 697 | DragQueryFileW(hDrop, iFile, szFileName, _countof(szFileName)); 698 | BitmapEx* pBitmap = new BitmapEx(szFileName); 699 | if (pBitmap) { 700 | if (pBitmap->GetLastStatus() == Gdiplus::Ok) { 701 | _this->m_listBitmap.push_back(pBitmap); 702 | bUpdate = TRUE; 703 | } 704 | else { 705 | delete pBitmap; 706 | } 707 | } 708 | } 709 | DragFinish(hDrop); 710 | if (bUpdate) 711 | InvalidateRect(hWnd, 0, 1); 712 | } 713 | return 0; 714 | case WM_PAINT: 715 | { 716 | PAINTSTRUCT ps; 717 | HDC hdc = BeginPaint(hWnd, &ps); 718 | { 719 | RECT rect; 720 | GetClientRect(hWnd, &rect); 721 | INT nLeft = _this->m_nMargin; 722 | Gdiplus::Graphics g(hdc); 723 | int nHeight1 = rect.bottom - 2 * _this->m_nMargin; 724 | Gdiplus::StringFormat f; 725 | f.SetAlignment(Gdiplus::StringAlignmentCenter); 726 | f.SetLineAlignment(Gdiplus::StringAlignmentCenter); 727 | if (_this->m_listBitmap.size() == 0) { 728 | Gdiplus::Font font(hdc, _this->m_hFont); 729 | Gdiplus::RectF rectf((Gdiplus::REAL)0, (Gdiplus::REAL)0, (Gdiplus::REAL)rect.right, (Gdiplus::REAL)rect.bottom); 730 | g.DrawString(L"画像をドロップ または クリックして画像を選択", -1, &font, rectf, &f, &Gdiplus::SolidBrush(Gdiplus::Color::MakeARGB(128, 0, 0, 0))); 731 | } 732 | else { 733 | Gdiplus::Font font(&Gdiplus::FontFamily(L"Marlett"), 11, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); 734 | for (auto bitmap : _this->m_listBitmap) { 735 | int nWidth = bitmap->GetWidth() * nHeight1 / bitmap->GetHeight(); 736 | g.DrawImage(bitmap, nLeft, _this->m_nMargin, nWidth, nHeight1); 737 | Gdiplus::RectF rectf((Gdiplus::REAL)(nLeft + nWidth - 16), (Gdiplus::REAL)(_this->m_nMargin), (Gdiplus::REAL)(16), (Gdiplus::REAL)(16)); 738 | g.FillRectangle(&Gdiplus::SolidBrush(Gdiplus::Color::MakeARGB(192, 255, 255, 255)), rectf); 739 | g.DrawString(L"r", 1, &font, rectf, &f, &Gdiplus::SolidBrush(Gdiplus::Color::MakeARGB(192, 0, 0, 0))); 740 | nLeft += nWidth + _this->m_nMargin; 741 | } 742 | } 743 | int nCameraIconWidth = _this->m_pCameraIcon->GetWidth(); 744 | int nCameraIconHeigth = _this->m_pCameraIcon->GetHeight(); 745 | g.DrawImage(_this->m_pCameraIcon, rect.right - nCameraIconWidth - 2, rect.bottom - nCameraIconHeigth - 2, nCameraIconWidth, nCameraIconHeigth); 746 | } 747 | EndPaint(hWnd, &ps); 748 | } 749 | return 0; 750 | case WM_APP: 751 | { 752 | BitmapEx* pBitmap = (BitmapEx*)lParam; 753 | BOOL bPushed = FALSE; 754 | if ((int)_this->m_listBitmap.size() < _this->m_nImageMaxCount) { 755 | if (pBitmap) { 756 | _this->m_listBitmap.push_back(pBitmap); 757 | InvalidateRect(hWnd, 0, 1); 758 | bPushed = TRUE; 759 | } 760 | } 761 | if (!bPushed) 762 | delete pBitmap; 763 | SetForegroundWindow(hWnd); 764 | } 765 | break; 766 | case WM_LBUTTONDOWN: 767 | { 768 | RECT rect; 769 | GetClientRect(hWnd, &rect); 770 | POINT point = { LOWORD(lParam), HIWORD(lParam) }; 771 | int nCameraIconWidth = _this->m_pCameraIcon->GetWidth(); 772 | int nCameraIconHeigth = _this->m_pCameraIcon->GetHeight(); 773 | RECT rectCameraIcon = { rect.right - nCameraIconWidth - 2, rect.bottom - nCameraIconHeigth - 2, rect.right, rect.bottom }; 774 | if (PtInRect(&rectCameraIcon, point)) { 775 | HWND hLayerWnd = CreateWindowExW(WS_EX_LAYERED | WS_EX_TOPMOST, L"LayerWindow", 0, WS_POPUP, 0, 0, 0, 0, 0, 0, GetModuleHandle(0), (LPVOID)hWnd); 776 | SetLayeredWindowAttributes(hLayerWnd, RGB(255, 0, 0), 64, LWA_ALPHA | LWA_COLORKEY); 777 | SetWindowPos(hLayerWnd, HWND_TOPMOST, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN), GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN), SWP_NOSENDCHANGING); 778 | ShowWindow(hLayerWnd, SW_NORMAL); 779 | UpdateWindow(hLayerWnd); 780 | return 0; 781 | } 782 | INT nLeft = _this->m_nMargin; 783 | int nHeight1 = rect.bottom - 2 * _this->m_nMargin; 784 | for (auto it = _this->m_listBitmap.begin(); it != _this->m_listBitmap.end(); ++it) { 785 | int nWidth1 = (*it)->GetWidth() * nHeight1 / (*it)->GetHeight(); 786 | RECT rectCloseButton = { nLeft + nWidth1 - 16, _this->m_nMargin, nLeft + nWidth1, _this->m_nMargin + 16}; 787 | if (PtInRect(&rectCloseButton, point)) { 788 | delete* it; 789 | *it = 0; 790 | _this->m_listBitmap.erase(it); 791 | InvalidateRect(hWnd, 0, 1); 792 | return 0; 793 | } 794 | nLeft += nWidth1 + _this->m_nMargin; 795 | } 796 | nLeft = _this->m_nMargin; 797 | int nIndex = 0; 798 | for (auto it = _this->m_listBitmap.begin(); it != _this->m_listBitmap.end(); ++it) { 799 | int nWidth1 = (*it)->GetWidth() * nHeight1 / (*it)->GetHeight(); 800 | RECT rectImage = { nLeft, _this->m_nMargin, nLeft + nWidth1, _this->m_nMargin + nWidth1 }; 801 | if (PtInRect(&rectImage, point)) { 802 | _this->m_bDrag = TRUE; 803 | SetCapture(hWnd); 804 | _this->m_nDragIndex = nIndex; 805 | return 0; 806 | } 807 | nLeft += nWidth1 + _this->m_nMargin; 808 | ++nIndex; 809 | } 810 | if ((int)_this->m_listBitmap.size() < _this->m_nImageMaxCount) { 811 | WCHAR szFileName[MAX_PATH] = { 0 }; 812 | OPENFILENAMEW of = { sizeof(OPENFILENAME) }; 813 | WCHAR szMyDocumentFolder[MAX_PATH]; 814 | SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, NULL, szMyDocumentFolder);// 815 | PathAddBackslashW(szMyDocumentFolder); 816 | of.hwndOwner = hWnd; 817 | of.lpstrFilter = L"画像ファイル\0*.png;*.gif;*.jpg;*.jpeg;*.bmp;*.tif;*.ico;*.emf;*.wmf;\0すべてのファイル(*.*)\0*.*\0\0"; 818 | of.lpstrFile = szFileName; 819 | of.nMaxFile = MAX_PATH; 820 | of.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; 821 | of.lpstrTitle = L"画像ファイルを開く"; 822 | of.lpstrInitialDir = szMyDocumentFolder; 823 | if (GetOpenFileNameW(&of)) { 824 | BitmapEx* pBitmap = new BitmapEx(szFileName); 825 | if (pBitmap) { 826 | if (pBitmap->GetLastStatus() == Gdiplus::Ok) { 827 | _this->m_listBitmap.push_back(pBitmap); 828 | InvalidateRect(hWnd, 0, 1); 829 | } 830 | else { 831 | delete pBitmap; 832 | } 833 | } 834 | } 835 | } 836 | } 837 | return 0; 838 | case WM_MOUSEMOVE: 839 | if (_this->m_bDrag) { 840 | RECT rect; 841 | GetClientRect(hWnd, &rect); 842 | INT nCursorX = LOWORD(lParam); 843 | INT nLeft = 0; 844 | int nHeight1 = rect.bottom - 2 * _this->m_nMargin; 845 | int nIndex = 0; 846 | for (auto it = _this->m_listBitmap.begin(); it != _this->m_listBitmap.end(); ++it) { 847 | int nWidth1 = (*it)->GetWidth() * nHeight1 / (*it)->GetHeight(); 848 | RECT rectImage = { nLeft, 0, nLeft + nWidth1 + _this->m_nMargin , rect.bottom}; 849 | if (nCursorX >= nLeft && (nIndex + 1 == _this->m_listBitmap.size() || nCursorX < nLeft + nWidth1 + _this->m_nMargin)) { 850 | int nCurrentIndex; 851 | int nCurrentPosX; 852 | if (nCursorX < nLeft + nWidth1 / 2 + _this->m_nMargin) { 853 | nCurrentIndex = nIndex; 854 | nCurrentPosX = nLeft; 855 | } 856 | else { 857 | nCurrentIndex = nIndex + 1; 858 | nCurrentPosX = nLeft + nWidth1 + _this->m_nMargin; 859 | } 860 | if (nCurrentIndex != _this->m_nSplitPrevIndex) { 861 | HDC hdc = GetDC(hWnd); 862 | if (_this->m_nSplitPrevIndex != -1) 863 | PatBlt(hdc, _this->m_nSplitPrevPosX, 0, _this->m_nMargin, rect.bottom, PATINVERT); 864 | PatBlt(hdc, nCurrentPosX, 0, _this->m_nMargin, rect.bottom, PATINVERT); 865 | ReleaseDC(hWnd, hdc); 866 | _this->m_nSplitPrevIndex = nCurrentIndex; 867 | _this->m_nSplitPrevPosX = nCurrentPosX; 868 | } 869 | return 0; 870 | } 871 | nLeft += nWidth1 + _this->m_nMargin; 872 | ++nIndex; 873 | } 874 | } 875 | return 0; 876 | case WM_LBUTTONUP: 877 | if (_this->m_bDrag) { 878 | ReleaseCapture(); 879 | _this->m_bDrag = FALSE; 880 | if (_this->m_nSplitPrevIndex != -1) { 881 | RECT rect; 882 | GetClientRect(hWnd, &rect); 883 | HDC hdc = GetDC(hWnd); 884 | PatBlt(hdc, _this->m_nSplitPrevPosX, 0, _this->m_nMargin, rect.bottom, PATINVERT); 885 | ReleaseDC(hWnd, hdc); 886 | if (_this->MoveImage(_this->m_nDragIndex, _this->m_nSplitPrevIndex)) { 887 | InvalidateRect(hWnd, 0, 1); 888 | } 889 | _this->m_nSplitPrevIndex = -1; 890 | } 891 | } 892 | return 0; 893 | } 894 | } 895 | return DefWindowProc(hWnd, msg, wParam, lParam); 896 | } 897 | void RemoveAllImage() { 898 | for (auto& bitmap : m_listBitmap) { 899 | delete bitmap; 900 | bitmap = 0; 901 | } 902 | m_listBitmap.clear(); 903 | } 904 | public: 905 | HWND m_hWnd; 906 | ImageListPanel(int nImageMaxCount, DWORD dwStyle, int x, int y, int width, int height, HWND hParent, HFONT hFont) 907 | : m_nImageMaxCount(nImageMaxCount) 908 | , m_hWnd(0) 909 | , fnWndProc(0) 910 | , m_nMargin(4) 911 | , m_bDrag(0) 912 | , m_nSplitPrevIndex(-1) 913 | , m_nSplitPrevPosX(0) 914 | , m_hFont(hFont) 915 | , m_pCameraIcon(0) { 916 | m_pCameraIcon = LoadBitmapFromResource(IDB_PNG1, L"PNG"); 917 | WNDCLASSW wndclass1 = { 0,LayerWndProc,0,0,GetModuleHandle(0),0,LoadCursor(0,IDC_CROSS),(HBRUSH)GetStockObject(BLACK_BRUSH),0,L"LayerWindow" }; 918 | RegisterClassW(&wndclass1); 919 | WNDCLASSW wndclass2 = { CS_HREDRAW | CS_VREDRAW,WndProc,0,0,GetModuleHandle(0),0,LoadCursor(0,IDC_ARROW),(HBRUSH)(COLOR_WINDOW + 1),0,__FUNCTIONW__ }; 920 | RegisterClassW(&wndclass2); 921 | m_hWnd = CreateWindowW(__FUNCTIONW__, 0, dwStyle, x, y, width, height, hParent, 0, GetModuleHandle(0), this); 922 | } 923 | ~ImageListPanel() { 924 | RemoveAllImage(); 925 | delete m_pCameraIcon; 926 | } 927 | int GetImageCount() { return (int)m_listBitmap.size(); } 928 | BitmapEx* GetImage(int nIndex) { 929 | std::list::iterator it = m_listBitmap.begin(); 930 | std::advance(it, nIndex); 931 | return *it; 932 | } 933 | void ResetContent() { 934 | RemoveAllImage(); 935 | InvalidateRect(m_hWnd, 0, 1); 936 | } 937 | }; 938 | 939 | BOOL GetEncoderClsid(LPCWSTR format, CLSID* pClsid) { 940 | UINT num = 0, size = 0; 941 | Gdiplus::GetImageEncodersSize(&num, &size); 942 | if (size == 0) return FALSE; 943 | Gdiplus::ImageCodecInfo* pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(GlobalAlloc(0, size)); 944 | if (pImageCodecInfo == NULL) return FALSE; 945 | GetImageEncoders(num, size, pImageCodecInfo); 946 | for (UINT i = 0; i < num; ++i) { 947 | if (wcscmp(pImageCodecInfo[i].MimeType, format) == 0) { 948 | *pClsid = pImageCodecInfo[i].Clsid; 949 | GlobalFree(pImageCodecInfo); 950 | return TRUE; 951 | } 952 | } 953 | GlobalFree(pImageCodecInfo); 954 | return FALSE; 955 | } 956 | 957 | LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 958 | { 959 | static HWND hEditConsumerKey; 960 | static HWND hEditConsumerSecret; 961 | static HWND hEditAccessToken; 962 | static HWND hEditAccessTokenSecret; 963 | static HWND hEditMessage; 964 | static ImageListPanel* pImageListPanel; 965 | static HWND hButton; 966 | static HFONT hFont; 967 | switch (msg) 968 | { 969 | case WM_CREATE: 970 | hFont = CreateFontW(22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Yu Gothic UI"); 971 | hEditConsumerKey = CreateWindowEx(0, L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); 972 | SendMessage(hEditConsumerKey, EM_SETCUEBANNER, TRUE, (LPARAM)L"Consumer Key"); 973 | SendMessage(hEditConsumerKey, WM_SETFONT, (WPARAM)hFont, 0); 974 | hEditConsumerSecret = CreateWindowEx(0, L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); 975 | SendMessage(hEditConsumerSecret, EM_SETCUEBANNER, TRUE, (LPARAM)L"Consumer Secret"); 976 | SendMessage(hEditConsumerSecret, WM_SETFONT, (WPARAM)hFont, 0); 977 | hEditAccessToken = CreateWindowEx(0, L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); 978 | SendMessage(hEditAccessToken, EM_SETCUEBANNER, TRUE, (LPARAM)L"Access Token"); 979 | SendMessage(hEditAccessToken, WM_SETFONT, (WPARAM)hFont, 0); 980 | hEditAccessTokenSecret = CreateWindowEx(0, L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); 981 | SendMessage(hEditAccessTokenSecret, EM_SETCUEBANNER, TRUE, (LPARAM)L"Access Token Secret"); 982 | SendMessage(hEditAccessTokenSecret, WM_SETFONT, (WPARAM)hFont, 0); 983 | hEditMessage = CreateWindowEx(0, L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); 984 | SendMessage(hEditMessage, WM_SETFONT, (WPARAM)hFont, 0); 985 | pImageListPanel = new ImageListPanel(4, WS_VISIBLE | WS_CHILD | WS_BORDER, 0, 0, 0, 0, hWnd, hFont); 986 | hButton = CreateWindow(L"BUTTON", L"ポスト", WS_VISIBLE | WS_CHILD | WS_TABSTOP, 0, 0, 0, 0, hWnd, (HMENU)IDOK, ((LPCREATESTRUCT)lParam)->hInstance, 0); 987 | SendMessage(hButton, WM_SETFONT, (WPARAM)hFont, 0); 988 | DragAcceptFiles(hWnd, TRUE); 989 | break; 990 | 991 | case WM_DROPFILES: 992 | if (pImageListPanel) { 993 | SendMessageW(pImageListPanel->m_hWnd, msg, wParam, lParam); 994 | } 995 | break; 996 | case WM_SIZE: 997 | MoveWindow(hEditConsumerKey, 10, 10, 512, 32, TRUE); 998 | MoveWindow(hEditConsumerSecret, 10, 50, 512, 32, TRUE); 999 | MoveWindow(hEditAccessToken, 10, 90, 512, 32, TRUE); 1000 | MoveWindow(hEditAccessTokenSecret, 10, 130, 512, 32, TRUE); 1001 | MoveWindow(hEditMessage, 10, 170, 512, 256 - 64 - 8, TRUE); 1002 | MoveWindow(pImageListPanel->m_hWnd, 10, 170 + 256 - 64 - 8 + 8, 512, 64, TRUE); 1003 | MoveWindow(hButton, 10, 238 + 256 - 64 - 8 + 11, 512, 32, TRUE); 1004 | break; 1005 | case WM_COMMAND: 1006 | if (LOWORD(wParam) == IDOK) { 1007 | CHAR szConsumerKey[256]; 1008 | CHAR szConsumerSecret[256]; 1009 | CHAR szAccessTokenKey[256]; 1010 | CHAR szAccessTokenSecret[256]; 1011 | 1012 | GetWindowTextA(hEditConsumerKey, szConsumerKey, _countof(szConsumerKey)); 1013 | GetWindowTextA(hEditConsumerSecret, szConsumerSecret, _countof(szConsumerSecret)); 1014 | GetWindowTextA(hEditAccessToken, szAccessTokenKey, _countof(szAccessTokenKey)); 1015 | GetWindowTextA(hEditAccessTokenSecret, szAccessTokenSecret, _countof(szAccessTokenSecret)); 1016 | 1017 | std::map m; 1018 | 1019 | std::vector media_ids; 1020 | 1021 | int nImageCount = pImageListPanel->GetImageCount(); 1022 | 1023 | if (nImageCount > 0) { 1024 | m.clear(); 1025 | m["oauth_consumer_key"] = szConsumerKey; 1026 | LPSTR lpszNonce = CreateRandomString(); 1027 | m["oauth_nonce"] = lpszNonce; 1028 | GlobalFree(lpszNonce); 1029 | m["oauth_signature_method"] = "HMAC-SHA1"; 1030 | CHAR szTimestamp[16] = {}; 1031 | wsprintfA(szTimestamp, "%I64d", GetUnixTime()); 1032 | m["oauth_timestamp"] = szTimestamp; 1033 | m["oauth_version"] = "1.0"; 1034 | m["oauth_token"] = szAccessTokenKey; 1035 | 1036 | LPSTR lpszOAuthParam = CreateOAuthPram(m, "https://upload.twitter.com/1.1/media/upload.json", szConsumerSecret, szAccessTokenSecret, TRUE); 1037 | 1038 | if (lpszOAuthParam) { 1039 | for (int i = 0; i < nImageCount; ++i) { 1040 | BitmapEx* pImage = pImageListPanel->GetImage(i); 1041 | GUID guid1; 1042 | LPWSTR lpszMediaType; 1043 | if (pImage->GetRawFormat(&guid1) != Gdiplus::Ok) continue; 1044 | if (guid1 == Gdiplus::ImageFormatGIF && pImage->m_lpByte) { 1045 | lpszMediaType = L"image/gif"; 1046 | } 1047 | else if (guid1 == Gdiplus::ImageFormatJPEG || guid1 == Gdiplus::ImageFormatEXIF) { 1048 | lpszMediaType = L"image/jpeg"; 1049 | } 1050 | else { 1051 | lpszMediaType = L"image/png"; 1052 | } 1053 | GUID guid2; 1054 | GetEncoderClsid(lpszMediaType, &guid2); 1055 | 1056 | std::string media_id; 1057 | 1058 | if (pImage->m_lpByte) { 1059 | media_id = image_upload(hWnd, lpszOAuthParam, pImage->m_lpByte); 1060 | } 1061 | else { 1062 | IStream* pStream = NULL; 1063 | if (CreateStreamOnHGlobal(NULL, TRUE, &pStream) == S_OK) { 1064 | if (pImage->Save(pStream, &guid2) == S_OK) { 1065 | ULARGE_INTEGER ulnSize; 1066 | LARGE_INTEGER lnOffset; 1067 | lnOffset.QuadPart = 0; 1068 | if (pStream->Seek(lnOffset, STREAM_SEEK_END, &ulnSize) == S_OK) { 1069 | if (pStream->Seek(lnOffset, STREAM_SEEK_SET, NULL) == S_OK) { 1070 | LPBYTE baPicture = (LPBYTE)GlobalAlloc(0, (SIZE_T)ulnSize.QuadPart); 1071 | ULONG ulBytesRead; 1072 | pStream->Read(baPicture, (ULONG)ulnSize.QuadPart, &ulBytesRead); 1073 | media_id = image_upload(hWnd, lpszOAuthParam, baPicture); 1074 | GlobalFree(baPicture); 1075 | } 1076 | } 1077 | } 1078 | pStream->Release(); 1079 | } 1080 | } 1081 | if (!media_id.empty()) { 1082 | media_ids.push_back(media_id); 1083 | } 1084 | else { 1085 | WCHAR szText[512]; 1086 | wsprintf(szText, TEXT("投稿に失敗しました。\r\n%d 番目の添付メディアのアップロードに失敗しました。"), i + 1); 1087 | MessageBoxW(hWnd, szText, L"確認", MB_ICONHAND); 1088 | GlobalFree(lpszOAuthParam); 1089 | return 0; 1090 | } 1091 | } 1092 | GlobalFree(lpszOAuthParam); 1093 | } 1094 | } 1095 | 1096 | m.clear(); 1097 | m["oauth_consumer_key"] = szConsumerKey; 1098 | LPSTR lpszNonce = CreateRandomString(); 1099 | m["oauth_nonce"] = lpszNonce; 1100 | GlobalFree(lpszNonce); 1101 | m["oauth_signature_method"] = "HMAC-SHA1"; 1102 | CHAR szTimestamp[16] = {}; 1103 | wsprintfA(szTimestamp, "%I64d", GetUnixTime()); 1104 | m["oauth_timestamp"] = szTimestamp; 1105 | m["oauth_version"] = "1.0"; 1106 | m["oauth_token"] = szAccessTokenKey; 1107 | 1108 | LPSTR lpszOAuthParam = CreateOAuthPram(m, "https://api.x.com/2/tweets", szConsumerSecret, szAccessTokenSecret, TRUE); 1109 | if (lpszOAuthParam) { 1110 | std::string id; 1111 | DWORD size = GetWindowTextLength(hEditMessage); 1112 | LPWSTR lpszMessageW = (LPWSTR)GlobalAlloc(0, sizeof(WCHAR) * (size + 1)); 1113 | if (lpszMessageW) { 1114 | GetWindowText(hEditMessage, lpszMessageW, size + 1); 1115 | size = WideCharToMultiByte(CP_UTF8, 0, lpszMessageW, -1, 0, 0, 0, 0); 1116 | LPSTR lpszMessageA = (LPSTR)GlobalAlloc(GPTR, size); 1117 | if (lpszMessageA) { 1118 | WideCharToMultiByte(CP_UTF8, 0, lpszMessageW, -1, lpszMessageA, size, 0, 0); 1119 | id = tweet(hWnd, lpszOAuthParam, lpszMessageA, media_ids); 1120 | GlobalFree(lpszMessageA); 1121 | } 1122 | GlobalFree(lpszMessageW); 1123 | } 1124 | 1125 | if (!id.empty()) 1126 | { 1127 | std::string message; 1128 | message = "ポストされました(id:"; 1129 | message += id; 1130 | message += ")"; 1131 | MessageBoxA(hWnd, message.c_str(), "成功", MB_OK); 1132 | } 1133 | 1134 | GlobalFree(lpszOAuthParam); 1135 | } 1136 | } 1137 | break; 1138 | case WM_CLOSE: 1139 | DestroyWindow(hWnd); 1140 | break; 1141 | case WM_DESTROY: 1142 | delete pImageListPanel; 1143 | DeleteObject(hFont); 1144 | PostQuitMessage(0); 1145 | break; 1146 | default: 1147 | return DefDlgProc(hWnd, msg, wParam, lParam); 1148 | } 1149 | return 0; 1150 | } 1151 | 1152 | int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nShowCmd) 1153 | { 1154 | ULONG_PTR gdiToken; 1155 | GdiplusStartupInput gdiSI; 1156 | GdiplusStartup(&gdiToken, &gdiSI, NULL); 1157 | 1158 | MSG msg; 1159 | WNDCLASS wndclass = { 1160 | CS_HREDRAW | CS_VREDRAW, 1161 | WndProc, 1162 | 0, 1163 | DLGWINDOWEXTRA, 1164 | hInstance, 1165 | 0, 1166 | LoadCursor(0,IDC_ARROW), 1167 | 0, 1168 | 0, 1169 | szClassName 1170 | }; 1171 | RegisterClass(&wndclass); 1172 | 1173 | RECT rect = { 0,0,532,475 }; 1174 | AdjustWindowRect(&rect, WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN, FALSE); 1175 | 1176 | HWND hWnd = CreateWindow( 1177 | szClassName, 1178 | TEXT("Xにポストする"), 1179 | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN, 1180 | CW_USEDEFAULT, 1181 | 0, 1182 | rect.right - rect.left, 1183 | rect.bottom - rect.top, 1184 | 0, 1185 | 0, 1186 | hInstance, 1187 | 0 1188 | ); 1189 | ShowWindow(hWnd, SW_SHOWDEFAULT); 1190 | UpdateWindow(hWnd); 1191 | while (GetMessage(&msg, 0, 0, 0)) { 1192 | if (!IsDialogMessage(hWnd, &msg)) { 1193 | TranslateMessage(&msg); 1194 | DispatchMessage(&msg); 1195 | } 1196 | } 1197 | GdiplusShutdown(gdiToken); 1198 | return (int)msg.wParam; 1199 | } 1200 | -------------------------------------------------------------------------------- /camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/tweet2/77c0d19d9cbd77094eabdc8dc8ff2590f2ed1b70/camera.png -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/tweet2/77c0d19d9cbd77094eabdc8dc8ff2590f2ed1b70/resource.h -------------------------------------------------------------------------------- /tweet2.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/tweet2/77c0d19d9cbd77094eabdc8dc8ff2590f2ed1b70/tweet2.rc -------------------------------------------------------------------------------- /tweet2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tweet2", "tweet2.vcxproj", "{D327119E-D676-4F87-B0AF-08D64AE6AC1A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Debug|x64.ActiveCfg = Debug|x64 17 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Debug|x64.Build.0 = Debug|x64 18 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Debug|x86.ActiveCfg = Debug|Win32 19 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Debug|x86.Build.0 = Debug|Win32 20 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Release|x64.ActiveCfg = Release|x64 21 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Release|x64.Build.0 = Release|x64 22 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Release|x86.ActiveCfg = Release|Win32 23 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /tweet2.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A} 23 | Win32Proj 24 | tweet2 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v143 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v143 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v143 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v143 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | 87 | 88 | Level3 89 | Disabled 90 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 91 | MultiThreadedDebug 92 | 93 | 94 | Windows 95 | true 96 | 97 | 98 | PerMonitorHighDPIAware 99 | 100 | 101 | 102 | 103 | 104 | 105 | Level3 106 | Disabled 107 | _DEBUG;_WINDOWS;%(PreprocessorDefinitions) 108 | MultiThreadedDebug 109 | 110 | 111 | Windows 112 | true 113 | 114 | 115 | PerMonitorHighDPIAware 116 | 117 | 118 | 119 | 120 | Level3 121 | 122 | 123 | MaxSpeed 124 | true 125 | true 126 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 127 | MultiThreaded 128 | 129 | 130 | Windows 131 | true 132 | true 133 | No 134 | 135 | 136 | PerMonitorHighDPIAware 137 | 138 | 139 | 140 | 141 | Level3 142 | 143 | 144 | MaxSpeed 145 | true 146 | true 147 | NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 148 | MultiThreaded 149 | 150 | 151 | Windows 152 | true 153 | true 154 | No 155 | 156 | 157 | PerMonitorHighDPIAware 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /tweet2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | 23 | 24 | ヘッダー ファイル 25 | 26 | 27 | ヘッダー ファイル 28 | 29 | 30 | 31 | 32 | リソース ファイル 33 | 34 | 35 | 36 | 37 | リソース ファイル 38 | 39 | 40 | --------------------------------------------------------------------------------