c++ - switch win32 console application to graphics mode -
c++ - switch win32 console application to graphics mode -
i want switch win32 console application graphics mode utilize setpixel function draw lines:
#include "stdafx.h" int _tmain(int argc, _tchar* argv[]) { //code switch graphics mode homecoming 0; }
please advice :)
here's fine setpixel()
example.
create win32 application project , paste code , compile it
//header files include #include<windows.h> #include<stdlib.h> #include<time.h> //application title #define apptitle "hello world" //function prototypes (forward declarations) bool initinstance(hinstance, int); atom myregisterclass(hinstance); lresult callback winproc(hwnd, uint, wparam, lparam); //the window event callback function lresult callback winproc(hwnd hwnd, uint message, wparam wparam, lparam lparam) { paintstruct ps; hdc hdc; char *szhello = "setpixel"; rect rt; int x=0, y=0, n=0; colorref c; int j; switch (message) { case wm_paint: //get dimensions of window getclientrect(hwnd, &rt); //start drawing on devicce context hdc = beginpaint (hwnd, &ps); //draw text drawtext(hdc, szhello, strlen(szhello), &rt, dt_center); j = (rand()*100); c = rgb(0, 0, 0); while( x<25000) { setpixel(hdc, rand()%400, rand()%400, rand()%255); x++; } //stop drawing endpaint(hwnd, &ps); break; case wm_destroy: postquitmessage(0); break; } homecoming defwindowproc(hwnd, message, wparam, lparam); } //helper function set window properties atom myregisterclass(hinstance hinstance) { //create window class construction wndclassex wc; wc.cbsize = sizeof(wndclassex); //fill struct info wc.style = cs_hredraw | cs_vredraw; wc.lpfnwndproc = (wndproc)winproc; wc.cbclsextra = 0; wc.cbwndextra = 0; wc.hinstance = hinstance; wc.hicon = null; wc.hcursor = loadcursor(null, idc_arrow); wc.hbrbackground = (hbrush) getstockobject(white_brush); wc.lpszmenuname = null; wc.lpszclassname = apptitle; wc.hiconsm = null; //set window class info homecoming registerclassex(&wc); } //helper function create window , refresh bool initinstance(hinstance hinstance, int ncmdshow) { hwnd hwnd; //create new window hwnd = createwindow( apptitle, //window class apptitle, //title bar ws_overlappedwindow, //window style cw_usedefault, //x position of window cw_usedefault, //y position of window 400, //width of window 400, //height of window null, //parent window null, //menu hinstance, //application instance null); //window parameters //was there error creating window? if(!hwnd) homecoming false; //display window showwindow(hwnd, ncmdshow); updatewindow(hwnd); homecoming true; } //entry point windows programme int winapi winmain(hinstance hinstance, hinstance hprevinstance, lpstr lpcmdline, int ncmdshow) { //declare variables msg msg; //register class myregisterclass(hinstance); //initialize application if(!initinstance (hinstance, ncmdshow)) homecoming false; //set random number seed srand(time(null)); //main message loop while(getmessage(&msg, null, 0, 0)) { translatemessage(&msg); dispatchmessage(&msg); } homecoming msg.wparam; }
c++ visual-c++
Comments
Post a Comment