Home > Software engineering >  Win32 programming c
Win32 programming c

Time:10-01

Win32 programming experience, not only simple c + + base, the need to crash a program, hope to get everybody greatly directions, if you have any book can quickly improve can also introduce,
Vs c + + development environment, win32 project, the program has three functions, 1 click on the first menu to select the target file, 2 to 1. The string into an array of TXT, 3 in the target file every order before end of each of the input array,
Functions: how to add calls to browse the file function (in the form of a subroutine)
Draw lessons from the Lao zhou code, synthesis, and there is a problem hDlg for declaring identifier, and not local declarations, global declarations I didn't try, feel should also be no good,
 # include & lt; Windows. H> 
# include "resource. H"

INT_PTR CALLBACK Obj (HWND hDlg, UINT MSG, WPARAM WPARAM, LPARAM LPARAM);
LRESULT a CALLBACK MyWinProce (HWND HWND, UINT MSG, WPARAM WPARAM, LPARAM LPARAM);

Int the CALLBACK WinMain (HINSTANCE HINSTANCE,
HINSTANCE hPrevInstance,
LPSTR cmdLine,
Int nShow)
{
WCHAR * cn=L "Myapp";
WNDCLASS wc={};
Wc. HbrBackground=(COLOR_WINDOW HBRUSH);
Wc. LpszClassName=cn;
Wc. Style=CS_HREDRAW | CS_VREDRAW;
The wc. The hInstance=hInstance;
Wc. LpfnWndProc=(WNDPROC) MyWinProce;
RegisterClass (& amp; Wc);
HWND hm=CreateWindow (cn,
L "my application",
WS_OVERLAPPEDWINDOW,
20,
15,
420,
360,
NULL,
//load the menu resource
LoadMenu (hInstance, MAKEINTRESOURCE (IDR_MAIN)),
HInstance,
NULL);
If (hm==NULL)
return 0;
ShowWindow (hm, nShow);
MSG MSG.
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}

return 0;
}


LRESULT a CALLBACK MyWinProce (HWND HWND, UINT MSG, WPARAM WPARAM, LPARAM LPARAM)
{

The switch (MSG)
{
Case WM_COMMAND:
{
//remove the resource Id value
//and decide which the user selects a menu item
The switch (LOWORD (wParam))
{
Case IDM_OBJ:
Obj (hDlg, MSG, wParam, lParam);
break;
Default:
break;
}
}
return 0;
Case WM_DESTROY:
The PostQuitMessage (0);
return 0;
Default:
Return DefWindowProc (HWND, MSG, wParam, lParam);
}
}

INT_PTR CALLBACK Obj (HWND hDlg, UINT MSG, WPARAM WPARAM, LPARAM LPARAM)
{
OPENFILENAME opfn;
WCHAR strFilename [MAX_PATH];//store the file name
//initialize
ZeroMemory (& amp; Opfn, sizeof (OPENFILENAME));
Opfn. LStructSize=sizeof (OPENFILENAME);//structure size
//set the filter
Opfn. LpstrFilter=L "all files \ 0 *. * \ \ 0 0 text files *. TXT \ 0 mp3 files \ 0 *. Mp3\0";
//the default filter index set to 1
Opfn. NFilterIndex=1;
//file name field must be set the first character to \ 0
Opfn. LpstrFile=strFilename;
Opfn. LpstrFile [0]='\ 0';
Opfn. NMaxFile=sizeof (strFilename);
//set the sign bit, check whether there is a directory or file
Opfn. Flags=OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
//opfn. LpstrInitialDir=NULL;
//display dialog box allows users to select file
If (GetOpenFileName (& amp; Opfn))
{
//in the text box display file path
HWND hEdt=GetDlgItem (hDlg, IDM_TXT);
SendMessage (hEdt WM_SETTEXT, NULL, (LPARAM) strFilename);
}
return 0;
}

CodePudding user response:

You can define a global variable,

CodePudding user response:

The fifth edition Windows programming

CodePudding user response:

From the command line parameters can't access to files or folders inside?
  • Related