Original Post
My menu won''t show! It was fine before I tweaked something and then when i recompiled it wasnt there. heres the code:
thx brassfish
extended waranty, how can I lose!
#include <windows.h>
#include <fstream>
#include "resource.h"
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "pattern maker";
struct pattern
{
int x;
int y;
};
int WINAPI
WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_HREDRAW|CS_VREDRAW; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName=MAKEINTRESOURCE(UMENU); /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows''s default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let''s create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW&~WS_THICKFRAME&~WS_MAXIMIZEBOX, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
30+32*4, /* The programs width */
75+32*4, /* and height in pixels */
NULL, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, SW_SHOWNORMAL);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
ofstream save;
pattern p[4];
static bool grid[4][4];
static int num=0;
static int pos=0;
static HBRUSH brush=CreateSolidBrush(RGB(177,177,177));
int x=0,y=0;
int q=0;
int i,j;
int right,bottom;
HDC hdc;
char buffer[20];
PAINTSTRUCT ps;
switch (message) /* handle the messages */
{
case WM_DESTROY:
DeleteObject(brush);
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
return 0;
case WM_RBUTTONDOWN:
x=LOWORD(lParam);
y=HIWORD(lParam);
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if((x>i*32+10)&&(x<i*32+42)&&(y>j*32+10)&&(y<j*32+42))
{
if(num>0&&grid[i][j])
num--;
grid[i][j]=0;
}
InvalidateRect(hwnd,NULL,1);
return 0;
case WM_LBUTTONDOWN:
if(num==4)
break;
x=LOWORD(lParam);
y=HIWORD(lParam);
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if((x>i*32+10)&&(x<i*32+42)&&(y>j*32+10)&&(y<j*32+42))
{
if(!grid[i][j])
num++;
grid[i][j]=1;
}
}
InvalidateRect(hwnd,NULL,1);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SelectObject(hdc,GetStockObject(BLACK_PEN));
SelectObject(hdc,GetStockObject(WHITE_BRUSH));
Rectangle(hdc,10,10,10+32*4+4,10+32*4+4);
for(int i=0;i<4;i++)
{
MoveToEx(hdc,i*32+10+i,10,NULL);
LineTo(hdc,i*32+10+i,10+32*4+4);
MoveToEx(hdc,10,i*32+10+i,NULL);
LineTo(hdc,10+32*4+4,i*32+10+i);
}
SelectObject(hdc,brush);
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(grid[i][j])
{
bottom=j*32+44+j;
right=i*32+44+i;
if(i==3)
right--;
if(j==3)
bottom--;
Rectangle(hdc,i*32+10+i,j*32+10+j,right,bottom);
}
}
EndPaint(hwnd,&ps);
return 0;
case WM_COMMAND:
MessageBox(hwnd,"you saved successfully",szClassName,MB_OK);
switch(wParam)
{
case ID_FILE_SAVE:
if(num<4)
{
MessageBox(hwnd,"pattern has less than 4 blocks!","Error",MB_OK);
break;
}
save.open("../patterns.dat",ios::app|ios::binary);
if(!save)
{
MessageBox(hwnd,"could not open save file!","Error",MB_OK);
break;
}
for(int x=0;x<4;x++)
for(int y=0;y<4;y++)
{
if(grid[x][y])
{
p[q].x=x*25;
p[q].y=y*25;
q++;
}
}
save.write((char*)&p,sizeof(pattern)*4);
save.close();
break;
case ID_FILE_EXIT:
SendMessage(hwnd,WM_CLOSE,0,0);
break;
}
}
return DefWindowProc (hwnd, message, wParam, lParam);
return 0;
}