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 108 109 110 111
|
#include <windows.h>
#define IDC_BUTTON 1500
#define IDC_TEXTBOX 1502
typedef struct WindowsEventArguments //Package Window Procedure Parameters into structure
{
HWND hWnd; //Handle of Window
WPARAM wParam; //Window Parameter
LPARAM lParam; //Long Parameter
HINSTANCE hIns; //Instance Handle (Resolves To Process Address)
}WndEventArgs, *lpWndEventArgs;
long fnWndProc_OnCreate(lpWndEventArgs Wea) //Called One Time During Window Creatiion
{ //This corresponds to Form_Load() in
HWND hWnd; //Visual Basic
Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance; //lParam is pointer to CREATESTRUCT in WM_CREATE
hWnd=CreateWindow("button","button #1",WS_CHILD|WS_VISIBLE,160,15,100,25,Wea->hWnd,(HMENU)(IDC_BUTTON),Wea->hIns,NULL);
hWnd=CreateWindow("edit",0,WS_CHILD|WS_VISIBLE|WS_BORDER,10,60,400,25,Wea->hWnd,(HMENU)(IDC_TEXTBOX),Wea->hIns,NULL);
return 0;
}
long btnOpen_Click(lpWndEventArgs Wea) //Do Not Delete
{
//static char szFilter[128]="C Files (*.C)\0*.C\0\0"; //one filter and one kind of file
//static char szFilter[128]="C Files (*.C)\0*.C\0plg Files (*.plg)\0*.plg\0\0"; //two filters for two kinds of files
static char szFilter[128]="c files (*.c), plg files (*.plg)\0*.c;*.plg\0\0"; //one filter for two kinds of files
static char szTitleName[_MAX_FNAME + _MAX_EXT];
static char szFileName[_MAX_PATH];
static OPENFILENAME ofn;
char szBuffer[128];
memset(&ofn,'\0',sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrFilter=szFilter;
GetCurrentDirectory(128,szBuffer);
ofn.lpstrInitialDir=szBuffer;
ofn.nMaxFile=_MAX_PATH;
ofn.nMaxFileTitle=_MAX_FNAME+_MAX_EXT;
ofn.lpstrFile=szFileName;
ofn.lpstrFileTitle=szTitleName;
ofn.lpstrDefExt = "C";
GetOpenFileName(&ofn);
SetWindowText(GetDlgItem(Wea->hWnd,IDC_TEXTBOX),szTitleName);
return 0;
}
long fnWndProc_OnCommand(lpWndEventArgs Wea)
{
if(LOWORD(Wea->wParam)==IDC_BUTTON)
return btnOpen_Click(Wea);
else
return 0;
}
long fnWndProc_OnClose(lpWndEventArgs Wea)
{
PostQuitMessage(0);
return 0;
}
LRESULT CALLBACK fnWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static WndEventArgs wea;
switch (message)
{
case WM_CREATE:
wea.hWnd=hwnd, wea.wParam=wParam, wea.lParam=lParam;
return fnWndProc_OnCreate(&wea);
case WM_COMMAND:
wea.hWnd=hwnd, wea.wParam=wParam, wea.lParam=lParam;
return fnWndProc_OnCommand(&wea);
case WM_CLOSE:
wea.hWnd=hwnd, wea.wParam=wParam, wea.lParam=lParam;
return fnWndProc_OnClose(&wea);
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hIns,HINSTANCE hPrevIns,LPSTR lpszArgument,int iCmdShow)
{
MSG messages;
WNDCLASSEX wincl;
HWND hMain;
wincl.lpszClassName="Form5"; wincl.lpfnWndProc=fnWndProc;
wincl.style=CS_HREDRAW | CS_VREDRAW; wincl.cbSize=sizeof(WNDCLASSEX);
wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION); wincl.hInstance=hIns;
wincl.hCursor=LoadCursor(NULL,IDC_ARROW); wincl.cbClsExtra=0;
wincl.hIconSm=LoadIcon(NULL,IDI_APPLICATION); wincl.lpszMenuName=NULL;
wincl.hbrBackground=(HBRUSH)COLOR_BACKGROUND; wincl.cbWndExtra=0;
RegisterClassEx(&wincl);
hMain=CreateWindow("Form5","Caption=Form5",WS_OVERLAPPEDWINDOW,250,300,425,150,HWND_DESKTOP,0,hIns,0);
ShowWindow(hMain,iCmdShow);
while(GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
|