2010年08月01日 vc基础(3)

    技术2022-05-19  17

    工程:DailyHelper

    1.       取得桌面大小(不包括任务栏)

    RECT rc; SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID) &rc, 0);

    2.       设置对话框背景颜色

    定义成员变量CBrush m_brush;

    OnInitDialog里面:m_brush.CreateSolidBrush(RGB(xx, yy, zz);

    OnCtlColor里面:if(pWnd==this) { return m_brush; }        //注意上一步不能放到这里面,

                                                                                                                      //至于原因还未知

    3.       使窗口置顶:SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

    4.       关闭当前对话框:this->OnOK();

    5.       创建一个非模态对话框:

      增加成员变量m_dlgHello;  一定要用成员变量,临时变量会被析构。当然,也可以用临时指针变量

      m_dlgHello.Create(IDD_DIALOG1, NULL);

      m_dlgHello.ShowWindow(SW_SHOWNORMAL);

     

    其它:

    1. 若:

    char *str1 = "hello";

    char str2[] = "world";

    则:sizeof(str1)=4,sizeof(str2)=6; 看来笔试的时候全填错了,晕。。。

    2. 对于一个Based on Dialog的VC project, 窗体的OnChar事件是捕捉不到的,要响应OnChar事件,则需要重写PreTranslateMessage函数. 对于PreTranslateMessage,一个按键事件会调用它两次(OnKeyUp一次,OnKeyDown)一次,为避免重复,可以

     if(pMsg->message==WM_KEYDOWN)

     {

    ...

     }

    3. VC 支持多媒体:

    #include <mmsystem.h>

    #pragma comment(lib,"winmm.lib")

    4. Consider  a call in C like     count = read(fd, buf, nbytes) ;to make the call, the caller pushes the parameters onto the stack in order, last one first. The reason that C compilers push the parameters in reverse order has to do with printf-- by doing so, printf can always locate its first parameter, the format string.


    最新回复(0)