1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <windows.h>
#include <string>
using std::string;
//global variables
HINSTANCE inst;
HWND hwnd;
HWND txtbox;
char buffer[256];
const int IDC_EDITBOX =3;
//useful functions
void show_error(const char* msg,unsigned error){
_snprintf(buffer,256,"ERROR: %s %i",msg,error);
MessageBox(0,buffer,"ERROR",MB_OK|MB_ICONEXCLAMATION);}
LRESULT CALLBACK pipad_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_CREATE:
txtbox=CreateWindow("EDIT","",WS_BORDER|WS_VISIBLE|WS_CHILD|ES_AUTOVSCROLL|ES_MULTILINE|WS_VSCROLL/*|ES_WANTRETURN*/,0,0,
300,300,hwnd,(HMENU)IDC_EDITBOX,inst,NULL);
if(txtbox==NULL){
show_error("Failed to create the text box\n\nError code:",GetLastError());
DestroyWindow(hwnd);}
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0 ;
}
int WINAPI WinMain(HINSTANCE hinst,HINSTANCE hprev,LPSTR cmdline,int cmdshow){
WNDCLASSEX wndclass;
MSG msg;
inst=hinst;
wndclass.cbSize=sizeof(WNDCLASSEX);
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=pipad_proc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hinst;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName="PIpad";
wndclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
if(!RegisterClassEx(&wndclass)){
show_error("Failed to register the window class\n\nError code:",GetLastError());
return 1;}
hwnd=CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,"PIpad","Untitled - PIpad",WS_OVERLAPPEDWINDOW|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hinst,NULL);
if(!hwnd){
show_error("Failed to create the window\n\nError code:",GetLastError());
return 2;}
ShowWindow(hwnd,cmdshow);
while(GetMessage(&msg,hwnd,0,0) >0){
TranslateMessage(&msg);
DispatchMessage(&msg);}
return msg.wParam;}
|