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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include <windows.h>
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM); //Prototype for action function
#define IDBUTTON 102
char szClassName[] = "MyFirstFrogram";
HINSTANCE g_hInst;
int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil) {
HWND hwnd; //Handle for window
MSG messages; //Messages sent to application
WNDCLASSEX wincl; //Window Class
g_hInst = hThisInstance; //Save the instance in global variable
wincl.hInstance = hThisInstance; //Register instance to the class
wincl.lpszClassName = (LPCWSTR)szClassName; //Set class name
wincl.lpfnWndProc = WindowProcedure; //Set procedure function
wincl.style = CS_DBLCLKS; //Set style?
wincl.cbSize = sizeof(WNDCLASSEX); //Set Size?
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); //Set defauly icon
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //Set default small icon
wincl.hCursor = LoadCursor(NULL, IDC_ARROW); //Set default cursor
wincl.lpszMenuName = NULL; //No menu
wincl.cbClsExtra= 0; //No extra bytes?
wincl.cbWndExtra = 0; //?
wincl.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); //Background color
if(!RegisterClassEx(&wincl)) {
return 0;
}
hwnd = CreateWindowEx(
0, //?
(LPCWSTR)szClassName, //Class Name
(LPCWSTR)"My First Program =O", //Title
WS_OVERLAPPEDWINDOW, //Default window?
CW_USEDEFAULT, //These two are for
CW_USEDEFAULT, //the window's placement
230, //height
75, //width
HWND_DESKTOP, //The desktop is the parent
NULL, //No Menu
hThisInstance, //The program instance
NULL); //No creation data?
ShowWindow(hwnd, SW_SHOW); //Show Window
UpdateWindow(hwnd); //Update window data?
while(GetMessage(&messages, NULL, 0, 0)) {
TranslateMessage(&messages); //Translate
DispatchMessage(&messages); //Send to procedure
}
return messages.wParam; //Should be 0 from PostQuitMessage()
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
HWND hwndButton;
switch(message) {
case WM_COMMAND: {
if(((HWND)lParam) && (HIWORD(wParam) == BN_CLICKED)) {
int iMID;
iMID = LOWORD(wParam);
switch(iMID) {
case IDBUTTON: {
MessageBox(hwnd, (LPCTSTR)"You just pushed me!", (LPCTSTR)"My Program =)",
MB_OK|MB_ICONEXCLAMATION);
break;
}
default:
break;
}
}
break;
}
case WM_DESTROY: {
PostQuitMessage(0); //Send Message to Shut Down Program
break;
}
case WM_CREATE:{
hwndButton = CreateWindowEx(0,
TEXT("BUTTON"), //Class name
TEXT("Push Me"), //Button Text
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON, //Styles
10, //Position from left
10, //position from top
200, //Width
30, //Height
hwnd, //Parent window
(HMENU)IDBUTTON, //Action Command
g_hInst, //Applicaton instance
NULL); //?
break;
}
default: {
return DefWindowProc(hwnd, message, wParam, lParam); //default actions
}
}
return 0;
}
|