Click here to Skip to main content
15,902,004 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Met problems with my first win32 program Pin
bloodwinner9-Sep-06 12:33
bloodwinner9-Sep-06 12:33 
GeneralRe: Met problems with my first win32 program Pin
Rick York9-Sep-06 12:41
mveRick York9-Sep-06 12:41 
GeneralRe: Met problems with my first win32 program Pin
TylerD759-Sep-06 13:15
TylerD759-Sep-06 13:15 
GeneralRe: Met problems with my first win32 program Pin
Rick York9-Sep-06 14:36
mveRick York9-Sep-06 14:36 
GeneralRe: Met problems with my first win32 program Pin
TylerD759-Sep-06 16:31
TylerD759-Sep-06 16:31 
GeneralRe: Met problems with my first win32 program Pin
Justin Tay9-Sep-06 15:08
Justin Tay9-Sep-06 15:08 
GeneralRe: Met problems with my first win32 program Pin
Michael Dunn9-Sep-06 17:20
sitebuilderMichael Dunn9-Sep-06 17:20 
AnswerRe: Met problems with my first win32 program Pin
mostafa_pasha10-Sep-06 4:13
mostafa_pasha10-Sep-06 4:13 
if you wanna program for win32 application you must drive to functions itself.
1)WinMain 2)WinPorc

try this code :(thanks for Ivor Horton Books. you can download source code & see chapter 7 )

<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
                   LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
   WNDCLASS WindowClass;                 // Structure to hold our window's attributes<br />
<br />
   static char szAppName[] = "OFWin";    // Define window class name<br />
   HWND hWnd;                            // Window handle<br />
   MSG msg;                              // Windows message structure<br />
<br />
   // Redraw the window if the size changes<br />
   WindowClass.style   = CS_HREDRAW | CS_VREDRAW;<br />
<br />
   // Define our procedure for message handling<br />
   WindowClass.lpfnWndProc = WindowProc;<br />
<br />
   WindowClass.cbClsExtra = 0;          // No extra bytes after the window class<br />
   WindowClass.cbWndExtra = 0;          // structure or the window instance<br />
<br />
   WindowClass.hInstance = hInstance;   // Application instance handle<br />
<br />
   // Set default application icon<br />
   WindowClass.hIcon = LoadIcon(0, IDI_APPLICATION);<br />
<br />
   // Set window cursor to be the standard arrow<br />
   WindowClass.hCursor = LoadCursor(0, IDC_ARROW);<br />
<br />
   // Set gray brush for background color<br />
   WindowClass.hbrBackground = static_cast<HBRUSH>(GetStockObject(GRAY_BRUSH));<br />
<br />
   WindowClass.lpszMenuName = 0;           // No menu, so no menu resource name<br />
<br />
   WindowClass.lpszClassName = szAppName;  // Set class name<br />
<br />
   // Now register our window class<br />
   RegisterClass(&WindowClass);<br />
<br />
   //  Now we can create the window<br />
   hWnd = CreateWindow(<br />
          szAppName,                       // the window class name<br />
          "A Basic Window the Hard Way",   // The window title<br />
          WS_OVERLAPPEDWINDOW,             // Window style as overlapped<br />
          CW_USEDEFAULT,         // Default screen position of upper left<br />
          CW_USEDEFAULT,         // corner of our window as x,y...<br />
          CW_USEDEFAULT,         // Default window size<br />
          CW_USEDEFAULT,         // .... <br />
          0,                     // No parent window<br />
          0,                     // No menu<br />
          hInstance,             // Program Instance handle<br />
          0                      // No window creation data<br />
        );<br />
<br />
   ShowWindow(hWnd, nCmdShow);   // Display the window<br />
   UpdateWindow(hWnd);           // Cause window client area to be drawn<br />
<br />
   // The message loop<br />
   while(GetMessage(&msg, 0, 0, 0) == TRUE)   // Get any messages<br />
   {<br />
      TranslateMessage(&msg);                 // Translate the message<br />
      DispatchMessage(&msg);                  // Dispatch the message<br />
   }<br />
<br />
   return msg.wParam;                         // End so return to Windows<br />
}<br />
<br />
<br />
// Listing OFWIN_2<br />
long WINAPI WindowProc(HWND hWnd, UINT message, WPARAM wParam,<br />
                       LPARAM lParam)<br />
{<br />
   HDC hDC;                       // Display context handle<br />
   PAINTSTRUCT PaintSt;           // Structure defining area to be drawn<br />
   RECT aRect;                    // A working rectangle<br />
<br />
   switch(message)                // Process selected messages<br />
   {<br />
      case WM_PAINT:                       // Message is to redraw the window<br />
         hDC = BeginPaint(hWnd, &PaintSt); // Prepare to draw the window<br />
<br />
         // Get upper left and lower right of client area<br />
         GetClientRect(hWnd, &aRect);<br />
<br />
         SetBkMode(hDC, TRANSPARENT);      // Set text background mode<br />
<br />
         // Now draw the text in the window client area<br />
         DrawText(<br />
             hDC,                  // Device context handle<br />
             "But, soft! What light through yonder window breaks?",<br />
             -1,                   // Indicate null terminated string<br />
             &aRect,               // Rectangle in which text is to be drawn<br />
             DT_SINGLELINE|        // Text format - single line<br />
             DT_CENTER|            //             - centered in the line<br />
             DT_VCENTER);          //             - line centered in aRect<br />
<br />
         EndPaint(hWnd, &PaintSt); // Terminate window redraw operation<br />
         return 0;<br />
<br />
      case WM_DESTROY:             // Window is being destroyed<br />
         PostQuitMessage(0);<br />
         return 0;<br />
<br />
      default:             // Any other message - we don't want to know,<br />
                           // so call default message processing<br />
         return DefWindowProc(hWnd, message, wParam, lParam);<br />
   }<br />
}<br />
<br />

QuestionDrag and Drop Operations Pin
ram on c#9-Sep-06 7:47
ram on c#9-Sep-06 7:47 
AnswerRe: Drag and Drop Operations Pin
mostafa_pasha9-Sep-06 12:31
mostafa_pasha9-Sep-06 12:31 
AnswerRe: Drag and Drop Operations Pin
TommyTooth9-Sep-06 18:52
TommyTooth9-Sep-06 18:52 
QuestionRe: Drag and Drop Operations Pin
Hamid_RT10-Sep-06 2:09
Hamid_RT10-Sep-06 2:09 
Questiontransfer dialog Pin
Oliver1239-Sep-06 7:36
Oliver1239-Sep-06 7:36 
AnswerRe: transfer dialog Pin
Rick York9-Sep-06 9:25
mveRick York9-Sep-06 9:25 
QuestionCBitMapButton Pin
ram on c#9-Sep-06 6:55
ram on c#9-Sep-06 6:55 
AnswerRe: CBitMapButton Pin
Hamid_RT9-Sep-06 7:14
Hamid_RT9-Sep-06 7:14 
QuestionHow to create modeless CDialog ? Pin
Yanshof9-Sep-06 6:23
Yanshof9-Sep-06 6:23 
AnswerRe: How to create modeless CDialog ? Pin
Hamid_RT9-Sep-06 7:22
Hamid_RT9-Sep-06 7:22 
GeneralRe: This not work. Pin
Yanshof9-Sep-06 7:29
Yanshof9-Sep-06 7:29 
QuestionRe: This not work. Pin
Hamid_RT10-Sep-06 2:09
Hamid_RT10-Sep-06 2:09 
AnswerRe: How to create modeless CDialog ? Pin
CWiC9-Sep-06 8:05
CWiC9-Sep-06 8:05 
GeneralRe: How to create modeless CDialog ? Pin
Yanshof9-Sep-06 8:23
Yanshof9-Sep-06 8:23 
AnswerRe: How to create modeless CDialog ? Pin
mostafa_pasha9-Sep-06 12:05
mostafa_pasha9-Sep-06 12:05 
AnswerRe: How to create modeless CDialog ? Pin
mostafa_pasha9-Sep-06 12:06
mostafa_pasha9-Sep-06 12:06 
AnswerRe: How to create modeless CDialog ? Pin
Michael Dunn9-Sep-06 17:21
sitebuilderMichael Dunn9-Sep-06 17:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.