Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you create a button outside the WM_CREATE message in win32?
    primarykey
    data
    text
    <p>I'm using c++ with win32 and gdi+ for graphics.<br> When I initialize a button outside WM_CREATE, specifically in a WM_TIMER message, I can't draw anything else, after that one frame is drawn. Here's a snippet of the code:</p> <pre><code>case WM_TIMER: RECT client; GetClientRect(hWnd, &amp;client); client.bottom-=100; //The bottom hundred pixels are static after I draw the first frame, so I never update them if(starting==true) { starting=false; hdc = GetDC(hWnd); hdcBuf = CreateCompatibleDC(hdc); hdcMem = CreateCompatibleDC(hdcBuf); hbmBackBM = CreateCompatibleBitmap(hdc, client.right, client.bottom ); hbmOldBackBM = (HBITMAP)SelectObject(hdcBuf, hbmBackBM); Graphics temp(hdc); SolidBrush yelloworange(Color(250,225,65)); temp.FillRectangle(&amp;yelloworange,0,client.bottom,client.right,100); //Fill the bottom with yellow buttons[0]=CreateWindow("button","makereg", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 100, 630, 60, 20, hWnd, HMENU(IDB_MAKEREG), NULL, NULL); //buttons[1]=CreateWindow("button","destroyreg", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 100, 670, 80, 20, hWnd, HMENU(IDB_MAKEREG+1), NULL, NULL); } Graphics g(hdcBuf); </code></pre> <p>The first part is for double buffering, and the variables that I instantiate are global. I delete the HDCs and HBITMAPs in WM_DESTROY. starting is a global boolean that is instantiated as true. I do all of my drawing in this WM_TIMER message. If I comment out just the two lines where the buttons are created, everything runs normally. With them, it only draws out what is left in this WM_TIMER, and does not draw in the next one. All of the other drawing code is done to hdcBuf or g, and hdcBuf is then BitBlt'd onto hdc.</p> <p>I tried creating the button in WM_CREATE, and then showing it in WM_TIMER, but that caused the same problem. I can't create and show the window in WM_CREATE, because otherwise it gets drawn over when I fill the bottom 100 pixels with a yellow color.</p> <p>Is there a way to create and show a button outside WM_CREATE and outside WM_PAINT without crashing the rest of the code?</p> <p>EDIT: Here is some of the code that stops working, in WM_TIMER:</p> <pre><code>if(mousex!=uptomousex &amp;&amp; mousey!=uptomousey &amp;&amp; lbuttondown==true) // this code draws a rectangle between the point where the user begins holding the left mousebutton, and where the mouse is right now. { if(uptomousex-mousex&gt;0 &amp;&amp; uptomousey-mousey&gt;0) g.DrawRectangle(&amp;(p[0]), mousex, mousey, uptomousex-mousex, uptomousey-mousey); else if(uptomousex-mousex&lt;0 &amp;&amp; uptomousey-mousey&gt;0) g.DrawRectangle((&amp;p[0]), uptomousex, mousey, mousex-uptomousex, uptomousey-mousey); else if(uptomousex-mousex&gt;0 &amp;&amp; uptomousey-mousey&lt;0) g.DrawRectangle((&amp;p[0]), mousex, uptomousey, uptomousex-mousex, mousey-uptomousey); else if(uptomousex-mousex&lt;0 &amp;&amp; uptomousey-mousey&lt;0) g.DrawRectangle(&amp;(p[0]), uptomousex, uptomousey, mousex-uptomousex, mousey-uptomousey); } </code></pre> <p>Some global variables:</p> <pre><code>bool lbuttondown=false; float mousex=0; float mousey=0; float uptomousex=0; float uptomousey=0; </code></pre> <p>Elsewhere in WndProc...</p> <pre><code>case WM_LBUTTONDOWN: lbuttondown=true; mousex=(float)GET_X_LPARAM(lParam); mousey=(float)GET_Y_LPARAM(lParam); uptomousex=mousex; uptomousey=mousey; break; case WM_MOUSEMOVE: if(mousex!=GET_X_LPARAM(lParam) &amp;&amp; mousey!=GET_Y_LPARAM(lParam)) { uptomousex=(float)GET_X_LPARAM(lParam); uptomousey=(float)GET_Y_LPARAM(lParam); } break; </code></pre>
    singulars
    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.
    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