vc创建窗体:使用API创建窗体(类似VC的创建过程)-vb教程疯狂代码ĵ:http:/CrazyCoder.cn/VisualBasic/Article15513.html中用API创建窗体和VC中步骤是样只不过用IDE环境创建是把过程都封装起来现在我们用API方式创建大致让我们了解个窗体产生过程让我们使用VB员对系统机制多些了解.先所以下用C创建窗体过程:入口:APIENTRYWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,nCmdShow)进入后先化结构WNDCLASSEXwcex;APIRegisterClassEx,注册窗体结构如果成功次CreateWindow、ShowWindow、UpdateWindow这样个主窗体就成功创建并显示给用户下面就缺少个处理消息死循环那么我们我们可以按照这个步骤在VB中实现样效果:在CAPI声明已经被包涵到头文件所以直接用就可以但是在VB中就要逐个声明下用到API结构PublicDeclareFunctionRegisterClassLib\user32\Alias\RegisterClassA\(ClassAsWNDCLASS)AsLongPublicDeclareFunctionUnregisterClassLib\user32\Alias\UnregisterClassA\(ByVallpClassNameAsString,ByValhInstanceAsLong)AsLongPublicDeclareFunctionDefWindowProcLib\user32\Alias\DefWindowProcA\(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLongPublicDeclareFunctionGetMessageLib\user32\Alias\GetMessageA\(lpMsgAsMsg,ByValhwndAsLong,ByValwMsgFilterMinAsLong,ByValwMsgFilterMaxAsLong)AsLongPublicDeclareFunctionTranslateMessageLib\user32\(lpMsgAsMsg)AsLongPublicDeclareFunctionDispatchMessageLib\user32\Alias\DispatchMessageA\(lpMsgAsMsg)AsLongPublicDeclareFunctionShowWindowLib\user32\(ByValhwndAsLong,ByValnCmdShowAsLong)AsLongPublicDeclareFunctionLoadCursorLib\user32\Alias\LoadCursorA\(ByValhInstanceAsLong,ByVallpCursorNameAsAny)AsLongPublicDeclareFunctionLoadIconLib\user32\Alias\LoadIconA\(ByValhInstanceAsLong,ByVallpIconNameAsString)AsLongPublicDeclareFunctionCreateWindowExLib\user32\Alias\CreateWindowExA\(ByValdwExStyleAsLong,ByVallpClassNameAsString,ByVallpWindowNameAsString,ByValdwStyleAsLong,ByValxAsLong,ByValyAsLong,ByValnWidthAsLong,ByValnHeightAsLong,ByValhWndParentAsLong,ByValhMenuAsLong,ByValhInstanceAsLong,lpParamAsAny)AsLongPublicDeclareFunctionCallWindowProcLib\user32\Alias\CallWindowProcA\(ByVallpPrevWndFuncAsLong,ByValhwndAsLong,ByValMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLongPublicDeclareFunctionSetWindowLongLib\user32\Alias\SetWindowLongA\(ByValhwndAsLong,ByValnIndexAsLong,ByValdwNewLongAsLong)AsLongPublicDeclareFunctionGetWindowLongLib\user32\Alias\GetWindowLongA\(ByValhwndAsLong,ByValnIndexAsLong)AsLongPublicDeclareFunctionMessageBoxLib\user32\Alias\MessageBoxA\(ByValhwndAsLong,ByVallpTextAsString,ByVallpCaptionAsString,ByValwTypeAsLong)AsLongPublicDeclareSubPostQuitMessageLib\user32\(ByValnExitCodeAsLong)PublicTypeWNDCLASSstyleAsLonglpfnwndprocAsLongcbClsextraAsLongcbWndExtra2AsLonghInstanceAsLonghIconAsLonghCursorAsLonghbrBackgroundAsLonglpszMenuNameAsStringlpszClassNameAsStringEndTypePublicTypePOINTAPIxAsLongyAsLongEndTypePublicTypeMsghwndAsLongmessageAsLongwParamAsLonglParamAsLongtimeAsLongptAsPOINTAPIEndTypePublicConstCS_VREDRAW=&H1PublicConstCS_HREDRAW=&H2PublicConstCW_USEDEFAULT=&H80000000PublicConstES_MULTILINE=&H4&PublicConstWS_BORDER=&H800000PublicConstWS_CHILD=&H40000000PublicConstWS_OVERLAPPED=&H0&PublicConstWS_CAPTION=&HC00000´WS_BORDEROrWS_DLGFRAMEPublicConstWS_SYSMENU=&H80000PublicConstWS_THICKFRAME=&H40000PublicConstWS_MINIMIZEBOX=&H20000PublicConstWS_MAXIMIZEBOX=&H10000PublicConstWS_OVERLAPPEDWINDOW=(WS_OVERLAPPEDOrWS_CAPTIONOrWS_SYSMENUOrWS_THICKFRAMEOrWS_MINIMIZEBOXOrWS_MAXIMIZEBOX)PublicConstWS_EX_CLIENTEDGE=&H200&PublicConstCOLOR_WINDOW=5PublicConstWM_DESTROY=&H2PublicConstWM_LBUTTONDOWN=&H201PublicConstWM_LBUTTONUP=&H202PublicConstIDC_ARROW=32512&PublicConstIDI_APPLICATION=32512&PublicConstGWL_WNDPROC=(-4)PublicConstSW_SHOWNORMAL=1PublicConstMB_OK=&H0&PublicConstMB_ICONEXCLAMATION=&H30&声明几个我们需要变量、常量:PublicConstgClassName=\MyClassName\PublicConstgAppName=\MyWindowCaption\PublicgButOldProcAsLongPublicgHwndAsLong,gButtonHwndAsLong,gEditHwndAsLong入口:SubMain代码如下:PublicSubMainDimwMsgAsMsg´´Callproceduretoregisterwindowname.Iffalse,thenexit.IfRegisterWindowClass=FalseThenExitSub´´CreatewindowIfCreateWindowsThen´´LoopwillexitwhenWM_QUITissenttothewindow.DoWhileGetMessage(wMsg,0&,0&,0&)´´TranslateMessagetakeskeyboardmessagesandconverts´´themtoWM_CHARforeasierprocessing.CallTranslateMessage(wMsg)´´Dispatchmessagecallsthedefaultwindowprocedure´´toprocessthewindowmessage.(WndProc)CallDispatchMessage(wMsg)LoopEndIfCallUnregisterClass(gClassName$,App.hInstance)EndSubPublicFunctionRegisterWindowClassAsBooleanDimwcAsWNDCLASSwc.style=CS_HREDRAWOrCS_VREDRAWwc.lpfnwndproc=GetAddress(AddressOfWndProc)´´Addressinmemoryofdefaultwindowprocedure.wc.hInstance=App.hInstancewc.hIcon=LoadIcon(0&,IDI_APPLICATION)´´Defaultapplicationiconwc.hCursor=LoadCursor(0&,IDC_ARROW)´´Defaultarrowwc.hbrBackground=COLOR_WINDOW´´Defaultacolorforwindow.wc.lpszClassName=gClassName$RegisterWindowClass=RegisterClass(wc)0EndFunctionPublicFunctionCreateWindowsAsBoolean´´开始创建窗体主窗体.gHwnd&=CreateWindowEx(0&,gClassName$,gAppName$,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,208,150,0&,0&,App.hInstance,ByVal0&)´´创建个按钮gButtonHwnd&=CreateWindowEx(0&,\Button\,\ClickHere\,WS_CHILD,58,90,85,25,gHwnd&,0&,App.hInstance,0&)´´创建个(WS_EX_CLIENTEDGE、ES_MULTILINE风格TextBoxgEditHwnd&=CreateWindowEx(WS_EX_CLIENTEDGE,\Edit\,\Thisistheeditcontrol.\&vbCrLf&\Asy