顯示具有 [Programming]C++ 標籤的文章。 顯示所有文章
顯示具有 [Programming]C++ 標籤的文章。 顯示所有文章

2016年3月4日 星期五

[Linux] How can I get what my main function has returned

Most shells store the exit code of the previous run command in $? so you can store or display it.
$ ./a.out
$ echo $?     # note - after this command $? contains the exit code of echo!
or
$ ./a.out
$ exit_code=$?    # save the exit code in another shell variable.

[Linux] Checking if a directory exists in Unix (system call)

#include <sys/stat.h>

struct stat sb;

if (stat(pathname, &sb) == 0 && S_ISDIR(sb.st_mode))
{
    ...it is a directory...
}

2014年1月1日 星期三

[Win32] 如何列印 %f 的資訊

先用ANSI code function, 再轉成Unicode, 如下:

char tmp[MAX_PATH];
ZeroMemory(tmp, sizeof(char) * MAX_PATH);
sprintf_s(tmp, "[Time Elapsed]: %f sec\n", dwTimeElapsed / 1000.0);
TCHAR tmp1[MAX_PATH];
ZeroMemory(tmp1, sizeof(TCHAR) * MAX_PATH);
wsprintf(tmp1, L"%S", tmp);
OutputDebugString(tmp1);

2013年5月1日 星期三

[Win32, C] Bitmap rendering translucent

BOOL AlphaBlend(
    HDC hdcDest,
    int nXOriginDest,
    int nYOriginDest,
    int nWidthDest,
    int nHeightDest,
    HDC hdcSrc,
    int nXOriginSrc,
    int nYOriginSrc,
    int nWidthSrc,
    int nHeightSrc,
    BLENDFUNCTION blendFunction
);

This function displays bitmaps that have transparent or semitransparent pixels.

Sample
    BLENDFUNCTION bf;
    bf.BlendOp = AC_SRC_OVER;
    bf.BlendFlags = 0;
    bf.SourceConstantAlpha = 127; // Transparency 0-255
    bf.AlphaFormat = 0;

    // hBmpDC for Transparency bitmap handle
    // hDC is background image handle
    AlphaBlend(hDC, 0, 0, 188, 69, hBmpDC, 0, 0, 188, 69, bf);