This program is supposed to draw a randomly colored dot (connected by a line of the same color) at a random location on the screen when I click "Start", then exit when I click ESCAPE. When I click "Start", though, nothing happens.
Code:
//FILE: main.c
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wingdi.h>
#include <stdlib.h>
#include "resource.h"
#include <stdio.h>
#define WM_START 12342649
HINSTANCE hInst;
void draw(HDC, int, int, int, int);
int x=1, y=1;
HDC me;
WINDOWPLACEMENT wp;
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
//SetBkColor(GetDC(NULL), RGB(0,0,0));
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(lParam))
{
case 2222:
MessageBox(hwndDlg, "start", "", MB_OK);
while(!(GetKeyState(VK_ESCAPE)&0b10000000)) {
while(((x=rand())<1024)&&(x>1));
while(((y=rand())<685)&&(x>23));
draw(me, 10, 10, x, y);
Sleep(300);
}
EndDialog(hwndDlg, 0);
return TRUE;
}
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst = hInstance;
// The user interface is a modal dialog box
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}
void draw(HDC dc, int x, int y, int xpos, int ypos)
{
srand(xpos*ypos);
//int ca=0, cb=0, cd=0;
COLORREF color;
//HPEN pen=CreatePen(PS_SOLID, 20);
LOGBRUSH mbrush;
/*while((ca=rand())<=0xFF);
while((ca=rand())<=0xFF);
while((ca=rand())<=0xFF);*/
COLORREF rnd=RGB(rand()&0xFF, rand()&0xFF, rand()&0xFF);
mbrush.lbStyle=BS_SOLID;
mbrush.lbColor=rnd;
mbrush.lbHatch=0;
HBRUSH brush=CreateBrushIndirect(&mbrush);
SelectObject(dc, (HGDIOBJ)brush);
LineTo(dc, xpos, ypos);
color=rnd;
//color=RGB(xpos, 0, 0);
int xx, yy;
for(xx=0; xx<x; xx++)
{
for(yy=0; yy<y; yy++)
{
SetPixel(dc, xx+xpos, yy+ypos, color);
}
}
}
Code:
//FILE: resource.h
#include <windows.h>
// ID of Main Dialog
#define DLG_MAIN 101
Code:
//FILE: resource.rc
#include "resource.h"
DLG_MAIN DIALOGEX 6, 5, 194, 106
CAPTION ""
STYLE DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
BEGIN
PUSHBUTTON "Start", 2222/*ID*/, 7, 7, 47, 22
END
What is wrong????? (Probably alot)
NOTE: Some of these functions I have just started using today.