Skip navigation.

exploreopera

| Help

Sign up | Help

云舒云卷

----我醉欲眠卿且去,明朝有意抱琴来

STICKY POST

DesktopAngel

,

小巧的桌面工具,提高工作效率。:smile:
Newest Version:
DeskAngel.2.0.6.9.7z

Read more...

CD sectors to MM:SS:FF

In CD disc, 1 second can play about 75 frames.
So, if we have a disc with 3,697,696 sectors, what MM:SS:FF is?
  1. How many frames?
    frames = sectors = 3,697,696
  2. How many interge seconds, and how many frames left?
    s = 3697696 / 75 = 49302
    f = 3697696 % 75 = 46
  3. Add two second lead in time
    s = 49304
  4. How many interge minutes, and how many seconds left?
    m = 49304 / 60 = 821
    s = 49304 % 60 = 44

MM:SS:FF = 821:44:46

Get rid of Notepad++ from my all PCs

虽然觉得notepad++是个还不错的软件,但是它的作者在其网站上表达的政治观点让我感到有点恶心。

wildcard search with source code (C language)

Using recursive procedure to deal with the wildcard search. It is too easy to comment.

#include <stdio.h>
#include <string.h>

//
// b_full means the whole string matching
//
bool WildSearch(char *psz_buf, int n_buflen, char *psz_sub, int n_sublen, bool b_full, char sz_prechar)
{
    if (n_buflen == 0 && n_sublen != 0)
    {
        if (n_sublen == 1 && psz_sub[0] == '*')
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else if (n_buflen != 0 && n_sublen == 0)
    {
        if (b_full)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    else if (n_buflen == 0 && n_sublen == 0)
    {
        return true;
    }

    if (psz_sub[0] == '*')
    {
        psz_sub++;
        n_sublen--;
        if (n_sublen == 0)
        {
            return true;
        }
        return WildSearch(psz_buf, n_buflen, psz_sub, n_sublen, b_full, '*');
    }
    else if (psz_sub[0] == '?')
    {
        psz_buf++;
        n_buflen--;
        psz_sub++;
        n_sublen--;
        return WildSearch(psz_buf, n_buflen, psz_sub, n_sublen, b_full, '?');
    }
    else
    {
        char *psz_star_pos = strchr(psz_sub, '*');
        char *psz_question_pos = strchr(psz_sub, '?');
        int n_len_to_star = (psz_star_pos == NULL) ? (int)strlen(psz_sub) : (int)(psz_star_pos - psz_sub);
        int n_len_to_question = (psz_question_pos == NULL) ? (int)strlen(psz_sub) : (int)(psz_question_pos - psz_sub);

        int n_compare_len = n_len_to_question > n_len_to_star ? n_len_to_star : n_len_to_question;
        if (_strnicmp(psz_buf, psz_sub, n_compare_len) == 0)
        //if (psz_buf[0] == psz_sub[0])
        {
            sz_prechar = psz_sub[0];
            psz_buf++;
            n_buflen--;
            psz_sub++;
            n_sublen--;
            return WildSearch(psz_buf, n_buflen, psz_sub, n_sublen, b_full, sz_prechar);
        }
        else
        {
            if (sz_prechar != '*')
            {
                return false;
            }
            psz_buf++;
            n_buflen--;
            return WildSearch(psz_buf, n_buflen, psz_sub, n_sublen, b_full, sz_prechar);
        }
    }
    return true;
}

int main(int argc, char** argv)
{
    char sz_buf[] = "abcdefghijk";
    char sz_sub[] = "abc?e*fg?i?*k*";
    //char sz_sub[] = "ae";

    bool b_result = WildSearch(sz_buf, (int)strlen(sz_buf), sz_sub, (int)strlen(sz_sub), false, ' ');

    printf("%d\n", b_result);

return 0;
}

minirun

, ,

采用主程序和配置程序分离的设计。让运行程序更小巧。包含主程序minirun.exe, tool_add.exe和tool_setting.exe。

minirun是快速启动程序的小工具。
通过预定义的快捷键scroll lock,启动minirun界面。
输入程序路径或别名即可启动程序,无需在快捷方式堆或浏览器中寻找。
输入时会自动匹配别名并自动完成。
TAB键可在匹配的多个别名中进行切换。

tool_add是minirun的辅助工具,用于收集程序并生成配置文件。
启动后选择搜索目录,点击‘add all’,会添加该目录下(包括子目录)所有的可执行文件,并自动创建别名。

tool_setting是配置工具。可以设置呼出主窗口的快捷键和选择语言,设置主窗口颜色等。

minirun.zip

Enable vista style for common controls

, ,

In visual studio 2005, they are several ways to enable it, but all are related to manifest file.
  1. Create a manifest manually with following codes, and input its path to the 'project setting'->'Manifest tool'->'Input and output'->'Additional manifest files':
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="X86"
                publicKeyToken="6595b64144ccf1df"
                language="*"
            />
        </dependentAssembly>
    </dependency>
    </assembly>

  2. Put the following code in the source file:
    #pragma comment(linker, "\"/manifestdependency:type='Win32' name='Test.Research.SampleAssembly' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='0000000000000000' language='*'\"")
    

  3. Put the following code to 'project setting'->'liker'->'Manifest file'->'Additional Manifest Dependencies':
    "name='Microsoft.Windows.Common-Controls' processorArchitecture='x86' version='6.0.0.0' type='win32' publicKeyToken='6595b64144ccf1df'"
    


All in all, DO NOT put the following codes into 'project setting'->'Manifest tool'->'General'->'Assembly Identity':
Microsoft.Windows.Common-Controls, processorArchitecture=x86, version=6.0.0.0, type=win32, publicKeyToken=6595b64144ccf1df

HKM_SETHOTKEY (msdn tells wrong information)

,

In msdn, it says:
wParam
The LOWORD is the virtual key code of the hot key. The HIWORD is the key modifier that indicates the keys that define a hot key combination. ...


It is not the truth.

In HKM_GETHOTKEY Message, it says:
Returns the virtual key code and modifier flags. The virtual key code is in the low-order byte, and the modifier flags are in the high-order byte. ...


So, in the first phase, LOWORD and HIWORD must be LOBYTE and HIBYTE. If you trust the description in msdn, use MAKEWPARAM (instead of MAKEWORD) macro to build the parameter, your hot key control will only display the VK without the modifiers.

EDIT BOX:一行一行显示文本

,

Edit Box是VC中比较阳春的一个控件。当设置了Multiline属性之后,可以显示多行文本——或者更精确的说法是,可以用多行来显示文本。
一般简单的用法如下:
SetDlgItemText(g_hWnd, IDC_EDIT_CONTENT, _T("Hello\r\nWorld!"));


但是,无论是SetDlgItemText/SetWindowTExt/WM_SETTEXT,多无法以如下如下的步骤来实现多行文本:
SetDlgItemText(g_hWnd, IDC_EDIT_CONTENT, _T("Hello\r\n"));
SetDlgItemText(g_hWnd, IDC_EDIT_CONTENT, _T("World!"));


Edit Box不会显示两行文本,而是以第二行替换第一行。

我们可以子类化Edit Box,或是换其他的控件来实现这个功能。但是,其实这样的功能,只要稍微变通一下,Edit Box自身也是可以实现的。
SetDlgItemText(g_hWnd, IDC_EDIT_CONTENT, _T("Hello\r\n"));
int nLen = (int)_tcslen(_T("Hello\r\n"));
SendDlgItemMessage(g_hWnd, IDC_EDIT_CONTENT, EM_SETSEL, nLen, nLen + 1);
SendDlgItemMessage(g_hWnd, IDC_EDIT_CONTENT, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)_T("World!"));

使用EM_SETSELEEM_REPLACESEL就可以实现。
试试看!:smile:

_interlockedbittestandset prototype conflict

If you use vs2005 and platform sdk v6.0, maybe you will encounter a issue as,

c:\program files\microsoft visual studio 8\vc\include\intrin.h(944) :
error C2733: second C linkage of overloaded function '_interlockedbittestandset' not allowed
c:\program files\microsoft visual studio
8\vc\include\intrin.h(944) : see declaration of '_interlockedbittestandset'
c:\program files\microsoft visual studio 8\vc\include\intrin.h(945) :
error C2733: second C linkage of overloaded function '_interlockedbittestandreset' not allowed
c:\program files\microsoft visual studio
8\vc\include\intrin.h(945) : see declaration of '_interlockedbittestandreset'


This error raised because if you use platform sdk v6.0, they will be 4 versions of the function '_interlockedbittestandset',
  1. in vs2005\...\intrin.h
  2. in vs2005\...\winnt.h
  3. sdk v6.0\...\intrin.h
  4. sdk v6.0\...\winnt.h


the first 3 is OK, but in the 4th, MS added 'volatile' for the first parameter of the function,
it causes the issues.

the workaround is simple, like following,
#define _interlockedbittestandset fk_m$_set
#define _interlockedbittestandreset fk_m$_reset
#include <intrin.h>
#undef _interlockedbittestandset
#undef _interlockedbittestandreset

SetLayeredWindowAttributes to Edit only window will fail in non-Window Vista Basic color scheme

using following code to create "edit" control only window:
    HWND hwnd = CreateWindowEx (WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW, 
                  _T("EDIT"), 
                  NULL/*szAppName*/, 
                  WS_POPUP | ES_CENTER,
                  CW_USEDEFAULT, 
                  CW_USEDEFAULT, 
                  CW_USEDEFAULT, 
                  CW_USEDEFAULT, 
                  NULL, 
                  NULL, 
                  hInstance,
                  NULL); 
    OrignalWndProc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WndProc);
    //ShowWindow (hwnd, iCmdShow);
    UpdateWindow (hwnd);
    //SetThemeAppProperties(0);
    SetLayeredWindowAttributes(hwnd, RGB(255, 0, 0), 200, LWA_ALPHA/* | LWA_COLORKEY*/);

Then, swich your color scheme from "Window Aero" to any others, like "Windows Vista Basic", you will notice that SetLayeredWindowAttributes will return 0, Last Error Code is 0 also.

Additional, a normal window is not effected after color sheme switched.
October 2008
SMTWTFS
September 2008November 2008
1234
567891011
12131415161718
19202122232425
262728293031