`

What the f*** of Visual C++?

阅读更多
一直崇拜c/c++的牛人,崇拜那些只有几百K甚至几十K的程序。

我知道只有C/C++可以帮助我。

我的内心发出狂热的呼喊:我要学C++

于是无奈之下安装了N个G的Visual studio。。。

Visual C++,我回来了,请不要抛弃我,虽然以前我没有耐心的学习你。。。

我潜心阅读MSDN的文档。。。

MFC,不是我想要的。。。一个很莫名奇妙的框架,以前就是他这个第三者破坏了我和C++良好的感情

Winform是什么??原来是披着C++外衣的.net狼。

我要的是最美最纯的C,接受C++其实是一种妥协,但还要我接受这些浮华的勒涩吗?NO!!!

我知道,windows下我也可以用printf来写最纯的C,但是,我们还需要GUI,除了要单纯的心,我们要一个美丽的脸庞。

GDI、GDIPlus,WIN API,非常好,我终于找到我的梦中情人了,我要的就是这样的最单纯的程序。

我潜心的读相关的文档,就像在读着盼望已久的情书。。。

TRUE,FALSE,VOID,怎么不是 true ,false ,void,我是不是看花了。

WCHAR NWPSTR, LPWSTR, PWSTR; 。。。 我理解这良苦用心,希望我更容易看懂。

INT_PTR,LRESULT 。。。

虽然我很爱她,但我终于忍不住对她发火了:美女,请问你真的是C小姐吗?你可以正常点说话吗?

Please help me , How could I found my Miss C ?

===================================
最后补充一下,看了下WCHAR,LPWSTR这些玩意的定义,最终是用到了 __wchar_t 这个非标准的关键字。
MS定义这些别名我想也是为了适应将来的编译器变化。
另外在32位和64位操作系统中,int、long、的长度也是不一样的,甚至64位windows和64位的 nix的long长度也不一样。
请看此文:一个长整数的自述
说到底 c/c++ 标准还不完善,但是我比较不满“Visual C++”的是,他太special了。
分享到:
评论
11 楼 xuby 2009-11-13  
用 Qt 是王道。MFC设计理念太落后了,相当山寨。
10 楼 mikeandmore 2009-11-13  
ray_linn 写道
mikeandmore 写道
于是给lz个sample。顺便来反驳一下C写UI是绝对恶心的观点。

#include <gtk/gtk.h>

static void
btn_clicked(GtkButton<script type="text/javascript" src="http://www.iteye.com/javascripts/tinymce/themes/advanced/langs/zh.js"></script><script type="text/javascript" src="http://www.iteye.com/javascripts/tinymce/plugins/javaeye/langs/zh.js"></script>* wid, gpointer user_data)
{
    GtkWidget* dlg = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
                                            GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                                            "Hello World!");
    gtk_dialog_run(GTK_DIALOG(dlg));
    gtk_widget_destroy(dlg);
}

int 
main(int argc, char* argv[])
{
    gtk_init(&argc, &argv);
    GtkWidget* win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    GtkWidget* btn = gtk_button_new_with_label("click me");
    g_signal_connect(btn, "clicked", G_CALLBACK(btn_clicked), NULL);
    gtk_container_add(GTK_CONTAINER(win), btn);
    gtk_widget_show_all(win);
    
    gtk_main();
    return 0;
}

一共25行


嘿,你用一个公用库来包装一切当然简单,无非是别人帮你处理了消息处理,你自己用C写写看吧,如果GTK可用,那QT和MFC不是一样么。

楼主是想用C+Win32 API来写,你明白不?


错 lz是除了MFC以外的C/C++写。

啊据说也要除去winform的。。

lz排除了mfc和winform,我来推荐gtk,但是没有人排挤Qt。嗯,就是这样。
9 楼 ray_linn 2009-11-13  
mikeandmore 写道
于是给lz个sample。顺便来反驳一下C写UI是绝对恶心的观点。

#include <gtk/gtk.h>

static void
btn_clicked(GtkButton* wid, gpointer user_data)
{
    GtkWidget* dlg = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
                                            GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                                            "Hello World!");
    gtk_dialog_run(GTK_DIALOG(dlg));
    gtk_widget_destroy(dlg);
}

int 
main(int argc, char* argv[])
{
    gtk_init(&argc, &argv);
    GtkWidget* win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    GtkWidget* btn = gtk_button_new_with_label("click me");
    g_signal_connect(btn, "clicked", G_CALLBACK(btn_clicked), NULL);
    gtk_container_add(GTK_CONTAINER(win), btn);
    gtk_widget_show_all(win);
    
    gtk_main();
    return 0;
}

一共25行


嘿,你用一个公用库来包装一切当然简单,无非是别人帮你处理了消息处理,你自己用C写写看吧,如果GTK可用,那QT和MFC不是一样么。

楼主是想用C+Win32 API来写,你明白不?
8 楼 mikeandmore 2009-11-13  
于是给lz个sample。顺便来反驳一下C写UI是绝对恶心的观点。

#include <gtk/gtk.h>

static void
btn_clicked(GtkButton* wid, gpointer user_data)
{
    GtkWidget* dlg = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
                                            GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                                            "Hello World!");
    gtk_dialog_run(GTK_DIALOG(dlg));
    gtk_widget_destroy(dlg);
}

int 
main(int argc, char* argv[])
{
    gtk_init(&argc, &argv);
    GtkWidget* win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    GtkWidget* btn = gtk_button_new_with_label("click me");
    g_signal_connect(btn, "clicked", G_CALLBACK(btn_clicked), NULL);
    gtk_container_add(GTK_CONTAINER(win), btn);
    gtk_widget_show_all(win);
    
    gtk_main();
    return 0;
}

一共25行
7 楼 mikeandmore 2009-11-13  
七猫 写道
在win上要是不嫌界面不好看的话,可以试试gtk<script type="text/javascript" src="http://www.iteye.com/javascripts/tinymce/themes/advanced/langs/zh.js"></script><script type="text/javascript" src="http://www.iteye.com/javascripts/tinymce/plugins/javaeye/langs/zh.js"></script>这玩意儿,我觉得这东东写些简单的程序用glade生成xml还是比较方便的。

非得在win下么,gtk这东西在linux下非常方便的,glade随便拖拖,生成一个gtkbuilder的xml,然后直接加载就好了。。。
6 楼 mikeandmore 2009-11-13  
ray_linn 写道
mikeandmore 写道
lz投奔linux吧。。。。



你在耍小白么?诸如wchar是C++标准中的unicode字符,你就是滚到linux里也是如此.GCC gui的能力弱得要死.
另外有一些是windows api的,你不调用Windows API,何必关注?



LZ到底是要从C写GUI界面,还是用C++写GUI界面? 以我看来,你还是放弃想用C写界面的想法吧:一个什么都不做的Windows界面,用C大概要300多行,你自己要去处理所有的消息。。


用MFC创建个界面,那不是相当简单的么?何至于那么难哈?



涨见识了啊。gcc和gui能联系到一起。。。。真是搞笑。。。

再说wchar_t也不只是C++标准,见C99标准7.24节
5 楼 七猫 2009-11-12  
折腾加自虐。
4 楼 七猫 2009-11-12  
在win上要是不嫌界面不好看的话,可以试试gtk这玩意儿,我觉得这东东写些简单的程序用glade生成xml还是比较方便的。
3 楼 ray_linn 2009-11-12  
mikeandmore 写道
lz投奔linux吧。。。。



你在耍小白么?诸如wchar是C++标准中的unicode字符,你就是滚到linux里也是如此.GCC gui的能力弱得要死.
另外有一些是windows api的,你不调用Windows API,何必关注?



LZ到底是要从C写GUI界面,还是用C++写GUI界面? 以我看来,你还是放弃想用C写界面的想法吧:一个什么都不做的Windows界面,用C大概要300多行,你自己要去处理所有的消息。。


用MFC创建个界面,那不是相当简单的么?何至于那么难哈?


下面就是纯C写的,不知道楼主看了有什么感想
 BOOL        bOnTop, bGrayScale, bBackground = TRUE;   
 COLORREF    cForeground = RGB(255,255,255), cBackground = RGB(0,0,0);   
 HBRUSH      hBackGrnd;   
 int         iCopyMode = 0;   
    
 /*/ ***** Function prototypes for static functions      ***** /*/   
    
 void GrabColor (HWND hwnd, HWND hwndCtl);   
 void UpdateDisplay (HWND hwnd, HWND hStatusRGB, HWND hStatusHex, int R, int G, int B);   
    
 /*/ ***** Function prototypes for callback functions    ***** /*/   
    
 BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);   
    
 /*/ ***** Function prototypes for message handlers      ***** /*/   
    
 static void Dialog_OnCommand        (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);   
 HBRUSH      Dialog_OnCtlColorStatic (HWND hwnd, HDC hdc, HWND hChild, int type);   
 static void Dialog_OnHScroll        (HWND hwnd, HWND hctl, UINT code, int pos);   
 static BOOL Dialog_OnInitDialog     (HWND hwnd, HWND hwndFocus, LPARAM lParam);   
 void        Dialog_OnTimer          (HWND hwnd, UINT id);   
    
 /*/  
 / / int WINAPI  
 / /     WinMain (HINSTANCE, HINSTANCE, LPSTR, int)  
 / /  
 / / PURPOSE:  
 / /     Entry point for the application.  
 / /  
 / / COMMENTS:  
 / /     This function initializes the application and processes the  
 / /     dialog box.  
 /*/   
    
 int WINAPI   
 WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)   
 {   
     /*/  
     / / Instead of using GetMessage(), TranslateMessage(), and DispatchMessage()  
     / / for the main message loop, we simply create a Dialog Box and let Windows  
     / / handle it internally.  
     /*/   
    
     DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOGBOX), NULL, (DLGPROC)DialogProc);   
    
     /*/ clean up /*/   
     if(hBackGrnd) DeleteObject(hBackGrnd);   
    
     return 1;   
    
     /*/ These prevent 'unreferenced formal parameter' warnings /*/   
     hPrevInstance;   
     lpCmdLine;   
     nCmdShow;   
 }   
    
 /*/  
 / / BOOL CALLBACK  
 / /     DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)  
 / /  
 / / PURPOSE:  
 / /     Dialog function for the Colorz dialog box.  
 / /     Processes messages sent by calling the  
 / /     appropriate functions  
 /*/   
    
 BOOL CALLBACK   
 DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)   
 {   
     /*/ The message cracker macros used here are defined in windowx.h /*/   
    
     switch (message)   
     {   
         case WM_COMMAND:                /*/ Notification from a control                 /*/   
             return HANDLE_WM_COMMAND (hwnd, wParam, lParam, Dialog_OnCommand);   
    
         case WM_CTLCOLORSTATIC:         /*/ Paint a static control's color              /*/   
             return HANDLE_WM_CTLCOLORSTATIC (hwnd, wParam, lParam, Dialog_OnCtlColorStatic);   
    
         case WM_HSCROLL:                /*/ Notification from a horizontal scrollbar    /*/   
             return HANDLE_WM_HSCROLL (hwnd, wParam, lParam, Dialog_OnHScroll);   
    
         case WM_INITDIALOG:             /*/ Initialization of controls complete         /*/   
             return HANDLE_WM_INITDIALOG (hwnd, wParam, lParam, Dialog_OnInitDialog);   
    
         case WM_TIMER:                  /*/ Notification of timer interval              /*/   
             return HANDLE_WM_TIMER (hwnd, wParam, lParam, Dialog_OnTimer);   
     }   
     return FALSE;   
 }   
    
 /*/  
 / / static void  
 / /     Dialog_OnCommand (HWND hwnd, int id, hwnd hwndCtl, UINT codeNotify)  
 / /  
 / /         hwnd        Window handle for the dialog box window  
 / /         id          Specifies the identifier of the menu item, control, or accelerator.  
 / /         hwndCtl     Handle of the control sending the message if the message  
 / /                     is from a control, otherwise, this parameter is NULL.   
 / /         codeNotify  Specifies the notification code if the message is from a control.  
 / /                     This parameter is 1 when the message is from an accelerator.  
 / /                     This parameter is 0 when the message is from a menu.  
 / /  
 / / PURPOSE:  
 / /     Handle the keyboard and control notifications.  
 / /     An OK button press, or Enter/Esc keypress  
 / /     all dismiss the Colorz dialog box.  
 /*/   
    
 static void   
 Dialog_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)   
 {   
     /*/ The macros used here are defined in windowx.h /*/   
    
     switch (id)   
     {   
         case IDC_CHECK_GRAYSCL:   
             if(Button_GetCheck(hwndCtl)==BST_CHECKED)   
                 bGrayScale = TRUE;   
             else   
                 bGrayScale = FALSE;   
             break;   
    
         case IDC_CHECK_ONTOP:   
             if(Button_GetCheck(hwndCtl)==BST_CHECKED)   
             {   
                 bOnTop = TRUE;   
                 /*/ set the Colorz dialog on top of others /*/   
                 SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);   
             }   
             else   
             {   
                 bOnTop = FALSE;   
                 /*/ restore the Colorz dialog /*/   
                 SetWindowPos(hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);   
             }   
             break;   
    
         case IDC_CHECK_GRABCLR:   
             GrabColor (hwnd, hwndCtl);   
             break;   
    
         case IDC_RADIO_BACKGND:   
             bBackground = TRUE;   
             /*/ update scroll bars to reflect selected color /*/   
             ScrollBar_SetPos(GetDlgItem(hwnd,IDC_SCROLLBAR_R),GetRValue(cBackground),TRUE);   
             ScrollBar_SetPos(GetDlgItem(hwnd,IDC_SCROLLBAR_G),GetGValue(cBackground),TRUE);   
             ScrollBar_SetPos(GetDlgItem(hwnd,IDC_SCROLLBAR_B),GetBValue(cBackground),TRUE);   
    
             /*/ display output /*/   
             UpdateDisplay(hwnd, GetDlgItem(hwnd,IDC_STATIC_RGB),GetDlgItem(hwnd,IDC_STATIC_HEX),   
                             GetRValue(cBackground),GetGValue(cBackground),GetBValue(cBackground));   
             break;   
    
         case IDC_RADIO_FOREGND:   
             bBackground = FALSE;   
             /*/ update scroll bars to reflect selected color /*/   
             ScrollBar_SetPos(GetDlgItem(hwnd,IDC_SCROLLBAR_R),GetRValue(cForeground),TRUE);   
             ScrollBar_SetPos(GetDlgItem(hwnd,IDC_SCROLLBAR_G),GetGValue(cForeground),TRUE);   
             ScrollBar_SetPos(GetDlgItem(hwnd,IDC_SCROLLBAR_B),GetBValue(cForeground),TRUE);   
    
             /*/ display output /*/   
             UpdateDisplay(hwnd, GetDlgItem(hwnd,IDC_STATIC_RGB),GetDlgItem(hwnd,IDC_STATIC_HEX),   
                             GetRValue(cForeground),GetGValue(cForeground),GetBValue(cForeground));   
             break;   
    
         case IDC_RADIO_OFF:   
             iCopyMode = 0;   
             /*/ force controls to repaint /*/   
             InvalidateRgn( GetDlgItem(hwnd,IDC_STATIC_RGB) ,NULL,TRUE);   
             InvalidateRgn( GetDlgItem(hwnd,IDC_STATIC_HEX) ,NULL,TRUE);   
             break;   
    
         case IDC_RADIO_RGB:   
             iCopyMode = 1;   
             /*/ force controls to repaint /*/   
             InvalidateRgn( GetDlgItem(hwnd,IDC_STATIC_RGB) ,NULL,TRUE);   
             InvalidateRgn( GetDlgItem(hwnd,IDC_STATIC_HEX) ,NULL,TRUE);   
             break;   
    
         case IDC_RADIO_HEX:   
             iCopyMode = 2;   
             /*/ force controls to repaint /*/   
             InvalidateRgn( GetDlgItem(hwnd,IDC_STATIC_RGB) ,NULL,TRUE);   
             InvalidateRgn( GetDlgItem(hwnd,IDC_STATIC_HEX) ,NULL,TRUE);   
             break;   
    
         case IDCANCEL:   
             if(hBackGrnd) DeleteObject(hBackGrnd);  /*/ Clean Up                      /*/   
             EndDialog (hwnd, TRUE);                 /*/ Dismiss the Colorz dialog box /*/   
             break;   
     }   
    
     /*/ This prevents 'unreferenced formal parameter' warnings /*/   
     codeNotify;   
 }   
    
 /*/  
 / / HBRUSH  
 / /     Dialog_OnCtlColorStatic (HWND hwnd, HDC hdc, HWND hChild, int type)  
 / /  
 / /         hwnd    Window handle for the dialog box window  
 / /         hdc     Handle to device context for static control  
 / /         hChild  Window handle for the static control  
 / /         type    HOWDY  
 / /  
 / / PURPOSE:  
 / /     Determines the colors of a static control.  
 /*/   
    
 HBRUSH   
 Dialog_OnCtlColorStatic (HWND hwnd, HDC hdc, HWND hChild, int type)   
 {   
     /*/ This prevents 'unreferenced formal parameter' warnings /*/   
     type;   
    
     /*/ The macros used here are defined in windowx.h /*/   
    
     if (hChild==GetDlgItem(hwnd,IDC_STATIC_PREVIEW))   
     {   
         if(hBackGrnd) DeleteObject(hBackGrnd);   
         hBackGrnd = CreateSolidBrush(cBackground);   
         SetBkMode(hdc,TRANSPARENT);   
         SetTextColor(hdc,cForeground);   
         return hBackGrnd;   
     }   
     if (hChild==GetDlgItem(hwnd,IDC_STATIC_RGB))   
     {   
         if(hBackGrnd) DeleteObject(hBackGrnd);   
         hBackGrnd = CreateSolidBrush( GetSysColor(COLOR_3DFACE) );   
         SetBkMode(hdc,TRANSPARENT);   
    
         if(iCopyMode==1)   
             SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHT) );   
         else   
             SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT) );   
    
         return hBackGrnd;   
     }   
     if (hChild==GetDlgItem(hwnd,IDC_STATIC_HEX))   
     {   
         if(hBackGrnd) DeleteObject(hBackGrnd);   
         hBackGrnd = CreateSolidBrush( GetSysColor(COLOR_3DFACE) );   
         SetBkMode(hdc,TRANSPARENT);   
    
         if(iCopyMode==2)   
             SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHT) );   
         else   
             SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT) );   
    
         return hBackGrnd;   
     }   
     else   
         return FORWARD_WM_CTLCOLORSTATIC(hwnd, hdc, hChild, DefWindowProc);   
 }   
    
 /*/  
 / / static void  
 / /     Dialog_OnHScroll (HWND hwnd, HWND hctl, UINT code, int pos)  
 / /  
 / /         hwnd    Window handle for the dialog box window  
 / /         hctl    Handle of the control sending the message  
 / /         code    Specifies the notification code if the message is from a control.  
 / /         pos     Position user moved the scroll bar to  
 / /  
 / / PURPOSE:  
 / /     Handle the scroll bar notifications.  
 / /     and update the other controls as needed.  
 /*/   
    
 static void   
 Dialog_OnHScroll (HWND hwnd, HWND hctl, UINT code, int pos)   
 {   
     HWND hPreview;  /*/ used to reference current control /*/   
     HWND hR,hG,hB;   
     HWND hStatusRGB, hStatusHex;   
    
     int posx;       /*/ used to track current position    /*/   
     int R,G,B;      /*/ used to set global variables      /*/   
    
     hR = GetDlgItem(hwnd,IDC_SCROLLBAR_R);   
     hG = GetDlgItem(hwnd,IDC_SCROLLBAR_G);   
     hB = GetDlgItem(hwnd,IDC_SCROLLBAR_B);   
    
     switch(code)   
     {   
         /*/ The macros used here are defined in windowx.h /*/   
    
         /*/  
         / / This code handles common notifications from the scroll bars  
         / / and if the user wants to keep his/her values in grayscale, it  
         / / makes sure the bars are in uniform. (same value for all)  
         /*/   
    
         case SB_THUMBPOSITION:      /*/ user releases thumb         /*/   
             if(bGrayScale)          /*/ see if grayscale is checked /*/   
             {   
                 ScrollBar_SetPos(hR,pos,TRUE);   
                 ScrollBar_SetPos(hG,pos,TRUE);   
                 ScrollBar_SetPos(hB,pos,TRUE);   
             }   
             else   
                 ScrollBar_SetPos(hctl,pos,TRUE);   
             break;   
    
         case SB_THUMBTRACK:         /*/ user drags thumb            /*/   
             if(bGrayScale)          /*/ see if grayscale is checked /*/   
             {   
                 ScrollBar_SetPos(hR,pos,TRUE);   
                 ScrollBar_SetPos(hG,pos,TRUE);   
                 ScrollBar_SetPos(hB,pos,TRUE);   
             }   
             else   
                 ScrollBar_SetPos(hctl,pos,TRUE);   
             break;   
    
         case SB_LINERIGHT:          /*/ user clicks right arrow     /*/   
             posx = ScrollBar_GetPos(hctl);   
             posx += 1;   
             if(bGrayScale)          /*/ see if grayscale is checked /*/   
             {   
                 ScrollBar_SetPos(hR,posx,TRUE);   
                 ScrollBar_SetPos(hG,posx,TRUE);   
                 ScrollBar_SetPos(hB,posx,TRUE);   
             }   
             else   
                 ScrollBar_SetPos(hctl,posx,TRUE);   
             break;   
                
         case SB_LINELEFT:           /*/ user clicks left arrow      /*/   
             posx = ScrollBar_GetPos(hctl);   
             posx -= 1;   
             if(bGrayScale)          /*/ see if grayscale is checked /*/   
             {   
                 ScrollBar_SetPos(hR,posx,TRUE);   
                 ScrollBar_SetPos(hG,posx,TRUE);   
                 ScrollBar_SetPos(hB,posx,TRUE);   
             }   
             else   
                 ScrollBar_SetPos(hctl,posx,TRUE);   
             break;   
    
         case SB_PAGERIGHT:          /*/ user pages right            /*/   
             posx = ScrollBar_GetPos(hctl);   
             posx += 5;   
             if(bGrayScale)          /*/ see if grayscale is checked /*/   
             {   
                 ScrollBar_SetPos(hR,posx,TRUE);   
                 ScrollBar_SetPos(hG,posx,TRUE);   
                 ScrollBar_SetPos(hB,posx,TRUE);   
             }   
             else   
                 ScrollBar_SetPos(hctl,posx,TRUE);   
             break;   
    
         case SB_PAGELEFT:           /*/ user pages left             /*/   
             posx = ScrollBar_GetPos(hctl);   
             posx -= 5;   
             if(bGrayScale)          /*/ see if grayscale is checked /*/   
             {   
                 ScrollBar_SetPos(hR,posx,TRUE);   
                 ScrollBar_SetPos(hG,posx,TRUE);   
                 ScrollBar_SetPos(hB,posx,TRUE);   
             }   
             else   
                 ScrollBar_SetPos(hctl,posx,TRUE);   
             break;   
     }   
    
     /*/ set IDC_PREVIEW to match the new values /*/   
     R = ScrollBar_GetPos(hR);   
     G = ScrollBar_GetPos(hG);   
     B = ScrollBar_GetPos(hB);   
    
     hPreview   = GetDlgItem(hwnd,IDC_STATIC_PREVIEW);   
     hStatusRGB = GetDlgItem(hwnd,IDC_STATIC_RGB);   
     hStatusHex = GetDlgItem(hwnd,IDC_STATIC_HEX);   
    
     /*/ update display and variables /*/   
     UpdateDisplay(hwnd, hStatusRGB, hStatusHex, R, G, B);   
    
     /*/ force control to repaint itself /*/   
     InvalidateRgn(hPreview,NULL,TRUE);   
 }   
    
 /*/  
 / / static BOOL  
 / /     Dialog_OnInitDialog (HWND hwnd, HWND hwndFocus, LPARAM lParam)  
 / /  
 / / PURPOSE:  
 / /     Function to handle any initialization necessary before  
 / /     the newly created window is shown.  
 /*/   
    
 static BOOL   
 Dialog_OnInitDialog (HWND hwnd, HWND hwndFocus, LPARAM lParam)   
 {   
     HFONT hFont;   
     HICON hIcon;   
     SCROLLINFO si;   
     HINSTANCE hInst;   
    
     /*/ Center the main window in the work area. /*/   
     CenterWnd(hwnd,NULL);   
    
     /*/ The macros used here are defined in windowx.h /*/   
    
     hInst = GetWindowInstance(hwnd);   
    
     /*/ Get a handle to the System font /*/   
     hFont = CreateFont(   
         10,0,0,0,FW_NORMAL,0,0,0,   
         ANSI_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,   
         FF_SWISS,"System");   
    
     /*/ set the preview pane's font /*/   
     SetWindowFont(GetDlgItem(hwnd,IDC_STATIC_PREVIEW),hFont,TRUE);   
    
     /*/ we are done with the font /*/   
     DeleteObject(hFont);   
    
     /*/ ***** INITIALIZATION ROUTINES ***** /*/   
    
     /*/ values for the R, G, and B scrollbars /*/   
    
     si.cbSize = sizeof(si);   
     si.nMin = 0;            /*/ Minimum value /*/   
     si.nMax = 255;          /*/ Maximum value /*/   
     si.fMask = SIF_RANGE;   /*/ Flag to indicate that want to manipulate ranges /*/   
    
     /*/ apply the data to the scroll bars /*/   
     SetScrollInfo(GetDlgItem(hwnd,IDC_SCROLLBAR_R),SB_CTL,&si,TRUE);   
     SetScrollInfo(GetDlgItem(hwnd,IDC_SCROLLBAR_G),SB_CTL,&si,TRUE);   
     SetScrollInfo(GetDlgItem(hwnd,IDC_SCROLLBAR_B),SB_CTL,&si,TRUE);   
    
     /*/  
     / / The Button_SetCheck macro is defined in Windowsx.h.  If you do not  
     / / include the header, you'll have to use the SendMessage API directly.  
     /*/   
    
     Button_SetCheck(GetDlgItem(hwnd, IDC_RADIO_BACKGND), BM_SETCHECK);   
     Button_SetCheck(GetDlgItem(hwnd, IDC_RADIO_OFF), BM_SETCHECK);   
    
     /*/  
     / / Use our custom icon for the dialog instead of the Windows'  
     / / default icon on the title bar (and when using Alt+Tab)  
     /*/   
    
     hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDR_MAINFRAME),   
                             IMAGE_ICON,   
                             GetSystemMetrics(SM_CXICON),   
                             GetSystemMetrics(SM_CYICON),   
                             LR_DEFAULTCOLOR);   
    
     SendMessage(hwnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);   
    
     hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDR_MAINFRAME),   
                             IMAGE_ICON,   
                             GetSystemMetrics(SM_CXSMICON),   
                             GetSystemMetrics(SM_CYSMICON),   
                             LR_DEFAULTCOLOR);   
    
     SendMessage(hwnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);   
    
     /*/ These prevent 'unreferenced formal parameter' warnings /*/   
     hwndFocus;   
     lParam;   
    
     return TRUE;   
 }   
    
 /*/  
 / / void  
 / /     Dialog_OnTimer (HWND hwnd, UINT id)  
 / /  
 / /         hwnd        Window handle for the dialog box window  
 / /         id          Specifies the identifier of the timer  
 / /  
 / / PURPOSE:  
 / /     Receives timer notifications.  
 /*/   
    
 void   
 Dialog_OnTimer (HWND hwnd, UINT id)   
 {   
     /*/ The macros used here are defined in windowx.h /*/   
    
     static POINT spoint;   
     POINT cursor;   
     HDC hdc, hdcPrev;   
     HWND hwndxy, hPreview;   
     HWND hStatusRGB,hStatusHex;   
     int R,G,B, AltKey;   
     COLORREF rgb;   
    
     /*/ is the user pressing either ALT key? /*/   
     AltKey = GetAsyncKeyState(VK_MENU);   
     /*/ key isn't being pressed, so get out /*/   
     if(AltKey==0) return;   
    
     /*/ ***** GRAB COLOR PROCESS ***** /*/   
    
     GetCursorPos(&cursor);   
    
     if(cursor.x==spoint.x && cursor.y==spoint.y) return;   
    
     spoint.x = cursor.x;   
     spoint.y = cursor.y;   
    
     /*/ get a handle to the window under the cursor /*/   
     hwndxy = WindowFromPoint(spoint);   
    
     /*/ get a handle to the window for IDC_STATIC_PREVIEW /*/   
     hPreview = GetDlgItem(hwnd,IDC_STATIC_PREVIEW);   
    
     /*/ get handles to both of the windows' DCs /*/   
     hdc =       GetDC(hwndxy);   
     hdcPrev =   GetDC(hPreview);   
    
     /*/ GetPixel requires client coordinates /*/   
     ScreenToClient(hwndxy,&cursor);   
     rgb = GetPixel(hdc,cursor.x,cursor.y);   
    
     /*/  
     / / The following is a workaround for the GetPixel API. If the  
     / / cursor is over a titlebar or other non-client areas of the  
     / / window it'll return -1 for the RGB intensities. In this case  
     / / we use BitBlt to copy the color to our control and extract  
     / / the the intensities from that.  
     /*/   
    
     if(rgb==-1)     /*/ check to see if intensities are valid /*/   
     {   
         BitBlt(hdcPrev,0,0,1,1,hdc,cursor.x,cursor.y,SRCCOPY);   
         rgb = GetPixel(hdcPrev,0,0);   
     }   
    
     /*/ we no longer need the handles, so we discard them /*/   
     ReleaseDC(hwndxy,hdc);   
     ReleaseDC(hPreview,hdcPrev);   
    
     /*/ retreive specific color intensities /*/   
    
     /*/ GetXValue macros are defined in windowx.h /*/   
     R = GetRValue(rgb);   
     G = GetGValue(rgb);   
     B = GetBValue(rgb);   
    
     /*/ get a handle to the output static controls /*/   
     hStatusRGB = GetDlgItem(hwnd,IDC_STATIC_RGB);   
     hStatusHex = GetDlgItem(hwnd,IDC_STATIC_HEX);   
    
     /*/ display output /*/   
     UpdateDisplay(hwnd, hStatusRGB, hStatusHex, R, G, B);   
    
     /*/ force control to repaint itself /*/   
     InvalidateRgn(hPreview,NULL,TRUE);   
    
     /*/ This prevents 'unreferenced formal parameter' warnings /*/   
     id;   
 }   
    
 /*/  
 / / void  
 / /     GrabColor (HWND hwnd, HWND hwndCtl)  
 / /  
 / /         hwnd        Window handle for the dialog box window  
 / /         hwndCtl     Window handle for the preview pane control  
 / /  
 / / PURPOSE:  
 / /     Initialize and prepares for the grab color  
 / /     process to begin  
 /*/   
    
 void   
 GrabColor (HWND hwnd, HWND hwndCtl)   
 {   
     /*/ The macros used here are defined in windowx.h /*/   
        
     BOOL bGrabColor;    /*/ temp flag /*/   
     HWND hwndOnTop, hwndGrayScale;   
     HWND hwndR,hwndG,hwndB;   
    
     hwndOnTop = GetDlgItem (hwnd,IDC_CHECK_ONTOP);   
     hwndGrayScale = GetDlgItem (hwnd, IDC_CHECK_GRAYSCL);   
     hwndR = GetDlgItem (hwnd, IDC_SCROLLBAR_R);   
     hwndG = GetDlgItem (hwnd, IDC_SCROLLBAR_G);   
     hwndB = GetDlgItem (hwnd, IDC_SCROLLBAR_B);   
    
     /*/ query state of the "Grab Color" checkbox and respond accordingly /*/   
     if(Button_GetCheck(hwndCtl)==BST_CHECKED) bGrabColor = TRUE; else bGrabColor = FALSE;   
    
     /*/  
     / / The following will check and uncheck the appropriate controls  
     / / and start and end the grab color process.  
     /*/   
    
     if(bGrabColor)   
     {   
         /*/ initiate process /*/   
         Button_SetCheck(hwndOnTop,BST_CHECKED);   
         Button_SetCheck(hwndGrayScale,BST_UNCHECKED);   
         Button_Enable(hwndOnTop,FALSE);   
         Button_Enable(hwndGrayScale,FALSE);   
         SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);   
         ScrollBar_Enable(hwndR,ESB_DISABLE_BOTH);   
         ScrollBar_Enable(hwndG,ESB_DISABLE_BOTH);   
         ScrollBar_Enable(hwndB,ESB_DISABLE_BOTH);   
    
         /*/  
         / / The timer is set to trigger every 55 milliseconds. It is  
         / / pointless to set it any faster for this application because  
         / / due to hardeware timers' limitations you'll never get a  
         / / message in under a 54.925 millsecond interval (without MM,  
         / / ASM, or QueryPerformanceCounter workarounds). Accuracy is  
         / / not imperative here, so we don't care.  
         /*/   
    
         SetTimer(hwnd,ID_TIMER,55,NULL);   
     }   
     else   
     {   
         int R,G,B;   
    
         /*/ terminate process /*/   
         Button_Enable(hwndOnTop,TRUE);   
         Button_Enable(hwndGrayScale,TRUE);   
         ScrollBar_Enable(hwndR,ESB_ENABLE_BOTH);   
         ScrollBar_Enable(hwndG,ESB_ENABLE_BOTH);   
         ScrollBar_Enable(hwndB,ESB_ENABLE_BOTH);   
    
         KillTimer(hwnd,ID_TIMER);   
    
         if(bOnTop)   
         {   
             Button_SetCheck(hwndOnTop,BST_CHECKED);   
             SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);   
         }   
         else   
         {   
             Button_SetCheck(hwndOnTop,BST_UNCHECKED);   
             SetWindowPos(hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);   
         }   
    
         if(bGrayScale)   
             Button_SetCheck(hwndGrayScale,BST_CHECKED);   
         else   
             Button_SetCheck(hwndGrayScale,BST_UNCHECKED);   
    
         /*/ do we need the current foreground or background color? /*/   
         if(bBackground)   
         {   
             /*/ GetXValue macros are defined in windowx.h /*/   
             R = GetRValue(cBackground);   
             G = GetGValue(cBackground);   
             B = GetBValue(cBackground);   
         }   
         else   
         {   
             /*/ GetXValue macros are defined in windowx.h /*/   
             R = GetRValue(cForeground);   
             G = GetGValue(cForeground);   
             B = GetBValue(cForeground);   
    
         }   
    
         /*/ update scroll bars to reflect selected color /*/   
         ScrollBar_SetPos(hwndR,R,TRUE);   
         ScrollBar_SetPos(hwndG,G,TRUE);   
         ScrollBar_SetPos(hwndB,B,TRUE);   
     }   
    
 }   
    
 void   
 UpdateDisplay (HWND hwnd, HWND hStatusRGB, HWND hStatusHex, int R, int G, int B)   
 {   
     char StatusRGB[20];   
     char StatusHex[20];   
    
     /*/ format the RGB output for display /*/   
     wsprintf(StatusRGB,"RGB: %d,%d,%d",R,G,B);   
    
     /*/ format the Hexadecimal output for display /*/   
     if(R<16 && G<16 && B<16)   
         wsprintf(StatusHex,"Hex: 0%X0%X0%X",R,G,B);   
     else if(R<16 && G<16)   
         wsprintf(StatusHex,"Hex: 0%X0%X%X",R,G,B);   
     else if(R<16 && B<16)   
         wsprintf(StatusHex,"Hex: 0%X%X0%X",R,G,B);   
     else if(G<16 && B<16)   
         wsprintf(StatusHex,"Hex: %X0%X0%X",R,G,B);   
     else if(R<16)   
         wsprintf(StatusHex,"Hex: 0%X%X%X",R,G,B);   
     else if(G<16)   
         wsprintf(StatusHex,"Hex: %X0%X%X",R,G,B);   
     else if(B<16)   
         wsprintf(StatusHex,"Hex: %X%X0%X",R,G,B);   
     else   
         wsprintf(StatusHex,"Hex: %X%X%X",R,G,B);   
    
     /*/ update labels with new data /*/   
     SetWindowText(hStatusRGB,StatusRGB);   
     SetWindowText(hStatusHex,StatusHex);   
    
     /*/ post data to clipboard (if selected) /*/   
     if(iCopyMode == 1)   
         /*/ Advance pointer by 5 to clip 'RGB: ' /*/   
         AddClipboardText(hwnd,StatusRGB+5);   
     else if(iCopyMode == 2)   
         /*/ Advance pointer by 5 to clip 'Hex: ' /*/   
         AddClipboardText(hwnd,StatusHex+5);   
    
     if(bBackground)   
         /*/ set the background color of the static control /*/   
         cBackground = RGB(R,G,B);   
     else   
         /*/ set the foreground color of the static control /*/   
         cForeground = RGB(R,G,B);   
 } 

2 楼 mikeandmore 2009-11-12  
lz投奔linux吧。。。。
1 楼 jasongreen 2009-11-12  
WTL... TAKE a try...

相关推荐

    oRTP-0.16.3 软件包下载 2010年7月发布。

    What is it ? ************ oRTP is a LGPL licensed C library implementing the RTP protocol (rfc3550)....There are instructions and Microsoft Visual C++ project files in build/win32native/oRTP.

    Visual C++ 2008 入门

    My objective with this book is to teach you the essentials of C++ programming using both of the tech- nologies supported by Visual C++ 2008. The book provides a detailed tutorial on both flavors of ...

    MapX 5.0开发手册

    **4.8 Getting Started with Visual C++** - **Visual C++入门:** 使用Visual C++进行MapX开发的基础教程。 - **开发流程:** 描述从新建项目到运行项目的整个流程。 **4.9 Getting Started With Delphi** - **...

    Visual C++做的连连看小程序,适合新手

    在本文中,我们将深入探讨如何使用Visual C++创建一个连连看小游戏,这是一款非常适合编程新手入门的项目。Visual C++是Microsoft开发的一款强大的集成开发环境(IDE),它提供了丰富的工具和库来支持C++编程,使得...

    仓库管理系统 visual c++6.0

    AppWizard has created this DMS application for you. This application not only demonstrates the...This file contains a summary of what you will find in each of the files that make up your DMS application.

    Visual C/C++的异常处理

    ### Visual C/C++ 的异常处理详解 #### 一、引言 在开发过程中,异常处理是一种重要的编程技术,用于管理程序执行过程中可能出现的各种错误或非预期情况。Visual C/C++ 提供了多种方式来处理异常,包括标准 C 语言...

    Visual C++课程设计案例精编(第二版) --第三章 系统进程管理器的开发

    // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_SHOWALLPROCESS_H__928B7E87_BDF8_4C4F_84D3_AF4D921C3CF8__INCLUDED_)

    Using LUA with Visual C++ (Introduction)

    Scripts give you the possibility to change the behaviour of your C++ programs without any need to recompile your program. A real world example would be game programming: you only have to change the ...

    Visual C++中的异常处理浅析

    《Visual C++中的异常处理深度解析》 Visual C++作为一款强大的开发工具,不仅支持标准的C++语言,还提供了对Microsoft Foundation Classes (MFC)的集成,这使得在异常处理方面,Visual C++有着独特的处理机制。...

    MAtlab与C,C#,VB接口电子书

    **5.4 Creating MEX-files in Visual C++** 演示如何使用Visual C++创建MEX文件。 **5.5 Example** 提供一个具体的例子来展示MEX文件的创建过程。 **5.6 Further reading** 进一步阅读材料推荐。 **5.7 About ...

    CImg Reference

    - **What are the specificities of the CeCILL license?** - The CeCILL license is a free software license compatible with the GNU GPL and designed specifically for French law. - **Who is behind CImg?**...

    C & C++ Win32 API Programming

    In this comprehensive guide on **C & C++ Win32 API Programming**, we delve into the essentials of developing Windows applications using the powerful Win32 API. The Win32 API is a set of programming ...

    Visual C++课程设计案例精编(第二版)--第六章 电子邮件发送和接受程序的开发

    // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_MAILSERVER_H__CB181B60_A7D0_4663_B1F4_A97F7F2B9BAB__INCLUDED_)

    SML VCL Package (Cracked)

    SMLPack is a suite of multilingual support components package for Delphi & C++Builder. It can help you to make your application support multilingual user interface. It is a real AUTOMATIC tool for ...

    [揭秘系列-C++]C.Demystified,.A.Self-Teaching.Guide.pdf

    - **Jeff Kent**:洛杉矶山谷学院计算机科学副教授,教授多种编程语言,包括Visual Basic、C++、Java等。他不仅是一位资深教师,还负责一家洛杉矶律师事务所的网络管理工作。 #### 学习资源特色 - **Hands-On ...

    迷宫游戏的c++源程序

    This file contains a summary of what you will find in each of the files that make up your maze application. maze.cpp This is the main application source file. maze.dsp This file (the project file)...

    C++ Without Fear 3rd 第3版 无水印pdf 0分

    Now updated for the newest C++14 standard and the free Microsoft Visual C++ Community Edition, it will quickly make you productive with C++ even if you’ve never written a line of code! Brian ...

Global site tag (gtag.js) - Google Analytics