c++ - Initilizer-list cannot convert to const MARGINS* -
today jumped visual studio (c++) 2013, using codeblocks lot of time realized codeblocks starts fail @ compiling codes this:
//#define _win32_winnt 0x0500 #include "hmain.h" #include <windows.h> #include <uxtheme.h> int width = 800; int height = 600; const margins* margin = { 0, 0, width , height }; char lwindowname[256] = "teeest"; hwnd hwnd; char twindowname[256] = "teeest"; hwnd twnd; rect tsize; msg message; lresult callback winproc(hwnd hwnd, uint message, wparam wparam, lparam lparam) { switch (message) { case wm_paint: render (); break; case wm_create: dwmextendframeintoclientarea(hwnd, margin); break; case wm_command: if (wparam == vk_escape) postquitmessage(0); break; case wm_destroy: postquitmessage(0); return 0; default: return defwindowproc(hwnd, message, wparam, lparam); break; } return 0; } int winapi winmain(hinstance hinstance, hinstance hsecinstance, lpstr ncmdline, int ncmdshow) { createthread(0, 0, (lpthread_start_routine)setwindowtotarget, 0, 0, 0); wndclassex wclass; wclass.cbclsextra = null; wclass.cbsize = sizeof(wndclassex); wclass.cbwndextra = null; wclass.hbrbackground = (hbrush)createsolidbrush(rgb(0, 0, 0)); wclass.hcursor = loadcursor(0, idc_arrow); wclass.hicon = loadicon(0, idi_application); wclass.hiconsm = loadicon(0, idi_application); wclass.hinstance = hinstance; wclass.lpfnwndproc = winproc; wclass.lpszclassname = (lpcwstr)lwindowname; wclass.lpszmenuname = (lpcwstr)lwindowname; wclass.style = cs_vredraw | cs_hredraw; if(!registerclassex(&wclass)) exit(1); twnd = findwindow(0, (lpcwstr)twindowname); if (twnd) { getwindowrect(twnd, &tsize); width = tsize.right - tsize.left; height = tsize.bottom - tsize.top; hwnd = createwindowex(ws_ex_topmost | ws_ex_transparent | ws_ex_layered, (lpcwstr)lwindowname, (lpcwstr)lwindowname, ws_popup, 1, 1, width, height, 0, 0, 0, 0); setlayeredwindowattributes(hwnd, 0, 1.0f, lwa_alpha); setlayeredwindowattributes(hwnd, 0, rgb(0, 0, 0), lwa_colorkey); showwindow( hwnd, sw_show); } directxinit(hwnd); (;;) { if (getasynckeystate(vk_escape)) break; if(peekmessage(&message, hwnd, 0, 0, pm_remove)) { dispatchmessage(&message); translatemessage(&message); } sleep(1); } return 0; } void setwindowtotarget() { while(true) { twnd = findwindow(0, (lpcwstr)twindowname); if (twnd) { getwindowrect(twnd, &tsize); width = tsize.right - tsize.left; height = tsize.bottom - tsize.top; dword dwstyle = getwindowlong(twnd, gwl_style); if(dwstyle & ws_border) { tsize.top += 23; height -= 23; } movewindow(hwnd, tsize.left, tsize.top, width, height, true); } else { char* errormsg[125]; messagebox(0, l"mal", (lpcwstr)l"error - cannot find game!", mb_ok | mb_iconerror); exit(1); } sleep(100); } }
so, 2 question. first, how fix compiler error: http://gyazo.com/6d7de9e0f3bad345dbbe7b9b80c90b8d , second question. realized must put "l" , (lpcwstr) before chars*, 100% required? there way avoid @ least (lpcwstr)? read.
first,
const margins* margin = { 0, 0, width , height };
is invalid. want create new margins
object , initialize given values, in case don't want margin
pointer:
const margins margin = { 0, 0, width , height };
second, dwmextendframeintoclientarea()
expects const margins*
, pointer margins
object. give address of margin
:
dwmextendframeintoclientarea(hwnd, &margin);
as wide character issues, assuming compiling "unicode character set" in project options. in case, strings in windows api pointers wide characters (wchar_t*
). however, allocating narrow character arrays (such lwindowname
) , casting them pointer wchar_t
:
wclass.lpszclassname = (lpcwstr)lwindowname;
this give sorts of weird behaviours. make sure strings really made of wide characters:
wchar_t lwindowname[256] = l"teeest";
this allow drop casts.
Comments
Post a Comment