Note that there are some explanatory texts on larger screens.

plurals
  1. POWinAPI window doesn't appear
    primarykey
    data
    text
    <p>And I can't figure out why. My code:</p> <pre><code>#include &lt;windows.h&gt; #include &lt;commctrl.h&gt; #include &lt;cstdio&gt; #include &lt;stdarg.h&gt; #include &lt;string&gt; #include &lt;cmath&gt; #include &lt;vector&gt; #include "resources.hpp" using std::string; using std::vector; struct undostruct{ /* add later */}; char buffer[2048]; HWND statusbar; HINSTANCE hinst; vector&lt;undostruct&gt; undo; void show_error(const char* format,...){ va_list args; va_start(args,format); vsprintf(buffer,format,args); va_end(args); MessageBox(NULL,buffer,"ERROR",MB_OK);} HWND create_tooltip(HWND parent,char* tip,unsigned uid,unsigned extraflags=0){ HWND tt=CreateWindowEx(WS_EX_TOPMOST,TOOLTIPS_CLASS,NULL,WS_POPUP|TTS_NOPREFIX|TTS_ALWAYSTIP,0,0,0,0,parent,NULL,NULL,NULL); SetWindowPos(tt,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); TOOLINFO ti; ti.cbSize=sizeof(TOOLINFO); ti.uFlags=TTF_SUBCLASS|extraflags; ti.hwnd=parent; ti.hinst=NULL; ti.uId=uid; ti.lpszText=tip; GetClientRect(parent,&amp;ti.rect); SendMessage(tt,TTM_ADDTOOL,0,(LPARAM)(LPTOOLINFO)&amp;ti); return tt;} LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); class Font{ private: HFONT hfont; public: Font(const char* fname){ hfont=CreateFont(0,0,0,0,FW_NORMAL,false,false,false,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,fname);} ~Font(){ DeleteObject(hfont);} operator HFONT(){ return hfont;}}courier("Courier New"); bool get_filename(char* fname,int len,HWND hwnd,bool save){ OPENFILENAME ofn; ZeroMemory(&amp;ofn,sizeof(OPENFILENAME)); ofn.lStructSize=sizeof(OPENFILENAME); ofn.hwndOwner=hwnd; ofn.lpstrFilter="Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0"; ofn.lpstrFile=fname; ofn.nMaxFile=len; ofn.lpstrTitle="Text Editor"; ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; if(save){ return GetSaveFileName(&amp;ofn);} else{ return GetOpenFileName(&amp;ofn);}} int WINAPI WinMain(HINSTANCE hprev,HINSTANCE hInst,LPSTR cmdline,int cmdshow){ WNDCLASSEX wcex; //HACCEL haccel=LoadAccelerators(hInst,MAKEINTRESOURCE(ACCELS)); HWND hwnd; MSG msg; hinst=hInst; //Register the window wcex.cbSize=sizeof(WNDCLASSEX); wcex.style=CS_HREDRAW|CS_VREDRAW; wcex.lpfnWndProc=WndProc; wcex.cbClsExtra=0; wcex.cbWndExtra=0; wcex.hInstance=hinst; wcex.hIcon=NULL; wcex.hCursor=NULL; wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName=MAKEINTRESOURCE(MAINMENU); wcex.lpszClassName="ImageEditor"; wcex.hIconSm=NULL; if(!RegisterClassEx(&amp;wcex)){ show_error("Error %i: Failed to register the window.",GetLastError()); return -1;} //Create the window hwnd=CreateWindow("ImageEditor","Image Editor",WS_VISIBLE|WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hinst,NULL); if(!hwnd){ show_error("Error %i: Failed to create the window.",GetLastError()); return -2;} //Show/Update the window ShowWindow(hwnd,cmdshow); UpdateWindow(hwnd); //Initialize common controls /*INITCOMMONCONTROLSEX iccex; iccex.dwICC=ICC_WIN95_CLASSES; iccex.dwSize=sizeof(INITCOMMONCONTROLSEX); InitCommonControlsEx(&amp;iccex);*/ //Go into the main program loop while(GetMessage(&amp;msg,NULL,0,0)){ //if(!TranslateAccelerator(hwnd,haccel,&amp;msg)){ TranslateMessage(&amp;msg); DispatchMessage(&amp;msg);}//} return msg.wParam;} LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){ static int sizes[]={260,330,420,520}; switch(msg){ case WM_CREATE: statusbar=CreateWindow(STATUSCLASSNAME,"",WS_CHILD|WS_BORDER|WS_VISIBLE,-100,-100,10,10,hwnd,NULL,hinst,NULL); if(!statusbar){ show_error("Error %i: Failed to create the statusbar.",GetLastError());} //Description|Characters|Size|Lines|Line|Column SendMessage(statusbar,SB_SETPARTS,sizeof(sizes),(LPARAM)sizes); break; case WM_QUIT: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_COMMAND: //switch(LOWORD(wparam)){} //break; default: return DefWindowProc(hwnd,msg,wparam,lparam);} return 0;} </code></pre> <p>Also, my compiler doesn't recognize INITCOMMONCONTROLSEX when it should, which is commented out near the end of WinMain.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload