c++ - Controls blanked using XP themes -
i have been learning win32 api, , have been stumped this:
when run on windows 7 in both "classic look" , "windows 7 aero glass" look, ok, , has aero on controls, normal appearance. when run on xp machine, again, "classic look", looks ok, when run on xp "windows xp theme", above get.
following microsoft's guidelines on visual styles @ http://msdn.microsoft.com/en-us/library/bb773175%28vs.85%29.aspx there 3 things needed do:
1 . link comctl32.lib , call initcommoncontrols.
check, did this, added comctl32 linker settings.
2 . add file called yourapp.exe.manifest source tree has xml manifest format.
check, did this. had version using, safe, tried version suggested on site, renamed started specified cover bases. (yes, know give name of application....)
3 . add manifest application's resource file follows:
check, did this. added specified line suggest rc file.
so, under conditions, works, except windows xp style theme.
the thing thinking remains somehow not responding wm_paint message, passing default window proc, allow windows thing in regard. (i couldn't see if wasn't working, wouldn't work anywhere else.)
i saw similar post post, , said use initcommoncontrolsex, did too, no avail.
i stumped.
#include <windows.h> #include <windowsx.h> #include <commctrl.h> #include <uxtheme.h> #include <iostream> using namespace std; #define idc_main_button_1 101 // button identifier #define idc_main_button_2 102 // button identifier #define idc_main_button_3 103 // button identifier #define idc_main_button_4 104 // button identifier hwnd hwndbutton1; hwnd hwndbutton2; hwnd hwndbutton3; hwnd hwndbutton4; msg msg; lresult callback wndproc(hwnd, uint, wparam, lparam); lresult callback mywndproc (hwnd hwnd, uint msg, wparam wparam, lparam lparam, uint_ptr uidsubclass, dword_ptr dwrefdata); int winapi winmain (hinstance hinstance, hinstance hprevinst, lpstr lpcmdline, int showcmd) { initcommoncontrolsex icc; // initialize common controls. icc.dwsize = sizeof(icc); icc.dwicc = icc_win95_classes | icc_cool_classes | icc_internet_classes | icc_link_class | icc_standard_classes | icc_userex_classes; initcommoncontrolsex(&icc); wndclassexw wclass; zeromemory(&wclass,sizeof(wndclassexw)); wclass.cbsize = sizeof(wndclassex); wclass.hinstance = hinstance; wclass.lpszclassname = l"window class"; wclass.lpfnwndproc = (wndproc)wndproc; wclass.style = cs_hredraw | cs_vredraw; wclass.lpszmenuname = null; wclass.hbrbackground = (hbrush)color_window; wclass.hcursor = loadcursor(null,idc_arrow); wclass.hicon = null; wclass.hiconsm = null; wclass.cbclsextra = 0; wclass.cbwndextra = 0; registerclassex(&wclass); hwnd hwnd=createwindowexw( 0, // in dword dwexstyle, l"window class", // in_opt lpctstr lpclassname, l"windows application", // in_opt lpctstr lpwindowname, ws_overlappedwindow, // in dword dwstyle, 200, // in int x, 200, // in int y, 640, // in int nwidth, 480, // in int nheight, null, // in_opt hwnd hwndparent, null, // in_opt hmenu hmenu, hinstance, // in_opt hinstance hinstance, null); // in_opt lpvoid lpparam showwindow(hwnd,showcmd); zeromemory(&msg,sizeof(msg)); while(getmessagew(&msg,null,0,0)) { translatemessage(&msg); dispatchmessagew(&msg); } return (int)&msg.wparam; } void button_proc (wparam, lparam); lresult callback wndproc(hwnd hwnd,uint msg,wparam wparam,lparam lparam) { hwnd group1 = 0; hwnd group2 = 0; switch(msg) { case wm_create: { // create group box group1 = createwindowexw( 0, l"button", l"group", ws_tabstop | ws_visible | ws_child | bs_notify | bs_groupbox , 100, 60, 150, 80, hwnd, 0, getmodulehandle(null), 0); setwindowsubclass(group1, (subclassproc) mywndproc, 0, 0); // create group box group2=createwindowexw( 0, l"button", l"group 2", ws_tabstop | ws_visible | ws_child | bs_groupbox , 100, 160, 150, 80, hwnd, 0, getmodulehandle(null), 0); setwindowsubclass(group2, (subclassproc) mywndproc, 0, 0); // create push button hwndbutton1=createwindowexw( 0, l"button", l"option 1", ws_tabstop | ws_visible | ws_child | ws_group | bs_notify | bs_autoradiobutton , 10, 20, 100, 24, group1, (hmenu)idc_main_button_1, getmodulehandle(null), 0); hwndbutton2=createwindowexw( 0, l"button", l"option 2", ws_tabstop | ws_visible | ws_child | bs_notify | bs_autoradiobutton , 10, 45, 100, 24, group1, (hmenu)idc_main_button_2, getmodulehandle(null), 0); hwndbutton3=createwindowexw( 0, l"button", l"option 3", ws_tabstop | ws_visible | ws_child | ws_group | bs_notify | bs_autoradiobutton , 10, 20, 100, 24, group2, (hmenu)idc_main_button_3, getmodulehandle(null), 0); hwndbutton4=createwindowexw( 0, l"button", l"option 4", ws_tabstop | ws_visible | ws_child | bs_notify | bs_autoradiobutton , 10, 45, 100, 24, group2, (hmenu)idc_main_button_4, getmodulehandle(null), 0); } break; case wm_notify: switch(loword(wparam)) { case idc_main_button_1: case idc_main_button_2: case idc_main_button_3: case idc_main_button_4: { button_proc(wparam,lparam); } break; } break; case wm_command: switch(loword(wparam)) { case idc_main_button_1: case idc_main_button_2: case idc_main_button_3: case idc_main_button_4: { button_proc(wparam,lparam); } break; } break; case wm_destroy: { removewindowsubclass(group1, (subclassproc) mywndproc, 0); removewindowsubclass(group2, (subclassproc) mywndproc, 0); postquitmessage(0); return 0; } break; } return defwindowprocw(hwnd,msg,wparam,lparam); } void button_proc (wparam wparam, lparam lparam) { switch (hiword(wparam)) { case bn_clicked: { cerr << "button clicked\n"; } break; case bn_dblclk: { cerr << "button double clicked\n"; } break; case bn_killfocus: { cerr << "button lost focus\n"; } break; case bn_setfocus: { cerr << "button set focus\n"; } break; // case bcn_hotitemchange: // controls version 6. // case bcn_dropdown: // controls version 6. // case nm_customdraw: // controls version 6. // case wm_ctlcolorbtn: // investigation required. } // //http://msdn.microsoft.com/en-us/library/windows/desktop/bb849167(v=vs.85).aspx // if ( button_getcheck((hwnd) lparam) == bst_unchecked) { // button_setcheck( (hwnd) lparam, bst_checked); // } else { // button_setcheck( (hwnd) lparam, bst_unchecked); // } } lresult callback mywndproc (hwnd hwnd, uint msg, wparam wparam, lparam lparam, uint_ptr uidsubclass, dword_ptr dwrefdata) { // cerr << "subclass proc called\n"; switch (msg) { case wm_command: { switch(loword(wparam)) { case idc_main_button_1: case idc_main_button_2: case idc_main_button_3: case idc_main_button_4: { button_proc(wparam,lparam); } break; } } break; } return defsubclassproc(hwnd, msg, wparam, lparam); }
if want remove black background of controls, can try enablethemedialogtexture()
.
the second method(from correctly drawn themed dialogs in winxp):
// wm_initdialog rect rc; getwindowrect(hwnd,&rc); hdc hdc=getdc(hwnd); hdc hdcmem=createcompatibledc(hdc); hbitmap hbmp=createcompatiblebitmap(hdc,rc.right-rc.left,rc.bottom-rc.top); hbitmap hbmpold=(hbitmap)selectobject(hdcmem,hbmp); sendmessage(hwnd,wm_printclient,(wparam)hdcmem,(lparam)(prf_erasebkgnd|prf_client|prf_nonclient)); hbrush=createpatternbrush(hbmp); // hbrush hbrush global selectobject(hdcmem,hbmpold); deleteobject(hbmp); deletedc(hdcmem); releasedc(hwnd,hdc); //wm_ctlcolorstatic rect rc; setbkmode((hdc)wparam,transparent); getwindowrect((hwnd)lparam,&rc); mapwindowpoints(null,hwnd,(lppoint)&rc,2); setbrushorgex((hdc)(wparam),-rc.left,-rc.top,null); return (lresult)hbrush;
Comments
Post a Comment