如何设置按钮的图标? (20分)

  • 主题发起人 主题发起人 firstrose
  • 开始时间 开始时间
F

firstrose

Unregistered / Unconfirmed
GUEST, unregistred user!
大家有用SQL Server吗?看到那个服务管理器的界面吗?上面有3个带图标的按钮。我想做类似的按钮。要求用Win32SDK,不用控件。<br><br>我用的代码:<br><br>Begin<br>&nbsp; Inst:=hInstance; <br>&nbsp; With WinClass do<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; lpfnWndProc:=@DefDlgProc;<br>&nbsp; &nbsp; &nbsp; cbWndExtra:=DLGWINDOWEXTRA;<br>&nbsp; &nbsp; &nbsp; hInstance:=Inst;<br>&nbsp; &nbsp; &nbsp; hCursor:=LoadCursor(0,IDC_ARROW);<br>&nbsp; &nbsp; &nbsp; hbrBackground:=COLOR_WINDOW + 1;<br>&nbsp; &nbsp; &nbsp; lpszClassname:='xxxxxx';<br>&nbsp; &nbsp; End;<br><br>&nbsp; RegisterClassEx(WinClass); <br><br>&nbsp; DialogBoxParam(Inst,MAKEINTRESOURCE(IDD_MAIN),0,@DialogFunc,0); <br>End.<br><br>下面是我用的RC文件。<br><br>#include "resource.h"<br><br>IDD_MAIN DIALOG 0, 0, 190, 141<br>STYLE DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU<br>CAPTION "xxxxx"<br>LANGUAGE LANG_CHINESE, 0x2<br>FONT 9, "宋体"<br>{<br>&nbsp; &nbsp;CONTROL "服务器(&amp;V):", 1010, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 5, 6, 52, 8 <br>&nbsp; &nbsp;CONTROL "", 1000, COMBOBOX, CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_SORT | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 61, 4, 122, 60 <br>&nbsp; &nbsp;CONTROL "服务(&amp;R):", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 6, 22, 53, 8 <br>&nbsp; &nbsp;CONTROL "", 1001, COMBOBOX, CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 61, 20, 122, 60 <br>&nbsp; &nbsp;CONTROL "开始/继续(&amp;S)", 1016, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 96, 61, 86, 8 <br>&nbsp; &nbsp;CONTROL "", 1013, BUTTON, BS_PUSHBUTTON | BS_ICON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 68, 58, 18, 14 <br>&nbsp; &nbsp;CONTROL "暂停(&amp;P)", 1017, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 96, 81, 83, 8 <br>&nbsp; &nbsp;CONTROL "", 1014, BUTTON, BS_PUSHBUTTON | BS_ICON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 68, 78, 18, 14 <br>&nbsp; &nbsp;CONTROL "停止(&amp;O)", 1018, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 96, 99, 83, 8 <br>&nbsp; &nbsp;CONTROL "", 1015, BUTTON, BS_PUSHBUTTON | BS_ICON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 68, 96, 18, 14 <br>&nbsp; &nbsp;CONTROL "当启动 OS 时自动启动服务(&amp;A)", 1021, BUTTON, BS_AUTOCHECKBOX | BS_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 6, 112, 182, 16 <br>&nbsp; &nbsp;CONTROL "", 1019, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 16, 61, 49, 49 <br>&nbsp; &nbsp;CONTROL "", 1007, STATIC, SS_LEFT | SS_SUNKEN | WS_CHILD | WS_VISIBLE, 1, 129, 188, 10 <br>&nbsp; &nbsp;CONTROL "停止(&amp;S)", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 65436, 65491, 16, 8<br>&nbsp; &nbsp;CONTROL "", 1004, EDIT, ES_LEFT | WS_CHILD | WS_VISIBLE, 65436, 65436, 40, 14 <br>&nbsp; &nbsp;CONTROL "暂停(&amp;P)", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 65436, 65436, 21, 8 <br>&nbsp; &nbsp;CONTROL "", 1005, EDIT, ES_LEFT | WS_CHILD | WS_VISIBLE, 65436, 65436, 40, 14 <br>&nbsp; &nbsp;CONTROL "开始/继续(&amp;C)", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 65436, 65436, 47, 8 <br>&nbsp; &nbsp;CONTROL "", 1006, EDIT, ES_LEFT | WS_CHILD | WS_VISIBLE, 65436, 65436, 40, 14 <br>&nbsp; &nbsp;CONTROL "刷新服务(&amp;H)...", 1023, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 60, 36, 123, 14 <br>}<br><br>IDI_MAIN ICON DISCARDABLE "Main.ICO"<br><br>换而言之,是把<br>&nbsp; &nbsp;CONTROL "", 1013, BUTTON, BS_PUSHBUTTON | BS_ICON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 68, 58, 18, 14 <br>所指的button画上图标,并可以改变!<br><br>说要设置按钮的属性者无分!
 
1/ 自已用gdi来个按钮<br>2/createwindow 按钮是 dwStyle 是 BS_OWNERDRAW <br>再拦截 WM_MEASUREITEM / WM_DRAWITEM &nbsp;
 
我是要用RC的模板创建含Button的DLG,并且设置该Btn的ICON。所以用CreateWindowEx的方法不是正确答案。
 
我已经实验了,用SendMessage可以设置Btn的Icon,现在问题在于如何取得DLG资源中Btn的HWND,谢谢。
 
问题已经解决!<br><br>SendMessage(GetDlgItem(hwndDlg,1013),BM_SETIMAGE,IMAGE_ICON,LoadIcon(Inst,MAKEINTRESOURCE(IDI_BTNSTART)));<br><br><br>但是,各位有不用GetDlgItem的方法吗?
 
那就试试SendDlgItemMessage():[:D]<br>SendDlgItemMessage(hwndDlg,1013,BM_SETIMAGE,IMAGE_ICON,LoadIcon(Inst,MAKEINTRESOURCE(IDI_BTNSTART)));
 
SendDlgItemMessage的机理好象还是GetDlgItem+SendMessage
 
后退
顶部