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

2014年3月3日 星期一

[Win32] How to get the OS Version?

DWORD WINAPI GetVersion(void);

Examples:
#include <windows.h>
#include <stdio.h>

void main()
{
    DWORD dwVersion = 0; 
    DWORD dwMajorVersion = 0;
    DWORD dwMinorVersion = 0; 
    DWORD dwBuild = 0;

    dwVersion = GetVersion();
    // Get the Windows version.

    dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
    dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));

    // Get the build number.

    if (dwVersion < 0x80000000)              
        dwBuild = (DWORD)(HIWORD(dwVersion));

    printf("Version is %d.%d (%d)\n", 
                dwMajorVersion,
                dwMinorVersion,
                dwBuild);
}

Reference:http://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx

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月7日 星期二

[Win32, DXUT] How to hide taskbar and task switcher icon with win32 DXUT

In the main function, i modified the some code:
  LONG _style = GetWindowLong(hWnd, GWL_STYLE);
  LONG _exStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
 
  // remove window frame and window caption
  _style &= ~(WS_CAPTION | WS_THICKFRAME);
  _exStyle |= WS_EX_TOOLWINDOW;
  
  // To remove taskbar item (Very important)
  ShowWindow(hWnd, SW_HIDE); 

  SetWindowLong(hWnd, GWL_STYLE, _style);
  SetWindowLong(hWnd, GWL_EXSTYLE, _exStyle);

  //auto adjust to screen size
  SetWindowPos(hWnd, NULL, 0, 0, GetSystemMetrics(SM_CXSCREEN), 
               GetSystemMetrics(SM_CYSCREEN), 0);
  ShowWindow(hWnd, SW_SHOW);

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);